Showing
5 changed files
with
82 additions
and
21 deletions
| ... | ... | @@ -3,9 +3,13 @@ | 
| 3 | 3 | import { BasicModal, useModalInner } from '/@/components/Modal'; | 
| 4 | 4 | import { FieldsEnum, schemas, ViewTypeEnum } from './config'; | 
| 5 | 5 | import { DataBoardRecord } from '/@/api/dataBoard/model'; | 
| 6 | - import { Alert } from 'ant-design-vue'; | |
| 6 | + import { Alert, Button, Tooltip } from 'ant-design-vue'; | |
| 7 | 7 | import { ref, unref } from 'vue'; | 
| 8 | 8 | import { nextTick } from 'vue'; | 
| 9 | + import { ModalParamsType } from '/#/utils'; | |
| 10 | + import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard'; | |
| 11 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
| 12 | + import { computed } from 'vue'; | |
| 9 | 13 | |
| 10 | 14 | const props = defineProps<{ | 
| 11 | 15 | shareApi?: (...args: any[]) => Promise<any>; | 
| ... | ... | @@ -13,15 +17,20 @@ | 
| 13 | 17 | |
| 14 | 18 | const loading = ref(false); | 
| 15 | 19 | const record = ref<DataBoardRecord>({} as unknown as DataBoardRecord); | 
| 20 | + const link = ref(''); | |
| 16 | 21 | |
| 17 | - const [register, { closeModal }] = useModalInner(async (data: DataBoardRecord) => { | |
| 18 | - record.value = data; | |
| 19 | - await nextTick(); | |
| 20 | - setFieldsValue({ | |
| 21 | - [FieldsEnum.IS_SHARE]: data.viewType === ViewTypeEnum.PUBLIC_VIEW, | |
| 22 | - [FieldsEnum.ACCESS_CREDENTIALS]: data.accessCredentials, | |
| 23 | - }); | |
| 24 | - }); | |
| 22 | + const [register, { closeModal }] = useModalInner( | |
| 23 | + async (data: ModalParamsType<DataBoardRecord>) => { | |
| 24 | + const { record: value, href } = data; | |
| 25 | + record.value = value; | |
| 26 | + link.value = href; | |
| 27 | + await nextTick(); | |
| 28 | + setFieldsValue({ | |
| 29 | + [FieldsEnum.IS_SHARE]: value.viewType === ViewTypeEnum.PUBLIC_VIEW, | |
| 30 | + [FieldsEnum.ACCESS_CREDENTIALS]: value.accessCredentials, | |
| 31 | + }); | |
| 32 | + } | |
| 33 | + ); | |
| 25 | 34 | |
| 26 | 35 | const [registerForm, { getFieldsValue, setFieldsValue }] = useForm({ | 
| 27 | 36 | schemas, | 
| ... | ... | @@ -32,6 +41,10 @@ | 
| 32 | 41 | |
| 33 | 42 | const emit = defineEmits(['register', 'success']); | 
| 34 | 43 | |
| 44 | + const handleOpenLink = () => { | |
| 45 | + window.open(unref(link)); | |
| 46 | + }; | |
| 47 | + | |
| 35 | 48 | const handleSubmit = async () => { | 
| 36 | 49 | try { | 
| 37 | 50 | loading.value = true; | 
| ... | ... | @@ -44,6 +57,19 @@ | 
| 44 | 57 | loading.value = false; | 
| 45 | 58 | } | 
| 46 | 59 | }; | 
| 60 | + | |
| 61 | + const isPublicState = computed(() => { | |
| 62 | + return unref(record).viewType === ViewTypeEnum.PUBLIC_VIEW; | |
| 63 | + }); | |
| 64 | + | |
| 65 | + const { clipboardRef, isSuccessRef } = useCopyToClipboard(); | |
| 66 | + const { createMessage } = useMessage(); | |
| 67 | + const handleCopy = () => { | |
| 68 | + clipboardRef.value = unref(link); | |
| 69 | + if (unref(isSuccessRef)) { | |
| 70 | + createMessage.success('复制成功~'); | |
| 71 | + } | |
| 72 | + }; | |
| 47 | 73 | </script> | 
| 48 | 74 | |
| 49 | 75 | <template> | 
| ... | ... | @@ -54,5 +80,27 @@ | 
| 54 | 80 | message="私有视图只有项目成员可以浏览,公开视图拥有一个公开的 URL,任何人无需登录即可浏览." | 
| 55 | 81 | /> | 
| 56 | 82 | <BasicForm @register="registerForm" /> | 
| 83 | + <section> | |
| 84 | + <div v-if="isPublicState" class="mt-4"> | |
| 85 | + <span> 设置分享后, 可通过如下 </span> | |
| 86 | + <Button type="link" class="!px-1" @click="handleOpenLink"> 链接 </Button> | |
| 87 | + <span>访问:</span> | |
| 88 | + </div> | |
| 89 | + <Tooltip v-if="isPublicState" title="点击复制链接"> | |
| 90 | + <div | |
| 91 | + class="px-4 py-2 my-2 bg-gray-50 font-semibold tracking-wider text-base cursor-pointer truncate" | |
| 92 | + @click="handleCopy" | |
| 93 | + > | |
| 94 | + <span>{{ link }}</span> | |
| 95 | + </div> | |
| 96 | + </Tooltip> | |
| 97 | + | |
| 98 | + <Alert type="warning"> | |
| 99 | + <template #message> | |
| 100 | + <span class="font-bold mr-1">提示:</span> | |
| 101 | + <span>不要忘记将相关设备 <span class="mx-1 font-bold">公开</span> 以访问其数据</span> | |
| 102 | + </template> | |
| 103 | + </Alert> | |
| 104 | + </section> | |
| 57 | 105 | </BasicModal> | 
| 58 | 106 | </template> | ... | ... | 
| ... | ... | @@ -153,17 +153,20 @@ | 
| 153 | 153 | getListData(); | 
| 154 | 154 | }; | 
| 155 | 155 | |
| 156 | - const { clipboardRef, isSuccessRef } = useCopyToClipboard(); | |
| 157 | - const handleCreateShareUrl = (record: ConfigurationCenterItemsModal) => { | |
| 158 | - if (!unref(getShareFlag)) return; | |
| 159 | - const { origin } = location; | |
| 156 | + const createShareUrl = (record: ConfigurationCenterItemsModal) => { | |
| 160 | 157 | const searchParams = new URLSearchParams(); | 
| 161 | 158 | isDev && searchParams.set('dev', '1'); | 
| 162 | 159 | searchParams.set('share', 'SCADA'); | 
| 163 | 160 | searchParams.set('configurationId', record.id); | 
| 164 | 161 | searchParams.set('publicId', record.publicId || ''); | 
| 165 | 162 | searchParams.set('lightbox', '1'); | 
| 166 | - const url = `${origin}${configurationPrefix}/?${searchParams.toString()}`; | |
| 163 | + return `${origin}${configurationPrefix}/?${searchParams.toString()}`; | |
| 164 | + }; | |
| 165 | + | |
| 166 | + const { clipboardRef, isSuccessRef } = useCopyToClipboard(); | |
| 167 | + const handleCreateShareUrl = (record: ConfigurationCenterItemsModal) => { | |
| 168 | + if (!unref(getShareFlag)) return; | |
| 169 | + const url = createShareUrl(record); | |
| 167 | 170 | clipboardRef.value = url; | 
| 168 | 171 | if (unref(isSuccessRef)) { | 
| 169 | 172 | createMessage.success('复制成功~'); | 
| ... | ... | @@ -173,7 +176,7 @@ | 
| 173 | 176 | const [registerShareModal, { openModal }] = useModal(); | 
| 174 | 177 | |
| 175 | 178 | const handleOpenShareModal = (record: ConfigurationCenterItemsModal) => { | 
| 176 | - openModal(true, record); | |
| 179 | + openModal(true, { record, href: createShareUrl(record) }); | |
| 177 | 180 | }; | 
| 178 | 181 | |
| 179 | 182 | const listEl = ref<Nullable<ComponentElRef>>(null); | ... | ... | 
| ... | ... | @@ -163,15 +163,18 @@ | 
| 163 | 163 | const getPublicApiListData = () => {}; | 
| 164 | 164 | |
| 165 | 165 | const [registerShareModal, { openModal }] = useModal(); | 
| 166 | - const handleOpenShareModal = (item: BigScreenCenterItemsModel) => { | |
| 167 | - openModal(true, item); | |
| 166 | + const handleOpenShareModal = (record: BigScreenCenterItemsModel) => { | |
| 167 | + openModal(true, { record, href: createShareUrl(record) }); | |
| 168 | + }; | |
| 169 | + | |
| 170 | + const createShareUrl = (record: BigScreenCenterItemsModel) => { | |
| 171 | + const { origin } = location; | |
| 172 | + return `${origin}${largeDesignerPrefix}/#/share/preview/${record.id}/${record.publicId}`; | |
| 168 | 173 | }; | 
| 169 | 174 | |
| 170 | 175 | const { clipboardRef, isSuccessRef } = useCopyToClipboard(); | 
| 171 | 176 | const handleCreateShareUrl = (record: BigScreenCenterItemsModel) => { | 
| 172 | - const { origin } = location; | |
| 173 | - const { largeDesignerPrefix } = useGlobSetting(); | |
| 174 | - clipboardRef.value = `${origin}${largeDesignerPrefix}/#/share/preview/${record.id}/${record.publicId}`; | |
| 177 | + clipboardRef.value = createShareUrl(record); | |
| 175 | 178 | if (unref(isSuccessRef)) { | 
| 176 | 179 | createMessage.success('复制成功~'); | 
| 177 | 180 | } | ... | ... | 
| ... | ... | @@ -22,6 +22,8 @@ | 
| 22 | 22 | import { useForm, BasicForm } from '/@/components/Form'; | 
| 23 | 23 | import { formSchema } from './config/searchForm'; | 
| 24 | 24 | import { ShareModal } from '/@/views/common/ShareModal'; | 
| 25 | + import { ModalParamsType } from '/#/utils'; | |
| 26 | + import { DataActionModeEnum } from '/@/enums/toolEnum'; | |
| 25 | 27 | |
| 26 | 28 | const ListItem = List.Item; | 
| 27 | 29 | const router = useRouter(); | 
| ... | ... | @@ -133,7 +135,11 @@ | 
| 133 | 135 | }; | 
| 134 | 136 | |
| 135 | 137 | const handleOpenShareModal = (record: DataBoardRecord) => { | 
| 136 | - openShareModal(true, record); | |
| 138 | + openShareModal(true, { | |
| 139 | + record, | |
| 140 | + mode: DataActionModeEnum.READ, | |
| 141 | + href: createShareUrl(record), | |
| 142 | + } as ModalParamsType<DataBoardRecord>); | |
| 137 | 143 | }; | 
| 138 | 144 | |
| 139 | 145 | const handleMenuEvent = (event: DropMenu, record: DataBoardRecord) => { | ... | ... |