123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- <template>
- <a-config-provider :locale="getAntdLocale">
- <a-modal
- :visible="visible"
- :title="isRoomEnd ? t('room.myEndRoom') : !room ? t('room.createRoom') : t('room.editRoom')"
- :after-close="onCancel"
- width="912px"
- :style="{
- top: '10px',
- minWidth: '912px'
- }"
- @cancel="visible = false"
- >
- <template #footer>
- <a-button class="action-bottom" size="middle" @click="visible = false">
- {{ t('base.cancel') }}
- </a-button>
- <a-button
- v-if="!isRoomEnd"
- class="action-bottom"
- type="primary"
- size="middle"
- @click="saveRoom"
- >
- {{ t('base.save') }}
- </a-button>
- <!-- <a-button
- v-if="room"
- class="action-bottom"
- type="primary"
- size="middle"
- @click="startSync"
- >
- 开始带看
- </a-button> -->
- </template>
- <div class="edit-room-layout">
- <div class="scene">
- <iframe
- v-if="current.scenes.length"
- :src="`${mainURL}/smg.html?m=${current.scenes[0].num}&mobile=true&lang=${returnLocale}`"
- frameborder="0"
- />
- <img v-else :src="unScenePng" />
- </div>
- <a-form
- ref="formRef"
- class="info"
- :label-col="{ span: 24 }"
- :wrapper-col="{ span: 24 }"
- :model="current"
- >
- <!-- <h4>{{ t('room.roomInfo') }}</h4> -->
- <a-form-item
- :label="t('room.form.title')"
- name="title"
- :rules="[{ required: true, message: t('room.form.titleRequired') }]"
- >
- <a-input
- v-model:value.trim="current.title"
- :placeholder="t('room.form.titleplaceHolder')"
- :maxlength="15"
- show-count
- :disabled="isRoomEnd"
- />
- </a-form-item>
- <a-form-item :label="t('room.form.desc')" name="desc">
- <a-textarea
- v-model:value="current.desc"
- :placeholder="t('room.form.descplaceHolder')"
- :maxlength="200"
- show-count
- :disabled="isRoomEnd"
- />
- </a-form-item>
- <!-- <h4>{{ t('room.form.host') }}</h4> -->
- <a-form-item
- :label="t('room.form.nickname')"
- name="leaderName"
- :rules="[
- { required: true, message: t('room.form.nicknameRequired') },
- { validator: handleNickRegex }
- ]"
- >
- <a-input
- v-model:value.trim="current.leaderName"
- :placeholder="t('room.form.nicknameDesc')"
- :maxlength="15"
- show-count
- :disabled="isRoomEnd"
- />
- </a-form-item>
- <!-- <h4>{{ t('room.form.selectScene') }}</h4> -->
- <a-form-item
- :label="t('room.form.addScene')"
- class="select-scene"
- name="scenes"
- style="margin-bottom: 2px"
- >
- </a-form-item>
- <EditScenes
- :class="{ disabled: isRoomEnd }"
- :scenes="current.scenes"
- @delete="deleteScene"
- @insert="scene => current.scenes.push(scene)"
- />
- <!-- <h4>{{ t('room.form.advanceConfig') }}</h4> -->
- <a-form-item
- :label="t('room.usingTime')"
- class="select-scene"
- name="useTimeList"
- style="margin-bottom: 2px"
- :rules="[{ required: true, message: t('room.usingTimeRequire') }]"
- >
- <a-range-picker
- :show-time="{ format: 'HH:mm' }"
- format="YYYY-MM-DD HH:mm:ss"
- style="width: 80%"
- :disabled="isRoomEnd"
- :disabledDate="disabledDate"
- :disabledTime="disabledTime"
- @calendarChange="onRangeChange"
- v-model:value="current.useTimeList"
- />
- </a-form-item>
- <a-form-item
- :label="t('room.setPassword')"
- name="visitPassword"
- style="margin-bottom: 2px"
- >
- <v-otp-input
- v-model:value="current.visitPassword"
- class="otp-container"
- input-classes="otp-input"
- input-type="number"
- separator="-"
- :num-inputs="4"
- :should-auto-focus="false"
- :class="{ disabled: isRoomEnd }"
- :is-input-num="true"
- :conditionalClass="['one', 'two', 'three', 'four']"
- :placeholder="['-', '-', '-', '-']"
- />
- </a-form-item>
- <a-form-item name="scenes" style="margin-bottom: 2px">
- <div slot="label" style="margin: 10px 0">
- {{ t('room.authorize') }}
- <InfoCircleOutlined
- @click="
- Modal.confirm({
- centered: true,
- title: () => t('room.authTipTitle'),
- icon: () => createVNode(ExclamationCircleOutlined),
- //@ts-ignore
- cancelButtonProps: { style: { display: 'none' } },
- cancelText: false,
- content: () =>
- createVNode(
- 'div',
- { style: 'color:red;' },
- t('room.authTipContent')
- ),
- class: 'test'
- })
- "
- />
- </div>
- <a-button
- type="primary"
- size="small"
- ghost
- :disabled="isRoomEnd"
- @click="authvisible = true"
- >
- <template #icon><plus-outlined /></template
- >{{ t('room.addUser') }}</a-button
- >
- <span
- class="user-label"
- :class="{disabled:isRoomEnd}"
- style="margin-left: 5px"
- v-for="lab in current.userObjList"
- >
- {{ lab.userName }}
- <CloseOutlined @click="handleAssistantUseDelete(lab.userName)" />
- </span>
- </a-form-item>
- <a-form-item
- :label="t('room.setRoomNumber')"
- class="maxMan"
- name="maxMan"
- style="margin-bottom: 2px"
- :rules="[{ required: true, message: t('room.form.titleRequired') }]"
- >
- <a-input-number
- v-model:value="current.maxMan"
- :min="2"
- :max="10"
- :disabled="isRoomEnd"
- style="width: 30%"
- >
- <template #addonBefore>
- <UserOutlined />
- </template>
- </a-input-number>
- </a-form-item>
- </a-form>
- </div>
- </a-modal>
- <a-modal
- v-model:visible="authvisible"
- :title="t('room.addUser')"
- centered
- @cancel="authformState.userName = ''"
- @ok="handleAuthConfirm"
- >
- <a-form layout="inline" :model="authformState">
- <a-form-item
- :label="t('room.userAccount')"
- name="userName"
- style="margin-bottom: 20px"
- :rules="[{ required: true, message: t('room.userAccountRequired') }]"
- >
- <a-input
- v-model:value.trim="authformState.userName"
- :placeholder="t('room.userAccountRequired')"
- />
- </a-form-item>
- <!-- <a-form-item
- :label="t('room.usingTime')"
- name="useTimeList"
- style="margin-bottom: 20px"
- :rules="[{ required: true, message: t('room.usingTimeRequire') }]"
- >
- <a-range-picker
- :show-time="{ format: 'HH:mm' }"
- format="YYYY-MM-DD HH:mm:ss"
- style="width: 90%"
- v-model:value="authformState.useTimeList"
- />
- </a-form-item> -->
- </a-form>
- </a-modal>
- </a-config-provider>
- </template>
- <script lang="ts">
- import {
- ref,
- UnwrapRef,
- toRaw,
- defineComponent,
- reactive,
- computed,
- unref,
- createVNode
- } from 'vue'
- import { createRoom, useRoomStore } from '@/store/modules/room'
- import { props } from './props'
- import { message, Modal } from 'ant-design-vue'
- import { mainURL } from '@/env'
- import EditScenes from './scene-list.vue'
- import unScenePng from '@/assets/images/un-scene.png'
- import VOtpInput from 'vue3-otp-input'
- import type { Scene } from '@/store/modules/scene'
- import type { FormInstance } from 'ant-design-vue'
- import { useI18n } from '@/hook/useI18n'
- import { useLocale } from '@/locales/useLocale'
- import dayjs, { Dayjs } from 'dayjs'
- import duration from 'dayjs/plugin/duration'
- import { addAuthUser } from '@/api'
- import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
- dayjs.extend(duration)
- // const titleValidator = ref({
- // validator: (_, value) =>
- // !value.includes(' ')
- // ? Promise.resolve()
- // : Promise.reject(new Error('No spaces allowed'))
- // })
- interface AuthUserFormState {
- userName: string
- useTimeList?: Dayjs[]
- }
- export default defineComponent({
- name: 'EditRoom',
- components: { EditScenes, VOtpInput },
- props,
- setup(props) {
- const visible = ref(true)
- const authvisible = ref(false)
- const authformState: UnwrapRef<AuthUserFormState> = reactive({
- userName: ''
- // useTimeList: []
- })
- const { getAntdLocale } = useLocale()
- const roomStore = useRoomStore()
- const isRoomEnd = computed(() => props.room?.roomStatus === 2)
- const { getLocale } = useLocale()
- const { t } = useI18n()
- const returnLocale = computed(() => {
- if (unref(getLocale).includes('zh')) {
- return 'zh'
- }
- return unref(getLocale)
- })
- const otpInput = ref('')
- const formRef = ref<FormInstance>()
- const current = reactive(createRoom(props.room || {}))
- if (current.useTimeList?.length) {
- current.useTimeList = current.useTimeList?.map(i => dayjs(i))
- }
- if (!current.visitPassword) {
- current.visitPassword = ''
- }
- if (!current.userObjList) {
- current.userObjList = []
- }
- const deleteScene = (scene: Scene) => {
- const index = current.scenes.indexOf(scene)
- if (~index) {
- current.scenes.splice(index, 1)
- }
- }
- const saveRoom = async () => {
- await formRef.value?.validate()
- if (!current.scenes.length) {
- return message.error(t('room.form.addLeastScene'))
- }
- let breakTime = false
- if (current.useTimeList) {
- current.useTimeList.forEach(i => {
- const diff = i.diff(dayjs(), 'minutes')
- console.log('diff')
- if (diff < 0) {
- breakTime = true
- }
- })
- }
- if (breakTime) {
- message.error('所选时间不能少于当前系统时间!')
- return
- }
- if (
- current.visitPassword?.length &&
- current.visitPassword.length > 0 &&
- current.visitPassword.length < 4
- ) {
- return message.error(t('room.passwordError'))
- } else {
- current.takeLookLock = 1
- }
- if (current.visitPassword?.length === 0) {
- current.takeLookLock = 0
- }
- current.cover = current.scenes[0].cover
- console.log('save', current)
- props.onSave && props.onSave(current)
- visible.value = false
- }
- // const startSync = () => {
- // window.open(roomStore.getShareUrl({
- // }))
- // }
- const handleNickRegex = async (_: any, value: string) => {
- console.log('value', value)
- const regex = new RegExp(
- '^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9_]){1,15}$'
- )
- if (value?.length && !regex.test(value)) {
- return Promise.reject(t('room.nickNameRegrexError'))
- }
- return Promise.resolve('')
- }
- const handleAuthConfirm = async () => {
- const { t } = useI18n()
- if (authformState.userName?.length) {
- const userName = authformState.userName
- const res = await addAuthUser(userName)
- if (res) {
- const isExist = current.userObjList?.findIndex(
- i => i.userName === authformState.userName
- )
- console.log('isExist', isExist === -1)
- if (isExist === -1) {
- const dup = structuredClone(toRaw(authformState))
- current.userObjList?.push(dup)
- }
- authvisible.value = false
- console.log('current', current)
- } else {
- message.error(t('room.authUserError'))
- }
- } else {
- message.error('用户账号不能为空!')
- }
- }
- const handleAssistantUseDelete = (userName: string) => {
- const users = current.userObjList || []
- const index = users.findIndex(i => i.userName === userName)
- if (index > -1) {
- current.userObjList?.splice(index, 1)
- }
- }
- const disabledDate = (current: Dayjs) => {
- return current && current < dayjs().startOf('day')
- }
- const disabledTime = () => {
- return {
- disabledHours: () => [],
- disabledMinutes: () => [],
- disabledSeconds: () => []
- }
- }
- const onRangeChange = (range: Dayjs[]) => {
- const select = range.map((i, index) => {
- if (i) {
- const diff = i.diff(dayjs(), 'minutes')
- if (diff < 0) {
- // @ts-ignore
- current.useTimeList[index] = dayjs()
- console.log('diff', diff, index)
- }
- }
- })
- console.log('onRangeChange', event)
- }
- return {
- handleNickRegex,
- returnLocale,
- t,
- visible,
- current,
- formRef,
- deleteScene,
- saveRoom,
- // startSync,
- mainURL,
- unScenePng,
- getAntdLocale,
- dayjs,
- otpInput,
- authvisible,
- handleAuthConfirm,
- authformState,
- isRoomEnd,
- handleAssistantUseDelete,
- disabledDate,
- disabledTime,
- createVNode,
- Modal,
- ExclamationCircleOutlined,
- onRangeChange
- // authTargetUser,
- // authTargetUserTime
- }
- }
- })
- </script>
- <style lang="scss" scoped>
- .edit-room-layout {
- display: flex;
- max-height: 700px;
- overflow: hidden;
- .info {
- max-height: 700px;
- overflow-y: scroll;
- overflow-x: hidden;
- }
- }
- .scene {
- flex: none;
- width: 320px;
- margin-right: 30px;
- height: 692px;
- background: #f7f8fa;
- display: flex;
- align-items: center;
- iframe {
- width: 320px;
- height: 100%;
- }
- img {
- width: 100%;
- display: block;
- }
- }
- .info {
- flex: 1;
- // min-width: 500px;
- .ant-form-item {
- width: 100%;
- }
- h4 {
- font-size: 18px;
- color: #333;
- font-weight: 400;
- &:not(:first-child) {
- margin-top: 20px;
- }
- }
- }
- .disabled {
- pointer-events: none;
- cursor: not-allowed;
- opacity: 0.5;
- }
- .user-label {
- background: #eee;
- padding: 5px 5px;
- font-size: 13px;
- &.disabled{
- pointer-events: none;
- cursor: not-allowed;
- opacity: 0.5;
- }
- }
- </style>
- <style lang="scss">
- .edit-room-layout {
- min-width: 864px;
- .ant-form-item {
- margin-bottom: 16px;
- }
- .ant-input-affix-wrapper,
- .ant-input {
- border-radius: 4px 4px 4px 4px;
- opacity: 1;
- border: 1px solid #ebedf0;
- padding: 6px 11px;
- // height: 36px;
- }
- textarea.ant-input {
- resize: none;
- height: 120px;
- }
- .ant-input-textarea {
- position: relative;
- &::after {
- position: absolute;
- bottom: 4px;
- right: 8px;
- margin: 0;
- }
- }
- .ant-form-item-label {
- padding-bottom: 0;
- > label {
- color: #646566;
- }
- }
- }
- .action-bottom {
- border-radius: 4px;
- min-width: 100px;
- }
- .select-scene label::before {
- display: inline-block;
- margin-right: 4px;
- color: #ff4d4f;
- font-size: 14px;
- font-family: SimSun, sans-serif;
- line-height: 1;
- content: '*';
- }
- .otp-container {
- input::placeholder {
- font-size: 15px;
- text-align: center;
- font-weight: 600;
- }
- }
- .otp-input {
- width: 40px;
- height: 40px;
- padding: 5px;
- margin: 0 10px;
- font-size: 20px;
- border-radius: 4px;
- border: 1px solid rgba(0, 0, 0, 0.3);
- text-align: center;
- &.is-complete {
- background-color: #e4e4e4;
- }
- &::-webkit-inner-spin-button {
- -webkit-appearance: none;
- margin: 0;
- }
- }
- </style>
|