index.vue 16 KB

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