Showing
5 changed files
with
915 additions
and
0 deletions
| 1 | +<template> | |
| 2 | + <BasicDrawer | |
| 3 | + v-bind="$attrs" | |
| 4 | + @register="registerDrawer" | |
| 5 | + showFooter | |
| 6 | + :title="getTitle" | |
| 7 | + width="30%" | |
| 8 | + @ok="handleSubmit" | |
| 9 | + > | |
| 10 | + <BasicForm @register="registerForm" /> | |
| 11 | + </BasicDrawer> | |
| 12 | +</template> | |
| 13 | +<script lang="ts"> | |
| 14 | + import { defineComponent, ref, computed, unref } from 'vue'; | |
| 15 | + import { BasicForm, useForm } from '/@/components/Form'; | |
| 16 | + import { formSchema, PC_DEFAULT_CONTENT, PHONE_DEFAULT_CONTENT, Platform } from './center.data'; | |
| 17 | + import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; | |
| 18 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
| 19 | + import { saveOrUpdateConfigurationCenter } from '/@/api/configuration/center/configurationCenter'; | |
| 20 | + import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; | |
| 21 | + import { buildUUID } from '/@/utils/uuid'; | |
| 22 | + | |
| 23 | + export default defineComponent({ | |
| 24 | + name: 'ConfigurationDrawer', | |
| 25 | + components: { BasicDrawer, BasicForm }, | |
| 26 | + emits: ['success', 'register'], | |
| 27 | + setup(_, { emit }) { | |
| 28 | + const isUpdate = ref(true); | |
| 29 | + | |
| 30 | + const [registerForm, { validate, setFieldsValue, resetFields }] = useForm({ | |
| 31 | + labelWidth: 120, | |
| 32 | + schemas: formSchema, | |
| 33 | + showActionButtonGroup: false, | |
| 34 | + }); | |
| 35 | + | |
| 36 | + const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { | |
| 37 | + await resetFields(); | |
| 38 | + setDrawerProps({ confirmLoading: false }); | |
| 39 | + isUpdate.value = !!data?.isUpdate; | |
| 40 | + if (unref(isUpdate)) { | |
| 41 | + if (data.record.thumbnail) { | |
| 42 | + data.record.thumbnail = [ | |
| 43 | + { uid: buildUUID(), name: 'name', url: data.record.thumbnail } as FileItem, | |
| 44 | + ]; | |
| 45 | + } | |
| 46 | + if (data.record.organizationDTO) { | |
| 47 | + await setFieldsValue(data.record); | |
| 48 | + } else { | |
| 49 | + Reflect.deleteProperty(data.record, 'organizationId'); | |
| 50 | + await setFieldsValue(data.record); | |
| 51 | + } | |
| 52 | + } | |
| 53 | + }); | |
| 54 | + | |
| 55 | + const getTitle = computed(() => (!unref(isUpdate) ? '新增组态中心' : '编辑组态中心')); | |
| 56 | + | |
| 57 | + const getDefaultContent = (platform: Platform) => { | |
| 58 | + if (platform === Platform.PC) { | |
| 59 | + return PC_DEFAULT_CONTENT; | |
| 60 | + } | |
| 61 | + return PHONE_DEFAULT_CONTENT; | |
| 62 | + }; | |
| 63 | + | |
| 64 | + async function handleSubmit() { | |
| 65 | + try { | |
| 66 | + const { createMessage } = useMessage(); | |
| 67 | + const values = await validate(); | |
| 68 | + if (Reflect.has(values, 'thumbnail')) { | |
| 69 | + const file = (values.thumbnail || []).at(0) || {}; | |
| 70 | + values.thumbnail = file.url || null; | |
| 71 | + } | |
| 72 | + setDrawerProps({ confirmLoading: true }); | |
| 73 | + let saveMessage = '添加成功'; | |
| 74 | + let updateMessage = '修改成功'; | |
| 75 | + values.defaultContent = getDefaultContent(values.platform); | |
| 76 | + await saveOrUpdateConfigurationCenter(values, unref(isUpdate)); | |
| 77 | + closeDrawer(); | |
| 78 | + emit('success'); | |
| 79 | + createMessage.success(unref(isUpdate) ? updateMessage : saveMessage); | |
| 80 | + } finally { | |
| 81 | + setDrawerProps({ confirmLoading: false }); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + return { | |
| 86 | + getTitle, | |
| 87 | + registerDrawer, | |
| 88 | + registerForm, | |
| 89 | + handleSubmit, | |
| 90 | + }; | |
| 91 | + }, | |
| 92 | + }); | |
| 93 | +</script> | ... | ... |
| 1 | +<template> | |
| 2 | + <div> | |
| 3 | + <PageWrapper dense contentFullHeight contentClass="flex"> | |
| 4 | + <OrganizationIdTree @select="handleSelect" ref="organizationIdTreeRef" /> | |
| 5 | + <BasicTable | |
| 6 | + style="flex: auto" | |
| 7 | + :clickToRowSelect="false" | |
| 8 | + @register="registerTable" | |
| 9 | + :searchInfo="searchInfo" | |
| 10 | + class="w-3/4 xl:w-4/5" | |
| 11 | + > | |
| 12 | + <template #platform="{ record }"> | |
| 13 | + <Tag :color="record.platform === Platform.PHONE ? 'cyan' : 'blue'"> | |
| 14 | + {{ record.platform === Platform.PHONE ? '移动端' : 'PC端' }} | |
| 15 | + </Tag> | |
| 16 | + </template> | |
| 17 | + <template #toolbar> | |
| 18 | + <Authority value="api:yt:configuration:center:post"> | |
| 19 | + <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增组态 </a-button> | |
| 20 | + </Authority> | |
| 21 | + <Authority value="api:yt:configuration:center:delete"> | |
| 22 | + <Popconfirm | |
| 23 | + title="您确定要批量删除数据" | |
| 24 | + ok-text="确定" | |
| 25 | + cancel-text="取消" | |
| 26 | + @confirm="handleDeleteOrBatchDelete(null)" | |
| 27 | + > | |
| 28 | + <a-button type="primary" color="error" :disabled="hasBatchDelete"> | |
| 29 | + 批量删除 | |
| 30 | + </a-button> | |
| 31 | + </Popconfirm> | |
| 32 | + </Authority> | |
| 33 | + </template> | |
| 34 | + <template #action="{ record }"> | |
| 35 | + <TableAction | |
| 36 | + :actions="[ | |
| 37 | + { | |
| 38 | + label: '设计', | |
| 39 | + auth: 'api:yt:configuration:center:get_configuration_info:get', | |
| 40 | + icon: 'clarity:note-edit-line', | |
| 41 | + onClick: handleDesign.bind(null, record), | |
| 42 | + }, | |
| 43 | + { | |
| 44 | + label: '预览', | |
| 45 | + auth: 'api:yt:configuration:center:get_configuration_info:get', | |
| 46 | + icon: 'ant-design:eye-outlined', | |
| 47 | + onClick: handlePreview.bind(null, record), | |
| 48 | + }, | |
| 49 | + { | |
| 50 | + label: '编辑', | |
| 51 | + auth: 'api:yt:configuration:center:update', | |
| 52 | + icon: 'clarity:note-edit-line', | |
| 53 | + onClick: handleCreateOrEdit.bind(null, record), | |
| 54 | + }, | |
| 55 | + { | |
| 56 | + label: '删除', | |
| 57 | + auth: 'api:yt:configuration:center:delete', | |
| 58 | + icon: 'ant-design:delete-outlined', | |
| 59 | + color: 'error', | |
| 60 | + popConfirm: { | |
| 61 | + title: '是否确认删除', | |
| 62 | + confirm: handleDeleteOrBatchDelete.bind(null, record), | |
| 63 | + }, | |
| 64 | + }, | |
| 65 | + ]" | |
| 66 | + /> | |
| 67 | + </template> | |
| 68 | + </BasicTable> | |
| 69 | + </PageWrapper> | |
| 70 | + <ContactDrawer @register="registerDrawer" @success="handleSuccess" /> | |
| 71 | + </div> | |
| 72 | +</template> | |
| 73 | + | |
| 74 | +<script lang="ts"> | |
| 75 | + import { defineComponent, reactive, nextTick } from 'vue'; | |
| 76 | + import { BasicTable, useTable, TableAction } from '/@/components/Table'; | |
| 77 | + import { PageWrapper } from '/@/components/Page'; | |
| 78 | + import { useDrawer } from '/@/components/Drawer'; | |
| 79 | + import ContactDrawer from './ConfigurationCenterDrawer.vue'; | |
| 80 | + import { useResetOrganizationTree, OrganizationIdTree } from '/@/views/common/organizationIdTree'; | |
| 81 | + import { searchFormSchema, columns, Platform } from './center.data'; | |
| 82 | + import { | |
| 83 | + getPage, | |
| 84 | + deleteConfigurationCenter, | |
| 85 | + } from '/@/api/configuration/center/configurationCenter'; | |
| 86 | + import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | |
| 87 | + import { isDevMode } from '/@/utils/env'; | |
| 88 | + import { Authority } from '/@/components/Authority'; | |
| 89 | + import { Popconfirm } from 'ant-design-vue'; | |
| 90 | + import { Tag } from 'ant-design-vue'; | |
| 91 | + import { useGlobSetting } from '/@/hooks/setting'; | |
| 92 | + export default defineComponent({ | |
| 93 | + components: { | |
| 94 | + PageWrapper, | |
| 95 | + OrganizationIdTree, | |
| 96 | + BasicTable, | |
| 97 | + TableAction, | |
| 98 | + ContactDrawer, | |
| 99 | + Authority, | |
| 100 | + Popconfirm, | |
| 101 | + Tag, | |
| 102 | + }, | |
| 103 | + setup() { | |
| 104 | + const { configurationPrefix } = useGlobSetting(); | |
| 105 | + const isDev = isDevMode(); | |
| 106 | + const searchInfo = reactive<Recordable>({}); | |
| 107 | + const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); | |
| 108 | + // 表格hooks | |
| 109 | + const [registerTable, { reload, setProps }] = useTable({ | |
| 110 | + title: '组态中心列表', | |
| 111 | + api: getPage, | |
| 112 | + columns, | |
| 113 | + clickToRowSelect: false, | |
| 114 | + formConfig: { | |
| 115 | + labelWidth: 120, | |
| 116 | + schemas: searchFormSchema, | |
| 117 | + resetFunc: resetFn, | |
| 118 | + }, | |
| 119 | + showIndexColumn: false, | |
| 120 | + useSearchForm: true, | |
| 121 | + showTableSetting: true, | |
| 122 | + bordered: true, | |
| 123 | + rowKey: 'id', | |
| 124 | + actionColumn: { | |
| 125 | + width: 200, | |
| 126 | + title: '操作', | |
| 127 | + dataIndex: 'action', | |
| 128 | + slots: { customRender: 'action' }, | |
| 129 | + fixed: 'right', | |
| 130 | + }, | |
| 131 | + }); | |
| 132 | + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete( | |
| 133 | + deleteConfigurationCenter, | |
| 134 | + handleSuccess, | |
| 135 | + setProps | |
| 136 | + ); | |
| 137 | + nextTick(() => { | |
| 138 | + setProps(selectionOptions); | |
| 139 | + }); | |
| 140 | + | |
| 141 | + // 弹框 | |
| 142 | + const [registerDrawer, { openDrawer }] = useDrawer(); | |
| 143 | + | |
| 144 | + // 刷新 | |
| 145 | + function handleSuccess() { | |
| 146 | + reload(); | |
| 147 | + } | |
| 148 | + // 新增或编辑 | |
| 149 | + const handleCreateOrEdit = (record: Recordable | null) => { | |
| 150 | + if (record) { | |
| 151 | + openDrawer(true, { | |
| 152 | + isUpdate: true, | |
| 153 | + record, | |
| 154 | + }); | |
| 155 | + } else { | |
| 156 | + openDrawer(true, { | |
| 157 | + isUpdate: false, | |
| 158 | + }); | |
| 159 | + } | |
| 160 | + }; | |
| 161 | + // 树形选择器 | |
| 162 | + const handleSelect = (organizationId: string) => { | |
| 163 | + searchInfo.organizationId = organizationId; | |
| 164 | + handleSuccess(); | |
| 165 | + }; | |
| 166 | + | |
| 167 | + const handlePreview = (record: Recordable | null) => { | |
| 168 | + window.open( | |
| 169 | + `${configurationPrefix}/${isDev ? '?dev=1&' : '?'}configurationId=${ | |
| 170 | + record!.id | |
| 171 | + }&lightbox=1` | |
| 172 | + ); | |
| 173 | + }; | |
| 174 | + const handleDesign = (record: Recordable | null) => { | |
| 175 | + window.open( | |
| 176 | + `${configurationPrefix}/${isDev ? '?dev=1&' : '?'}configurationId=${record!.id}` | |
| 177 | + ); | |
| 178 | + }; | |
| 179 | + | |
| 180 | + return { | |
| 181 | + Platform, | |
| 182 | + searchInfo, | |
| 183 | + hasBatchDelete, | |
| 184 | + handleCreateOrEdit, | |
| 185 | + handleDeleteOrBatchDelete, | |
| 186 | + handleSelect, | |
| 187 | + handleSuccess, | |
| 188 | + handlePreview, | |
| 189 | + handleDesign, | |
| 190 | + registerTable, | |
| 191 | + registerDrawer, | |
| 192 | + organizationIdTreeRef, | |
| 193 | + }; | |
| 194 | + }, | |
| 195 | + }); | |
| 196 | +</script> | ... | ... |
| 1 | +import { BasicColumn, FormSchema } from '/@/components/Table'; | |
| 2 | +import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; | |
| 3 | +import { createImgPreview } from '/@/components/Preview'; | |
| 4 | +import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter'; | |
| 5 | +import { useComponentRegister } from '/@/components/Form'; | |
| 6 | +import { OrgTreeSelect } from '../../common/OrgTreeSelect'; | |
| 7 | +import { getDeviceProfile } from '/@/api/alarm/position'; | |
| 8 | + | |
| 9 | +useComponentRegister('OrgTreeSelect', OrgTreeSelect); | |
| 10 | +export enum Platform { | |
| 11 | + PHONE = 'phone', | |
| 12 | + PC = 'pc', | |
| 13 | +} | |
| 14 | + | |
| 15 | +export enum ConfigurationPermission { | |
| 16 | + CREATE = 'api:yt:configuration:center:post', | |
| 17 | + UPDATE = 'api:yt:configuration:center:update', | |
| 18 | + DELETE = 'api:yt:configuration:center:delete', | |
| 19 | + DESIGN = 'api:yt:configuration:center:get_configuration_info:design', | |
| 20 | + PREVIEW = 'api:yt:configuration:center:get_configuration_info:preview', | |
| 21 | + SHARE = 'api:yt:configuration:center:share', | |
| 22 | + UN_SHARE = 'api:yt:configuration:center:monopoly', | |
| 23 | +} | |
| 24 | + | |
| 25 | +export const PC_DEFAULT_CONTENT = | |
| 26 | + '<mxfile><diagram>dZHBDsIgDIafhvuEzOh5Tr142sEzGXWQsHVhmKFP7xbAidMT5fv/UtoSVrTuZHgvLyhAE5oJR9iBUMrybT4dM3l4stnTzJPGKBHYAir1hACj7a4EDInRImqr+hTW2HVQ24RxY3BMbTfUadWeN7ACVc31ml6VsPK7jVk4g2pkLJ3tgtLy6A5gkFzg+IFYSVhhEK2PWleAnscXB+Pzjn/U988MdPZHwhQsb0+XZEesfAE=</diagram></mxfile>'; | |
| 27 | + | |
| 28 | +export const PHONE_DEFAULT_CONTENT = | |
| 29 | + '<mxfile><diagram>dZHBEoIgEEC/hru6lXU2q0snD50Z2YQZdB2k0fr6dMCMsU4sb9+ysDDI6uFseCuvJFCzJBIDgyNLkjjdw7hM5OnIYRc5UBklvLSAQr3Qw1l7KIFdIFoibVUbwpKaBksbMG4M9aF2Jx12bXmFK1CUXK/pTQkrHd3E24VfUFXSd04hdYmaz65/SCe5oP4LQc4gM0TWRfWQoZ5mN4/F1Z3+ZD/3MtjYHwVjsJw9boIPgvwN</diagram></mxfile>'; | |
| 30 | +// 表格列数据 | |
| 31 | +export const columns: BasicColumn[] = [ | |
| 32 | + { | |
| 33 | + title: '组态名称', | |
| 34 | + dataIndex: 'name', | |
| 35 | + width: 120, | |
| 36 | + }, | |
| 37 | + { | |
| 38 | + title: '所属组织', | |
| 39 | + dataIndex: 'organizationDTO.name', | |
| 40 | + width: 160, | |
| 41 | + }, | |
| 42 | + { | |
| 43 | + title: '平台', | |
| 44 | + dataIndex: 'platform', | |
| 45 | + width: 100, | |
| 46 | + slots: { customRender: 'platform' }, | |
| 47 | + }, | |
| 48 | + { | |
| 49 | + title: '备注', | |
| 50 | + dataIndex: 'remark', | |
| 51 | + width: 200, | |
| 52 | + }, | |
| 53 | + { | |
| 54 | + title: '创建时间', | |
| 55 | + dataIndex: 'createTime', | |
| 56 | + width: 120, | |
| 57 | + }, | |
| 58 | + { | |
| 59 | + title: '更新时间', | |
| 60 | + dataIndex: 'updateTime', | |
| 61 | + width: 120, | |
| 62 | + }, | |
| 63 | + { | |
| 64 | + title: '操作', | |
| 65 | + dataIndex: 'action', | |
| 66 | + flag: 'ACTION', | |
| 67 | + width: 260, | |
| 68 | + slots: { customRender: 'action' }, | |
| 69 | + }, | |
| 70 | +]; | |
| 71 | + | |
| 72 | +// 查询字段 | |
| 73 | +export const searchFormSchema: FormSchema[] = [ | |
| 74 | + { | |
| 75 | + field: 'name', | |
| 76 | + label: '组态名称', | |
| 77 | + component: 'Input', | |
| 78 | + colProps: { span: 8 }, | |
| 79 | + componentProps: { | |
| 80 | + maxLength: 36, | |
| 81 | + placeholder: '请输入组态名称', | |
| 82 | + }, | |
| 83 | + }, | |
| 84 | +]; | |
| 85 | + | |
| 86 | +export const formSchema: FormSchema[] = [ | |
| 87 | + { | |
| 88 | + field: 'thumbnail', | |
| 89 | + label: '缩略图', | |
| 90 | + component: 'ApiUpload', | |
| 91 | + changeEvent: 'update:fileList', | |
| 92 | + valueField: 'fileList', | |
| 93 | + componentProps: () => { | |
| 94 | + return { | |
| 95 | + listType: 'picture-card', | |
| 96 | + maxFileLimit: 1, | |
| 97 | + accept: '.png,.jpg,.jpeg,.gif', | |
| 98 | + api: async (file: File) => { | |
| 99 | + try { | |
| 100 | + const formData = new FormData(); | |
| 101 | + formData.set('file', file); | |
| 102 | + const { fileStaticUri, fileName } = await uploadThumbnail(formData); | |
| 103 | + return { | |
| 104 | + uid: fileStaticUri, | |
| 105 | + name: fileName, | |
| 106 | + url: fileStaticUri, | |
| 107 | + } as FileItem; | |
| 108 | + } catch (error) { | |
| 109 | + return {}; | |
| 110 | + } | |
| 111 | + }, | |
| 112 | + onPreview: (fileList: FileItem) => { | |
| 113 | + createImgPreview({ imageList: [fileList.url!] }); | |
| 114 | + }, | |
| 115 | + // showUploadList: { | |
| 116 | + // showDownloadIcon: true, | |
| 117 | + // showRemoveIcon: true, | |
| 118 | + // }, | |
| 119 | + }; | |
| 120 | + }, | |
| 121 | + }, | |
| 122 | + | |
| 123 | + { | |
| 124 | + field: 'name', | |
| 125 | + label: '组态名称', | |
| 126 | + required: true, | |
| 127 | + component: 'Input', | |
| 128 | + componentProps: { | |
| 129 | + placeholder: '请输入组态名称', | |
| 130 | + maxLength: 36, | |
| 131 | + }, | |
| 132 | + }, | |
| 133 | + { | |
| 134 | + field: 'organizationId', | |
| 135 | + label: '所属组织', | |
| 136 | + required: true, | |
| 137 | + component: 'OrgTreeSelect', | |
| 138 | + }, | |
| 139 | + { | |
| 140 | + field: 'isTemplate', | |
| 141 | + label: '模版', | |
| 142 | + component: 'Switch', | |
| 143 | + defaultValue: 0, | |
| 144 | + componentProps: { | |
| 145 | + checkedValue: 1, | |
| 146 | + unCheckedValue: 0, | |
| 147 | + }, | |
| 148 | + }, | |
| 149 | + { | |
| 150 | + field: 'productIds', | |
| 151 | + label: '产品', | |
| 152 | + component: 'ApiSelect', | |
| 153 | + required: true, | |
| 154 | + componentProps: { | |
| 155 | + api: getDeviceProfile, | |
| 156 | + mode: 'multiple', | |
| 157 | + labelField: 'name', | |
| 158 | + valueField: 'tbProfileId', | |
| 159 | + }, | |
| 160 | + }, | |
| 161 | + { | |
| 162 | + field: 'platform', | |
| 163 | + label: '平台', | |
| 164 | + required: true, | |
| 165 | + component: 'RadioGroup', | |
| 166 | + defaultValue: Platform.PC, | |
| 167 | + componentProps: { | |
| 168 | + defaultValue: Platform.PC, | |
| 169 | + options: [ | |
| 170 | + { label: 'PC端', value: Platform.PC }, | |
| 171 | + { label: '移动端', value: Platform.PHONE }, | |
| 172 | + ], | |
| 173 | + }, | |
| 174 | + }, | |
| 175 | + { | |
| 176 | + field: 'remark', | |
| 177 | + label: '备注', | |
| 178 | + component: 'InputTextArea', | |
| 179 | + componentProps: { | |
| 180 | + placeholder: '请输入备注', | |
| 181 | + maxLength: 255, | |
| 182 | + }, | |
| 183 | + }, | |
| 184 | + { | |
| 185 | + field: 'id', | |
| 186 | + label: '', | |
| 187 | + component: 'Input', | |
| 188 | + show: false, | |
| 189 | + componentProps: { | |
| 190 | + maxLength: 36, | |
| 191 | + placeholder: 'id', | |
| 192 | + }, | |
| 193 | + }, | |
| 194 | +]; | ... | ... |
src/views/configuration/template/help.ts
0 → 100644
| 1 | +import { Platform } from './center.data'; | |
| 2 | +import { ConfigurationCenterItemsModal } from '/@/api/configuration/center/model/configurationCenterModal'; | |
| 3 | +import { useGlobSetting } from '/@/hooks/setting'; | |
| 4 | + | |
| 5 | +export enum ScadaModeEnum { | |
| 6 | + LIGHTBOX = 'lightbox', | |
| 7 | + DESIGN = 'design', | |
| 8 | + SHARE = 'share', | |
| 9 | +} | |
| 10 | + | |
| 11 | +interface ScadaLinkParamsType { | |
| 12 | + configurationId: string; | |
| 13 | + organizationId: string; | |
| 14 | + mode: ScadaModeEnum; | |
| 15 | + platform: Platform; | |
| 16 | + publicId?: string; | |
| 17 | +} | |
| 18 | + | |
| 19 | +const getRandomString = () => Number(Math.random().toString().substring(2)).toString(36); | |
| 20 | + | |
| 21 | +export const encode = (record: Recordable) => { | |
| 22 | + let hash = JSON.stringify(record); | |
| 23 | + const mixinString = getRandomString() | |
| 24 | + .slice(0, 10) | |
| 25 | + .padEnd(10, getRandomString()) | |
| 26 | + .split('') | |
| 27 | + .map((item) => (Math.random() > 0.5 ? item.toUpperCase() : item)) | |
| 28 | + .join(''); | |
| 29 | + hash = window.btoa(hash); | |
| 30 | + hash = hash.substring(0, 6) + mixinString + hash.substring(6); | |
| 31 | + hash = window.btoa(hash); | |
| 32 | + return hash; | |
| 33 | +}; | |
| 34 | + | |
| 35 | +export const createScadaPageLink = ( | |
| 36 | + record: ConfigurationCenterItemsModal, | |
| 37 | + mode: ScadaModeEnum = ScadaModeEnum.DESIGN, | |
| 38 | + open = true | |
| 39 | +) => { | |
| 40 | + const { configurationPrefix } = useGlobSetting(); | |
| 41 | + const params: ScadaLinkParamsType = { | |
| 42 | + configurationId: record.id, | |
| 43 | + organizationId: record.organizationId!, | |
| 44 | + mode: mode, | |
| 45 | + platform: record.platform as Platform, | |
| 46 | + }; | |
| 47 | + | |
| 48 | + if (mode === ScadaModeEnum.SHARE) { | |
| 49 | + params.publicId = record.publicId; | |
| 50 | + } | |
| 51 | + | |
| 52 | + const href = new URL(location.origin); | |
| 53 | + href.pathname = configurationPrefix; | |
| 54 | + href.hash = encode(params); | |
| 55 | + open && window.open(href.href); | |
| 56 | + return href.href; | |
| 57 | +}; | ... | ... |
src/views/configuration/template/index.vue
0 → 100644
| 1 | +<script setup lang="ts"> | |
| 2 | + import { List, Card, Button, PaginationProps, Tooltip } from 'ant-design-vue'; | |
| 3 | + import { ReloadOutlined } from '@ant-design/icons-vue'; | |
| 4 | + import { computed, onMounted, reactive, ref, unref } from 'vue'; | |
| 5 | + import { OrganizationIdTree, useResetOrganizationTree } from '../../common/organizationIdTree'; | |
| 6 | + import { | |
| 7 | + deleteConfigurationCenter, | |
| 8 | + getPage, | |
| 9 | + shareConfiguration, | |
| 10 | + } from '/@/api/configuration/center/configurationCenter'; | |
| 11 | + import { ConfigurationCenterItemsModal } from '/@/api/configuration/center/model/configurationCenterModal'; | |
| 12 | + import { PageWrapper } from '/@/components/Page'; | |
| 13 | + import { BasicForm, useForm } from '/@/components/Form'; | |
| 14 | + import { ConfigurationPermission, Platform, searchFormSchema } from './center.data'; | |
| 15 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
| 16 | + import { Authority } from '/@/components/Authority'; | |
| 17 | + import ConfigurationCenterDrawer from './ConfigurationCenterDrawer.vue'; | |
| 18 | + import { useDrawer } from '/@/components/Drawer'; | |
| 19 | + import { getBoundingClientRect } from '/@/utils/domUtils'; | |
| 20 | + import configurationSrc from '/@/assets/icons/configuration.svg'; | |
| 21 | + import { cloneDeep } from 'lodash'; | |
| 22 | + import { usePermission } from '/@/hooks/web/usePermission'; | |
| 23 | + import { AuthIcon, CardLayoutButton } from '/@/components/Widget'; | |
| 24 | + import AuthDropDown from '/@/components/Widget/AuthDropDown.vue'; | |
| 25 | + import { ShareModal } from '/@/views/common/ShareModal'; | |
| 26 | + import { ViewTypeNameEnum } from '../../common/ShareModal/config'; | |
| 27 | + import { useModal } from '/@/components/Modal'; | |
| 28 | + import { ViewType } from '../../visual/board/config/panelDetail'; | |
| 29 | + import { useRole } from '/@/hooks/business/useRole'; | |
| 30 | + import { useClipboard } from '@vueuse/core'; | |
| 31 | + import { Icon } from '/@/components/Icon'; | |
| 32 | + import { createScadaPageLink, ScadaModeEnum } from './help'; | |
| 33 | + | |
| 34 | + const listColumn = ref(5); | |
| 35 | + | |
| 36 | + const { createMessage } = useMessage(); | |
| 37 | + | |
| 38 | + const { isCustomerUser } = useRole(); | |
| 39 | + | |
| 40 | + const organizationId = ref<Nullable<number>>(null); | |
| 41 | + | |
| 42 | + const pagination = reactive<PaginationProps>({ | |
| 43 | + size: 'small', | |
| 44 | + showTotal: (total: number) => `共 ${total} 条数据`, | |
| 45 | + current: 1, | |
| 46 | + pageSize: unref(listColumn) * 2, | |
| 47 | + onChange: (page: number) => { | |
| 48 | + pagination.current = page; | |
| 49 | + getListData(); | |
| 50 | + }, | |
| 51 | + }); | |
| 52 | + | |
| 53 | + const loading = ref(false); | |
| 54 | + | |
| 55 | + const dataSource = ref<ConfigurationCenterItemsModal[]>([]); | |
| 56 | + | |
| 57 | + const [registerForm, { getFieldsValue }] = useForm({ | |
| 58 | + schemas: searchFormSchema, | |
| 59 | + showAdvancedButton: true, | |
| 60 | + labelWidth: 100, | |
| 61 | + compact: true, | |
| 62 | + resetFunc: () => { | |
| 63 | + resetFn(); | |
| 64 | + organizationId.value = null; | |
| 65 | + return getListData(); | |
| 66 | + }, | |
| 67 | + submitFunc: async () => { | |
| 68 | + const value = getFieldsValue(); | |
| 69 | + getListData(value); | |
| 70 | + }, | |
| 71 | + }); | |
| 72 | + | |
| 73 | + async function getListData(value: Recordable = {}) { | |
| 74 | + try { | |
| 75 | + loading.value = true; | |
| 76 | + const pageSize = unref(listColumn) * 2; | |
| 77 | + const { items, total } = await getPage({ | |
| 78 | + organizationId: unref(organizationId), | |
| 79 | + ...value, | |
| 80 | + page: pagination.current!, | |
| 81 | + pageSize, | |
| 82 | + }); | |
| 83 | + | |
| 84 | + dataSource.value = items; | |
| 85 | + Object.assign(pagination, { total, pageSize }); | |
| 86 | + } catch (error) { | |
| 87 | + } finally { | |
| 88 | + loading.value = false; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + onMounted(() => { | |
| 93 | + getListData(); | |
| 94 | + }); | |
| 95 | + | |
| 96 | + const searchInfo = reactive<Recordable>({}); | |
| 97 | + const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); | |
| 98 | + const handleSelect = (orgId: number) => { | |
| 99 | + organizationId.value = orgId; | |
| 100 | + getListData(); | |
| 101 | + }; | |
| 102 | + | |
| 103 | + const [registerDrawer, { openDrawer }] = useDrawer(); | |
| 104 | + | |
| 105 | + const { hasPermission } = usePermission(); | |
| 106 | + | |
| 107 | + const getPreviewFlag = computed(() => { | |
| 108 | + return hasPermission(ConfigurationPermission.PREVIEW); | |
| 109 | + }); | |
| 110 | + | |
| 111 | + const getDesignFlag = computed(() => { | |
| 112 | + return hasPermission(ConfigurationPermission.DESIGN); | |
| 113 | + }); | |
| 114 | + | |
| 115 | + const getShareFlag = computed(() => { | |
| 116 | + return hasPermission(ConfigurationPermission.SHARE); | |
| 117 | + }); | |
| 118 | + | |
| 119 | + const handleCreateOrUpdate = (record?: ConfigurationCenterItemsModal) => { | |
| 120 | + if (record) { | |
| 121 | + openDrawer(true, { | |
| 122 | + isUpdate: true, | |
| 123 | + record: cloneDeep(record), | |
| 124 | + }); | |
| 125 | + } else { | |
| 126 | + openDrawer(true, { | |
| 127 | + isUpdate: false, | |
| 128 | + }); | |
| 129 | + } | |
| 130 | + }; | |
| 131 | + | |
| 132 | + const handlePreview = (record: ConfigurationCenterItemsModal) => { | |
| 133 | + if (!unref(getPreviewFlag)) return; | |
| 134 | + createScadaPageLink(record, ScadaModeEnum.LIGHTBOX); | |
| 135 | + }; | |
| 136 | + | |
| 137 | + const handleDesign = (record: ConfigurationCenterItemsModal) => { | |
| 138 | + if (!unref(getDesignFlag)) return; | |
| 139 | + | |
| 140 | + createScadaPageLink(record, ScadaModeEnum.DESIGN); | |
| 141 | + }; | |
| 142 | + | |
| 143 | + const handleDelete = async (record: ConfigurationCenterItemsModal) => { | |
| 144 | + try { | |
| 145 | + await deleteConfigurationCenter([record.id]); | |
| 146 | + createMessage.success('删除成功'); | |
| 147 | + await getListData(); | |
| 148 | + } catch (error) {} | |
| 149 | + }; | |
| 150 | + | |
| 151 | + const handleCardLayoutChange = () => { | |
| 152 | + pagination.current = 1; | |
| 153 | + getListData(); | |
| 154 | + }; | |
| 155 | + | |
| 156 | + const createShareUrl = (record: ConfigurationCenterItemsModal) => { | |
| 157 | + return createScadaPageLink(record, ScadaModeEnum.SHARE, false); | |
| 158 | + }; | |
| 159 | + | |
| 160 | + const { copied, copy } = useClipboard({ legacy: true }); | |
| 161 | + const handleCreateShareUrl = async (record: ConfigurationCenterItemsModal) => { | |
| 162 | + if (!unref(getShareFlag)) return; | |
| 163 | + const url = createShareUrl(record); | |
| 164 | + await copy(url); | |
| 165 | + if (unref(copied)) { | |
| 166 | + createMessage.success('复制成功~'); | |
| 167 | + } | |
| 168 | + }; | |
| 169 | + | |
| 170 | + const [registerShareModal, { openModal }] = useModal(); | |
| 171 | + | |
| 172 | + const handleOpenShareModal = (record: ConfigurationCenterItemsModal) => { | |
| 173 | + openModal(true, { record, href: createShareUrl(record) }); | |
| 174 | + }; | |
| 175 | + | |
| 176 | + const listEl = ref<Nullable<ComponentElRef>>(null); | |
| 177 | + | |
| 178 | + onMounted(() => { | |
| 179 | + const clientHeight = document.documentElement.clientHeight; | |
| 180 | + const rect = getBoundingClientRect(unref(listEl)!.$el! as HTMLElement) as DOMRect; | |
| 181 | + // margin-top 24 height 24 | |
| 182 | + const paginationHeight = 24 + 24 + 8; | |
| 183 | + // list pading top 8 maring-top 8 extra slot 56 | |
| 184 | + const listContainerMarginBottom = 8 + 8 + 56; | |
| 185 | + const listContainerHeight = | |
| 186 | + clientHeight - rect.top - paginationHeight - listContainerMarginBottom; | |
| 187 | + const listContainerEl = (unref(listEl)!.$el as HTMLElement).querySelector( | |
| 188 | + '.ant-spin-container' | |
| 189 | + ) as HTMLElement; | |
| 190 | + listContainerEl && | |
| 191 | + (listContainerEl.style.height = listContainerHeight + 'px') && | |
| 192 | + (listContainerEl.style.overflowY = 'auto') && | |
| 193 | + (listContainerEl.style.overflowX = 'hidden'); | |
| 194 | + }); | |
| 195 | +</script> | |
| 196 | + | |
| 197 | +<template> | |
| 198 | + <PageWrapper dense contentFullHeight contentClass="flex"> | |
| 199 | + <OrganizationIdTree @select="handleSelect" ref="organizationIdTreeRef" /> | |
| 200 | + <section class="flex-auto p-4 w-3/4 xl:w-4/5 w-full configuration-list"> | |
| 201 | + <div class="flex-auto w-full bg-light-50 dark:bg-dark-900 p-4"> | |
| 202 | + <BasicForm @register="registerForm" /> | |
| 203 | + </div> | |
| 204 | + <List | |
| 205 | + ref="listEl" | |
| 206 | + :loading="loading" | |
| 207 | + class="flex-auto bg-light-50 dark:bg-dark-900 !p-2 !mt-4" | |
| 208 | + position="bottom" | |
| 209 | + :pagination="pagination" | |
| 210 | + :data-source="dataSource" | |
| 211 | + :grid="{ gutter: 4, column: listColumn }" | |
| 212 | + > | |
| 213 | + <template #header> | |
| 214 | + <div class="flex gap-3 justify-end"> | |
| 215 | + <Authority v-if="!isCustomerUser" :value="ConfigurationPermission.CREATE"> | |
| 216 | + <Button type="primary" @click="handleCreateOrUpdate()">新增组态</Button> | |
| 217 | + </Authority> | |
| 218 | + <CardLayoutButton v-model:value="listColumn" @change="handleCardLayoutChange" /> | |
| 219 | + <Tooltip title="刷新"> | |
| 220 | + <Button type="primary" @click="getListData"> | |
| 221 | + <ReloadOutlined /> | |
| 222 | + </Button> | |
| 223 | + </Tooltip> | |
| 224 | + </div> | |
| 225 | + </template> | |
| 226 | + <template #renderItem="{ item }"> | |
| 227 | + <List.Item> | |
| 228 | + <Card | |
| 229 | + :style="{ | |
| 230 | + '--viewType': item.viewType === ViewType.PUBLIC_VIEW ? '#1890ff' : '#faad14', | |
| 231 | + }" | |
| 232 | + hoverable | |
| 233 | + class="card-container" | |
| 234 | + > | |
| 235 | + <template #cover> | |
| 236 | + <div | |
| 237 | + class="img-container h-full w-full !flex justify-center items-center text-center p-1 relative" | |
| 238 | + > | |
| 239 | + <img | |
| 240 | + class="w-full h-36" | |
| 241 | + alt="example" | |
| 242 | + :src="item.thumbnail || configurationSrc" | |
| 243 | + @click="handlePreview(item)" | |
| 244 | + /> | |
| 245 | + <span | |
| 246 | + class="absolute top-0 left-0 text-light-50 transform -rotate-45 translate-y-1" | |
| 247 | + > | |
| 248 | + {{ ViewTypeNameEnum[item.viewType] || ViewTypeNameEnum.PRIVATE_VIEW }} | |
| 249 | + </span> | |
| 250 | + </div> | |
| 251 | + </template> | |
| 252 | + <template class="ant-card-actions" #actions> | |
| 253 | + <Tooltip title="预览"> | |
| 254 | + <AuthIcon | |
| 255 | + :auth="ConfigurationPermission.PREVIEW" | |
| 256 | + class="!text-lg" | |
| 257 | + icon="ant-design:eye-outlined" | |
| 258 | + @click="handlePreview(item)" | |
| 259 | + /> | |
| 260 | + </Tooltip> | |
| 261 | + <Tooltip v-if="!isCustomerUser" title="设计"> | |
| 262 | + <AuthIcon | |
| 263 | + :auth="ConfigurationPermission.DESIGN" | |
| 264 | + class="!text-lg" | |
| 265 | + icon="ant-design:edit-outlined" | |
| 266 | + @click="handleDesign(item)" | |
| 267 | + /> | |
| 268 | + </Tooltip> | |
| 269 | + <Tooltip title="点击复制分享链接"> | |
| 270 | + <AuthIcon | |
| 271 | + :auth="ConfigurationPermission.SHARE" | |
| 272 | + :disabled="!item.publicId" | |
| 273 | + class="!text-lg" | |
| 274 | + icon="ant-design:share-alt-outlined" | |
| 275 | + @click="handleCreateShareUrl(item)" | |
| 276 | + /> | |
| 277 | + </Tooltip> | |
| 278 | + <AuthDropDown | |
| 279 | + v-if="!isCustomerUser" | |
| 280 | + :dropMenuList="[ | |
| 281 | + { | |
| 282 | + text: '分享', | |
| 283 | + auth: ConfigurationPermission.SHARE, | |
| 284 | + icon: 'ant-design:share-alt-outlined', | |
| 285 | + event: '', | |
| 286 | + onClick: handleOpenShareModal.bind(null, item), | |
| 287 | + }, | |
| 288 | + { | |
| 289 | + text: '编辑', | |
| 290 | + auth: ConfigurationPermission.UPDATE, | |
| 291 | + icon: 'clarity:note-edit-line', | |
| 292 | + event: '', | |
| 293 | + onClick: handleCreateOrUpdate.bind(null, item), | |
| 294 | + }, | |
| 295 | + { | |
| 296 | + text: '删除', | |
| 297 | + auth: ConfigurationPermission.DELETE, | |
| 298 | + icon: 'ant-design:delete-outlined', | |
| 299 | + event: '', | |
| 300 | + popconfirm: { | |
| 301 | + title: '是否确认删除操作?', | |
| 302 | + onConfirm: handleDelete.bind(null, item), | |
| 303 | + }, | |
| 304 | + }, | |
| 305 | + ]" | |
| 306 | + :trigger="['hover']" | |
| 307 | + /> | |
| 308 | + </template> | |
| 309 | + <Card.Meta> | |
| 310 | + <template #title> | |
| 311 | + <span class="truncate">{{ item.name }}</span> | |
| 312 | + </template> | |
| 313 | + <template #description> | |
| 314 | + <div class="truncate h-11"> | |
| 315 | + <div class="truncate flex justify-between items-center"> | |
| 316 | + <div>{{ item.organizationDTO.name }}</div> | |
| 317 | + <Icon | |
| 318 | + :icon=" | |
| 319 | + item.platform === Platform.PC | |
| 320 | + ? 'ri:computer-line' | |
| 321 | + : 'clarity:mobile-phone-solid' | |
| 322 | + " | |
| 323 | + /> | |
| 324 | + </div> | |
| 325 | + <div class="truncate">{{ item.remark || '' }} </div> | |
| 326 | + </div> | |
| 327 | + </template> | |
| 328 | + </Card.Meta> | |
| 329 | + </Card> | |
| 330 | + </List.Item> | |
| 331 | + </template> | |
| 332 | + </List> | |
| 333 | + </section> | |
| 334 | + <ConfigurationCenterDrawer @register="registerDrawer" @success="getListData" /> | |
| 335 | + <ShareModal | |
| 336 | + @register="registerShareModal" | |
| 337 | + :shareApi="shareConfiguration" | |
| 338 | + @success="getListData" | |
| 339 | + /> | |
| 340 | + </PageWrapper> | |
| 341 | +</template> | |
| 342 | + | |
| 343 | +<style lang="less" scoped> | |
| 344 | + .configuration-list:deep(.ant-list-header) { | |
| 345 | + border-bottom: none !important; | |
| 346 | + } | |
| 347 | + | |
| 348 | + .configuration-list:deep(.ant-list-pagination) { | |
| 349 | + height: 24px; | |
| 350 | + } | |
| 351 | + | |
| 352 | + .configuration-list:deep(.ant-card-body) { | |
| 353 | + padding: 16px !important; | |
| 354 | + } | |
| 355 | + | |
| 356 | + .configuration-list:deep(.ant-list-empty-text) { | |
| 357 | + @apply w-full h-full flex justify-center items-center; | |
| 358 | + } | |
| 359 | + | |
| 360 | + .card-container { | |
| 361 | + // background-color: red; | |
| 362 | + .img-container { | |
| 363 | + border-top-left-radius: 80px; | |
| 364 | + background-color: #fff; | |
| 365 | + | |
| 366 | + img { | |
| 367 | + border-top-left-radius: 80px; | |
| 368 | + } | |
| 369 | + } | |
| 370 | + } | |
| 371 | + | |
| 372 | + .card-container:deep(.ant-card-cover) { | |
| 373 | + background-color: var(--viewType); | |
| 374 | + } | |
| 375 | +</style> | ... | ... |