index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <a-modal
  3. :visible="visible"
  4. title="创建房间"
  5. :after-close="onCancel"
  6. width="912px"
  7. @cancel="visible = false"
  8. >
  9. <template #footer>
  10. <a-button class="action-bottom" size="middle" @click="visible = false">
  11. 取消
  12. </a-button>
  13. <a-button
  14. class="action-bottom"
  15. type="primary"
  16. size="middle"
  17. @click="saveRoom"
  18. >
  19. 保存
  20. </a-button>
  21. <a-button
  22. class="action-bottom"
  23. type="primary"
  24. size="middle"
  25. @click="onSave && onSave(current)"
  26. >
  27. 开始带看
  28. </a-button>
  29. </template>
  30. <div class="edit-room-layout">
  31. <div class="scene">
  32. <template v-if="!current.scenes.length">
  33. {{ current }}
  34. </template>
  35. <iframe
  36. v-else
  37. :src="`https://test.4dkankan.com/spg.html?m=${current.scenes[0].num}`"
  38. frameborder="0"
  39. />
  40. </div>
  41. <a-form
  42. ref="formRef"
  43. class="info"
  44. :label-col="{ span: 24 }"
  45. :wrapper-col="{ span: 24 }"
  46. :model="current"
  47. >
  48. <h4>房间信息</h4>
  49. <a-form-item
  50. label="标题"
  51. name="title"
  52. :rules="[{ required: true, message: '标题为必填字段' }]"
  53. >
  54. <a-input v-model:value="current.title" :maxlength="15" show-count />
  55. </a-form-item>
  56. <a-form-item label="简介" name="desc">
  57. <a-textarea
  58. v-model:value="current.desc"
  59. no
  60. :maxlength="200"
  61. show-count
  62. />
  63. </a-form-item>
  64. <h4>主持人信息</h4>
  65. <a-form-item
  66. label="昵称"
  67. name="leaderName"
  68. :rules="[{ required: true, message: '请输入昵称' }]"
  69. >
  70. <a-input
  71. v-model:value="current.leaderName"
  72. :maxlength="15"
  73. show-count
  74. />
  75. </a-form-item>
  76. <h4>选择场景</h4>
  77. <EditScenes
  78. :scenes="current.scenes"
  79. @delete="deleteScene"
  80. @insert="scene => current.scenes.push(scene)"
  81. />
  82. </a-form>
  83. </div>
  84. </a-modal>
  85. </template>
  86. <script lang="ts">
  87. import { ref, defineComponent, reactive } from 'vue'
  88. import { createRoom } from '@/store'
  89. import { props } from './props'
  90. import EditScenes from './scene-list.vue'
  91. import type { RoomScene } from '@/store'
  92. import { FormInstance, message } from 'ant-design-vue'
  93. export default defineComponent({
  94. name: 'EditRoom',
  95. components: { EditScenes },
  96. props,
  97. setup(props) {
  98. const visible = ref(true)
  99. const formRef = ref<FormInstance>()
  100. const current = reactive(createRoom(props.room || {}))
  101. const deleteScene = (scene: RoomScene) => {
  102. const index = current.scenes.indexOf(scene)
  103. if (~index) {
  104. current.scenes.splice(index, 1)
  105. }
  106. }
  107. const saveRoom = async () => {
  108. try {
  109. await formRef.value?.validate()
  110. if (!current.scenes.length) {
  111. return message.error('至少添加一个场景')
  112. }
  113. current.cover = current.scenes[0].cover
  114. props.onSave && props.onSave(current)
  115. visible.value = false
  116. } catch (config: any) {
  117. if (config && config.errorFields && config.errorFields.length) {
  118. message.error(config.errorFields[0].errors.join(','))
  119. }
  120. }
  121. }
  122. return {
  123. visible,
  124. current,
  125. formRef,
  126. deleteScene,
  127. saveRoom
  128. }
  129. }
  130. })
  131. </script>
  132. <style lang="scss" scoped>
  133. .edit-room-layout {
  134. display: flex;
  135. }
  136. .scene {
  137. flex: none;
  138. width: 320px;
  139. margin-right: 30px;
  140. height: 692px;
  141. background: #f7f8fa;
  142. iframe {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. }
  147. .info {
  148. flex: 1;
  149. h4 {
  150. font-size: 18px;
  151. color: #333;
  152. font-weight: 400;
  153. &:not(:first-child) {
  154. margin-top: 20px;
  155. }
  156. }
  157. }
  158. </style>
  159. <style lang="scss">
  160. .edit-room-layout {
  161. .ant-form-item {
  162. margin-bottom: 16px;
  163. }
  164. .ant-input-affix-wrapper,
  165. .ant-input {
  166. border-radius: 4px 4px 4px 4px;
  167. opacity: 1;
  168. border: 1px solid #ebedf0;
  169. padding: 6px 11px;
  170. // height: 36px;
  171. }
  172. textarea.ant-input {
  173. resize: none;
  174. height: 120px;
  175. }
  176. .ant-input-textarea {
  177. position: relative;
  178. &::after {
  179. position: absolute;
  180. bottom: 4px;
  181. right: 8px;
  182. margin: 0;
  183. }
  184. }
  185. .ant-form-item-label {
  186. padding-bottom: 0;
  187. > label {
  188. color: #646566;
  189. }
  190. }
  191. }
  192. .action-bottom {
  193. border-radius: 4px;
  194. min-width: 100px;
  195. }
  196. </style>