From 328e4b2c2f7c3da74c9b2e82e0f23c270d26036a Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Thu, 23 Oct 2025 11:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E4=BA=A7=E5=93=81=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=B7=B2=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api-client/services.gen.ts | 4 +- .../devicemanagement/thingmodelinfo/index.vue | 86 +++++++++++++++++++ .../devicemanagement/thingmodelinfo/schema.ts | 81 ++++++++++++++++- 3 files changed, 168 insertions(+), 3 deletions(-) diff --git a/apps/web-antd/src/api-client/services.gen.ts b/apps/web-antd/src/api-client/services.gen.ts index b54c514..1cb60e9 100644 --- a/apps/web-antd/src/api-client/services.gen.ts +++ b/apps/web-antd/src/api-client/services.gen.ts @@ -517,7 +517,7 @@ export const postThingModelInfoFindByPlatformProductIdAsync = (options?: Options) => { return (options?.client ?? client).post({ @@ -537,7 +537,7 @@ export const postThingModelInfoCopyStandardThingModel = (options?: Options) => { return (options?.client ?? client).post({ diff --git a/apps/web-antd/src/views/devicemanagement/thingmodelinfo/index.vue b/apps/web-antd/src/views/devicemanagement/thingmodelinfo/index.vue index 47cef50..733ab16 100644 --- a/apps/web-antd/src/views/devicemanagement/thingmodelinfo/index.vue +++ b/apps/web-antd/src/views/devicemanagement/thingmodelinfo/index.vue @@ -11,6 +11,7 @@ import { message as Message, Modal, Tag } from 'ant-design-vue'; import { useVbenForm } from '#/adapter/form'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { + postThingModelInfoCopyAnotherThingModelAsync, postThingModelInfoCopyStandardThingModel, postThingModelInfoCreateAsync, postThingModelInfoDeleteAsync, @@ -22,6 +23,7 @@ import { $t } from '#/locales'; import { addThingModelFormSchema, + copyThingModelFormSchema, editThingModelFormSchema, querySchema, tableSchema, @@ -83,6 +85,8 @@ const gridOptions: VxeGridProps = { ...formValues, }, }); + // 更新数据状态,检查是否有数据 + hasData.value = data?.items && data.items.length > 0; return data; }, }, @@ -93,6 +97,10 @@ const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions }); const editRow: Record = ref({}); +// 跟踪数据状态,用于控制按钮显示 +const hasData = ref(true); + + const [ThingModelModal, thingModelModalApi] = useVbenModal({ draggable: true, footer: true, @@ -115,6 +123,20 @@ const [ThingModelModal, thingModelModalApi] = useVbenModal({ }, }); +const [CopyModal, copyModalApi] = useVbenModal({ + draggable: true, + footer: true, + showCancelButton: true, + showConfirmButton: true, + onConfirm: submitCopy, + onBeforeClose: () => { + return true; + }, + onCancel: () => { + copyModalApi.close(); + }, +}); + const [AddForm, addFormApi] = useVbenForm({ collapsed: false, commonConfig: { @@ -145,6 +167,21 @@ const [EditForm, editFormApi] = useVbenForm({ wrapperClass: 'grid-cols-2', }); +const [CopyForm, copyFormApi] = useVbenForm({ + collapsed: false, + commonConfig: { + labelWidth: 110, + componentProps: { + class: 'w-4/5', + }, + }, + layout: 'horizontal', + schema: copyThingModelFormSchema.value, + showCollapseButton: false, + showDefaultActions: false, + wrapperClass: 'grid-cols-2', +}); + // 监听props变化,自动设置筛选条件 watch( () => [props.visible, props.productId, props.ioTPlatform], @@ -235,6 +272,41 @@ const openAddModal = async () => { thingModelModalApi.open(); }; +// 打开复制已有模型模态框 +const openCopyAnotherThingModelModal = async () => { + copyModalApi.open(); +}; + +// 复制提交逻辑 +async function submitCopy() { + const { valid } = await copyFormApi.validate(); + if (!valid) return; + + const formValues = await copyFormApi.getValues(); + + try { + const resp = await postThingModelInfoCopyAnotherThingModelAsync({ + body: { + ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2, + ioTPlatformProductId: props.productId, + sourceProductId: formValues.sourceProductId, + filedType: formValues.filedType, + }, + }); + + if (resp.data) { + Message.success('复制模型成功'); + copyModalApi.close(); + gridApi.reload(); + } else { + Message.error('复制模型失败'); + } + } catch (error) { + console.error('复制模型失败:', error); + Message.error('复制模型失败'); + } +} + // 删除函数 async function onDel(record: any) { try { @@ -279,6 +351,7 @@ function closeModal() { emit('update:visible', false); emit('close'); } + @@ -343,4 +424,9 @@ function closeModal() { + + + + + diff --git a/apps/web-antd/src/views/devicemanagement/thingmodelinfo/schema.ts b/apps/web-antd/src/views/devicemanagement/thingmodelinfo/schema.ts index 4d467ab..4af2ca8 100644 --- a/apps/web-antd/src/views/devicemanagement/thingmodelinfo/schema.ts +++ b/apps/web-antd/src/views/devicemanagement/thingmodelinfo/schema.ts @@ -4,7 +4,7 @@ import { z } from '@vben/common-ui'; import dayjs from 'dayjs'; -import { getCommonGetSelectList } from '#/api-client'; +import { getCommonGetSelectList, postOneNetProductListAsync } from '#/api-client'; import { $t } from '#/locales'; export const querySchema = computed(() => [ @@ -360,3 +360,82 @@ export const editThingModelFormSchema = computed(() => [ }, }, ]); + +// 复制已有模型表单schema +export const copyThingModelFormSchema = computed(() => [ + { + component: 'ApiSelect', + fieldName: 'sourceProductId', + label: '选择要复制的产品', + rules: z.preprocess( + (v) => (v == null ? '' : v), + z.string().min(1, '请选择要复制的产品'), + ), + componentProps: { + api: postOneNetProductListAsync, + params: { + query: { + input: { + pageIndex: 1, + pageSize: 1000, + }, + }, + }, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'items', + immediate: true, + allowClear: true, + placeholder: '请选择产品', + afterFetch: (res: any) => { + // 确保返回的是数组格式 + if (Array.isArray(res)) { + return res; + } + if (res && Array.isArray(res.items)) { + return res.items; + } + if (res && Array.isArray(res.data)) { + return res.data; + } + return []; + }, + }, + }, + { + component: 'ApiSelect', + fieldName: 'filedType', + label: '选择物模型类型', + rules: z.preprocess( + (v) => (v == null ? '' : v), + z.string().min(1, '请选择物模型类型'), + ), + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + typeName: 'DataDictionaryTypeConst', + }, + }, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: true, + allowClear: true, + placeholder: '请选择物模型类型', + afterFetch: (res: any) => { + // 确保返回的是数组格式 + if (Array.isArray(res)) { + return res; + } + if (res && Array.isArray(res.items)) { + return res.items; + } + if (res && Array.isArray(res.data)) { + return res.data; + } + return []; + }, + }, + }, +]);