index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <a-config-provider :locale="getAntdLocale">
  3. <a-modal
  4. :visible="visible"
  5. :title="!room ? t('room.createRoom') : t('room.editRoom')"
  6. :after-close="onCancel"
  7. width="912px"
  8. :style="{
  9. top: '10px',
  10. minWidth: '912px'
  11. }"
  12. @cancel="visible = false"
  13. >
  14. <template #footer>
  15. <a-button class="action-bottom" size="middle" @click="visible = false">
  16. {{ t('base.cancel') }}
  17. </a-button>
  18. <a-button
  19. class="action-bottom"
  20. type="primary"
  21. size="middle"
  22. @click="saveRoom"
  23. >
  24. {{ t('base.save') }}
  25. </a-button>
  26. <!-- <a-button
  27. v-if="room"
  28. class="action-bottom"
  29. type="primary"
  30. size="middle"
  31. @click="startSync"
  32. >
  33. 开始带看
  34. </a-button> -->
  35. </template>
  36. <div class="edit-room-layout">
  37. <div class="scene">
  38. <iframe
  39. v-if="current.scenes.length"
  40. :src="`${mainURL}/smg.html?m=${current.scenes[0].num}&mobile=true&lang=${returnLocale}`"
  41. frameborder="0"
  42. />
  43. <img v-else :src="unScenePng" />
  44. </div>
  45. <a-form
  46. ref="formRef"
  47. class="info"
  48. :label-col="{ span: 24 }"
  49. :wrapper-col="{ span: 24 }"
  50. :model="current"
  51. >
  52. <h4>{{ t('room.roomInfo') }}</h4>
  53. <a-form-item
  54. :label="t('room.form.title')"
  55. name="title"
  56. :rules="[{ required: true, message: t('room.form.titleRequired') }]"
  57. >
  58. <a-input
  59. v-model:value.trim="current.title"
  60. :placeholder="t('room.form.titleplaceHolder')"
  61. :maxlength="15"
  62. show-count
  63. :disabled="isRoomEnd"
  64. />
  65. </a-form-item>
  66. <a-form-item :label="t('room.form.desc')" name="desc">
  67. <a-textarea
  68. v-model:value="current.desc"
  69. :placeholder="t('room.form.descplaceHolder')"
  70. :maxlength="200"
  71. show-count
  72. :disabled="isRoomEnd"
  73. />
  74. </a-form-item>
  75. <h4>{{ t('room.form.host') }}</h4>
  76. <a-form-item
  77. :label="t('room.form.nickname')"
  78. name="leaderName"
  79. :rules="[
  80. { required: true, message: t('room.form.nicknameRequired') },
  81. { validator: handleNickRegex }
  82. ]"
  83. >
  84. <a-input
  85. v-model:value.trim="current.leaderName"
  86. :placeholder="t('room.form.nicknameDesc')"
  87. :maxlength="15"
  88. show-count
  89. :disabled="isRoomEnd"
  90. />
  91. </a-form-item>
  92. <h4>{{ t('room.form.selectScene') }}</h4>
  93. <a-form-item
  94. :label="t('room.form.addScene')"
  95. class="select-scene"
  96. name="scenes"
  97. style="margin-bottom: 2px"
  98. >
  99. </a-form-item>
  100. <EditScenes
  101. :class="{ disabled: isRoomEnd }"
  102. :scenes="current.scenes"
  103. @delete="deleteScene"
  104. @insert="scene => current.scenes.push(scene)"
  105. />
  106. <h4>{{ t('room.form.advanceConfig') }}</h4>
  107. <a-form-item
  108. label="使用时间"
  109. class="select-scene"
  110. name="useTimeList"
  111. style="margin-bottom: 2px"
  112. :rules="[{ required: true, message: `请输入房间使用时间` }]"
  113. >
  114. <a-range-picker
  115. :show-time="{ format: 'HH:mm' }"
  116. format="YYYY-MM-DD HH:mm:ss"
  117. style="width: 80%"
  118. :disabled="isRoomEnd"
  119. v-model:value="current.useTimeList"
  120. />
  121. </a-form-item>
  122. <a-form-item
  123. label="设置密码"
  124. name="visitPassword"
  125. style="margin-bottom: 2px"
  126. >
  127. <v-otp-input
  128. v-model:value="current.visitPassword"
  129. class="otp-container"
  130. input-classes="otp-input"
  131. input-type="number"
  132. separator="-"
  133. :num-inputs="4"
  134. :should-auto-focus="false"
  135. :class="{ disabled: isRoomEnd }"
  136. :is-input-num="true"
  137. :conditionalClass="['one', 'two', 'three', 'four']"
  138. :placeholder="['-', '-', '-', '-']"
  139. />
  140. </a-form-item>
  141. <a-form-item label="授权" name="scenes" style="margin-bottom: 2px">
  142. <a-button
  143. type="primary"
  144. size="small"
  145. ghost
  146. :disabled="isRoomEnd"
  147. @click="authvisible = true"
  148. >
  149. <template #icon><plus-outlined /></template>添加用户</a-button
  150. >
  151. <span
  152. class="user-label"
  153. style="margin-left: 5px"
  154. v-for="lab in current.userObjList"
  155. >
  156. {{ lab.userName }}
  157. <CloseOutlined @click="handleAssistantUseDelete(lab.userName)" />
  158. </span>
  159. </a-form-item>
  160. <a-form-item
  161. label="设置房间人数"
  162. class="maxMan"
  163. name="maxMan"
  164. style="margin-bottom: 2px"
  165. :rules="[{ required: true, message: t('room.form.titleRequired') }]"
  166. >
  167. <a-input-number
  168. v-model:value="current.maxMan"
  169. placeholder="请输入房间人数"
  170. :min="5"
  171. :max="50"
  172. :disabled="isRoomEnd"
  173. style="width: 80%"
  174. >
  175. <template #addonBefore>
  176. <UserOutlined />
  177. </template>
  178. </a-input-number>
  179. </a-form-item>
  180. </a-form>
  181. </div>
  182. </a-modal>
  183. <a-modal
  184. v-model:visible="authvisible"
  185. title="添加用户"
  186. centered
  187. @ok="handleAuthConfirm"
  188. >
  189. <a-form layout="inline" :model="authformState">
  190. <a-form-item
  191. label="用户账号"
  192. name="userName"
  193. style="margin-bottom: 20px"
  194. :rules="[{ required: true, message: `请输入房间使用时间` }]"
  195. >
  196. <a-input
  197. v-model:value="authformState.userName"
  198. placeholder="请输入完整的账号"
  199. />
  200. </a-form-item>
  201. <a-form-item
  202. label="使用时间"
  203. name="useTimeList"
  204. style="margin-bottom: 20px"
  205. :rules="[{ required: true, message: `请输入房间使用时间` }]"
  206. >
  207. <a-range-picker
  208. :show-time="{ format: 'HH:mm' }"
  209. format="YYYY-MM-DD HH:mm:ss"
  210. style="width: 90%"
  211. v-model:value="authformState.useTimeList"
  212. />
  213. </a-form-item>
  214. </a-form>
  215. </a-modal>
  216. </a-config-provider>
  217. </template>
  218. <script lang="ts">
  219. import { ref, UnwrapRef, defineComponent, reactive, computed, unref } from 'vue'
  220. import { createRoom, useRoomStore } from '@/store/modules/room'
  221. import { props } from './props'
  222. import { message } from 'ant-design-vue'
  223. import { mainURL } from '@/env'
  224. import EditScenes from './scene-list.vue'
  225. import unScenePng from '@/assets/images/un-scene.png'
  226. import VOtpInput from 'vue3-otp-input'
  227. import type { Scene } from '@/store/modules/scene'
  228. import type { FormInstance } from 'ant-design-vue'
  229. import { useI18n } from '@/hook/useI18n'
  230. import { useLocale } from '@/locales/useLocale'
  231. import dayjs, { Dayjs } from 'dayjs'
  232. import { addAuthUser } from '@/api'
  233. // const titleValidator = ref({
  234. // validator: (_, value) =>
  235. // !value.includes(' ')
  236. // ? Promise.resolve()
  237. // : Promise.reject(new Error('No spaces allowed'))
  238. // })
  239. interface AuthUserFormState {
  240. userName: string
  241. useTimeList: Dayjs[]
  242. }
  243. export default defineComponent({
  244. name: 'EditRoom',
  245. components: { EditScenes, VOtpInput },
  246. props,
  247. setup(props) {
  248. const visible = ref(true)
  249. const authvisible = ref(false)
  250. const authformState: UnwrapRef<AuthUserFormState> = reactive({
  251. userName: '',
  252. useTimeList: []
  253. })
  254. const { getAntdLocale } = useLocale()
  255. const roomStore = useRoomStore()
  256. const isRoomEnd = computed(() => roomStore.roomStatus === 2)
  257. const { getLocale } = useLocale()
  258. const { t } = useI18n()
  259. const returnLocale = computed(() => {
  260. if (unref(getLocale).includes('zh')) {
  261. return 'zh'
  262. }
  263. return unref(getLocale)
  264. })
  265. const otpInput = ref('')
  266. const formRef = ref<FormInstance>()
  267. const current = reactive(createRoom(props.room || {}))
  268. if (current.useTimeList?.length) {
  269. current.useTimeList = current.useTimeList?.map(i => dayjs(i))
  270. }
  271. if (!current.visitPassword) {
  272. current.visitPassword = ''
  273. }
  274. if (!current.userObjList) {
  275. current.userObjList = []
  276. }
  277. const deleteScene = (scene: Scene) => {
  278. const index = current.scenes.indexOf(scene)
  279. if (~index) {
  280. current.scenes.splice(index, 1)
  281. }
  282. }
  283. const saveRoom = async () => {
  284. await formRef.value?.validate()
  285. if (!current.scenes.length) {
  286. return message.error(t('room.form.addLeastScene'))
  287. }
  288. if (
  289. current.visitPassword?.length &&
  290. current.visitPassword.length > 0 &&
  291. current.visitPassword.length < 4
  292. ) {
  293. return message.error('密码缺失,请填写完整!')
  294. } else {
  295. current.takeLookLock = 1
  296. }
  297. if (current.visitPassword?.length === 0) {
  298. current.takeLookLock = 0
  299. }
  300. current.cover = current.scenes[0].cover
  301. console.log('save', current)
  302. props.onSave && props.onSave(current)
  303. visible.value = false
  304. }
  305. // const startSync = () => {
  306. // window.open(roomStore.getShareUrl({
  307. // }))
  308. // }
  309. const handleNickRegex = async (_: any, value: string) => {
  310. console.log('value', value)
  311. const regex = new RegExp(
  312. '^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_]){1,15}$'
  313. )
  314. if (value?.length && !regex.test(value)) {
  315. return Promise.reject(t('room.nickNameRegrexError'))
  316. }
  317. return Promise.resolve('')
  318. }
  319. const handleAuthConfirm = async () => {
  320. if (authformState.userName?.length) {
  321. const userName = authformState.userName
  322. const res = await addAuthUser(userName)
  323. if (res) {
  324. const isExist = current.userObjList?.findIndex(
  325. i => i.userName === authformState.userName
  326. )
  327. console.log('isExist', isExist === -1)
  328. if (isExist === -1) {
  329. current.userObjList?.push(authformState)
  330. }
  331. authvisible.value = false
  332. console.log('current', current)
  333. }
  334. } else {
  335. message.error('用户账号不能为空!')
  336. }
  337. }
  338. const handleAssistantUseDelete = (userName: string) => {
  339. const users = current.userObjList || []
  340. const index = users.findIndex(i => i.userName === userName)
  341. if (index > -1) {
  342. current.userObjList?.splice(index, 1)
  343. }
  344. }
  345. return {
  346. handleNickRegex,
  347. returnLocale,
  348. t,
  349. visible,
  350. current,
  351. formRef,
  352. deleteScene,
  353. saveRoom,
  354. // startSync,
  355. mainURL,
  356. unScenePng,
  357. getAntdLocale,
  358. dayjs,
  359. otpInput,
  360. authvisible,
  361. handleAuthConfirm,
  362. authformState,
  363. isRoomEnd,
  364. handleAssistantUseDelete
  365. // authTargetUser,
  366. // authTargetUserTime
  367. }
  368. }
  369. })
  370. </script>
  371. <style lang="scss" scoped>
  372. .edit-room-layout {
  373. display: flex;
  374. max-height: 700px;
  375. overflow: hidden;
  376. .info {
  377. max-height: 700px;
  378. overflow-y: scroll;
  379. overflow-x: hidden;
  380. }
  381. }
  382. .scene {
  383. flex: none;
  384. width: 320px;
  385. margin-right: 30px;
  386. height: 692px;
  387. background: #f7f8fa;
  388. display: flex;
  389. align-items: center;
  390. iframe {
  391. width: 320px;
  392. height: 100%;
  393. }
  394. img {
  395. width: 100%;
  396. display: block;
  397. }
  398. }
  399. .info {
  400. flex: 1;
  401. // min-width: 500px;
  402. .ant-form-item {
  403. width: 100%;
  404. }
  405. h4 {
  406. font-size: 18px;
  407. color: #333;
  408. font-weight: 400;
  409. &:not(:first-child) {
  410. margin-top: 20px;
  411. }
  412. }
  413. }
  414. .disabled {
  415. pointer-events: none;
  416. cursor: not-allowed;
  417. opacity: 0.5;
  418. }
  419. .user-label {
  420. background: #eee;
  421. padding: 5px 5px;
  422. font-size: 13px;
  423. }
  424. </style>
  425. <style lang="scss">
  426. .edit-room-layout {
  427. min-width: 864px;
  428. .ant-form-item {
  429. margin-bottom: 16px;
  430. }
  431. .ant-input-affix-wrapper,
  432. .ant-input {
  433. border-radius: 4px 4px 4px 4px;
  434. opacity: 1;
  435. border: 1px solid #ebedf0;
  436. padding: 6px 11px;
  437. // height: 36px;
  438. }
  439. textarea.ant-input {
  440. resize: none;
  441. height: 120px;
  442. }
  443. .ant-input-textarea {
  444. position: relative;
  445. &::after {
  446. position: absolute;
  447. bottom: 4px;
  448. right: 8px;
  449. margin: 0;
  450. }
  451. }
  452. .ant-form-item-label {
  453. padding-bottom: 0;
  454. > label {
  455. color: #646566;
  456. }
  457. }
  458. }
  459. .action-bottom {
  460. border-radius: 4px;
  461. min-width: 100px;
  462. }
  463. .select-scene label::before {
  464. display: inline-block;
  465. margin-right: 4px;
  466. color: #ff4d4f;
  467. font-size: 14px;
  468. font-family: SimSun, sans-serif;
  469. line-height: 1;
  470. content: '*';
  471. }
  472. .otp-container {
  473. input::placeholder {
  474. font-size: 15px;
  475. text-align: center;
  476. font-weight: 600;
  477. }
  478. }
  479. .otp-input {
  480. width: 40px;
  481. height: 40px;
  482. padding: 5px;
  483. margin: 0 10px;
  484. font-size: 20px;
  485. border-radius: 4px;
  486. border: 1px solid rgba(0, 0, 0, 0.3);
  487. text-align: center;
  488. &.is-complete {
  489. background-color: #e4e4e4;
  490. }
  491. &::-webkit-inner-spin-button {
  492. -webkit-appearance: none;
  493. margin: 0;
  494. }
  495. }
  496. </style>