From 031364ba7eb7b4d8c5cbf4337c43f88f1c6533b2 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Wed, 17 Dec 2025 17:04:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AB=AF=E7=89=A9=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api-client/schemas.gen.ts | 6 + apps/web-antd/src/api-client/types.gen.ts | 2 + .../StandardThingModelCodeSelect.vue | 188 ------ .../deviceThingModelManagement/index.vue | 396 +++++------- .../deviceThingModelManagement/schema.ts | 592 +++++++++--------- 5 files changed, 438 insertions(+), 746 deletions(-) delete mode 100644 apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/StandardThingModelCodeSelect.vue diff --git a/apps/web-antd/src/api-client/schemas.gen.ts b/apps/web-antd/src/api-client/schemas.gen.ts index 0b6ede7..41be258 100644 --- a/apps/web-antd/src/api-client/schemas.gen.ts +++ b/apps/web-antd/src/api-client/schemas.gen.ts @@ -2544,6 +2544,9 @@ export const DeviceThingModelCreateInputSchema = { type: 'string', description: '脚本函数体', nullable: true + }, + parsingSequence: { + '$ref': '#/components/schemas/ParsingSequenceTypeEnum' } }, additionalProperties: false @@ -3105,6 +3108,9 @@ export const DeviceThingModelUpdateInputSchema = { description: '脚本函数体', nullable: true }, + parsingSequence: { + '$ref': '#/components/schemas/ParsingSequenceTypeEnum' + }, id: { type: 'string', format: 'uuid' diff --git a/apps/web-antd/src/api-client/types.gen.ts b/apps/web-antd/src/api-client/types.gen.ts index 5a6d5f3..81dd359 100644 --- a/apps/web-antd/src/api-client/types.gen.ts +++ b/apps/web-antd/src/api-client/types.gen.ts @@ -1433,6 +1433,7 @@ export type DeviceThingModelCreateInput = { * 脚本函数体 */ functionScript?: (string) | null; + parsingSequence?: ParsingSequenceTypeEnum; }; /** @@ -1796,6 +1797,7 @@ export type DeviceThingModelUpdateInput = { * 脚本函数体 */ functionScript?: (string) | null; + parsingSequence?: ParsingSequenceTypeEnum; id?: string; }; diff --git a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/StandardThingModelCodeSelect.vue b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/StandardThingModelCodeSelect.vue deleted file mode 100644 index de4d207..0000000 --- a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/StandardThingModelCodeSelect.vue +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - diff --git a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue index f9c975a..018ef1a 100644 --- a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue +++ b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue @@ -2,66 +2,91 @@ import type { VbenFormProps } from '#/adapter/form'; import type { VxeGridProps } from '#/adapter/vxe-table'; -import { h, nextTick, ref, watch } from 'vue'; +import { h, nextTick, ref } from 'vue'; +import { useRoute } from 'vue-router'; -import { useVbenModal } from '@vben/common-ui'; +import { Page, useVbenModal } from '@vben/common-ui'; -import { message as Message, Modal, Tag } from 'ant-design-vue'; +import { message as Message, Tag } from 'ant-design-vue'; import { useVbenForm } from '#/adapter/form'; import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { - postIoTplatformThingModelInfoCopyAnotherThingModelAsync, - postIoTplatformThingModelInfoCopyStandardThingModel, - postIoTplatformThingModelInfoCreateAsync, - postIoTplatformThingModelInfoDeleteAsync, - postIoTplatformThingModelInfoPageAsync, - postIoTplatformThingModelInfoUpdateAsync, + postDeviceThingModelManagementCreateAsync, + postDeviceThingModelManagementDeleteAsync, + postDeviceThingModelManagementPageAsync, + postDeviceThingModelManagementUpdateAsync, } from '#/api-client'; import { TableAction } from '#/components/table-action'; import { $t } from '#/locales'; import { - addThingModelFormSchema, - copyThingModelFormSchema, - editThingModelFormSchema, + addDeviceThingModelFormSchema, + editDeviceThingModelFormSchema, querySchema, tableSchema, } from './schema'; defineOptions({ - name: 'ThingModelInfoModal', + name: 'DeviceThingModelManagement', }); -const props = withDefaults(defineProps(), { - visible: false, - productId: '', - productName: '', - ioTPlatform: '2', -}); +const route = useRoute(); -// 定义emits -const emit = defineEmits<{ - close: []; - 'update:visible': [value: boolean]; -}>(); - -// 定义props -interface Props { - visible?: boolean; - productId?: string; - productName?: string; - ioTPlatform?: string; -} +// 从路由参数获取初始平台和产品信息(如果有) +const productId = ref((route.query.productId as string) || ''); +const ioTPlatform = ref((route.query.ioTPlatform as string) || ''); const formOptions: VbenFormProps = { schema: querySchema.value, + initialValues: { + ioTPlatform: route.query.ioTPlatform + ? String(route.query.ioTPlatform) + : undefined, + ioTPlatformProductId: route.query.productId + ? String(route.query.productId) + : undefined, + }, + submitOnChange: false, + handleValuesChange: async (values, changedFields) => { + // 平台变化时,清空产品并更新状态 + if (changedFields.includes('ioTPlatform')) { + if (values.ioTPlatform) { + ioTPlatform.value = String(values.ioTPlatform); + if (gridApi?.formApi) { + await gridApi.formApi.setValues({ + ioTPlatformProductId: undefined, + }); + } + productId.value = ''; + } + } + + // 产品变化时,更新 productId 并刷新列表 + if (changedFields.includes('ioTPlatformProductId')) { + if (values.ioTPlatformProductId) { + productId.value = String(values.ioTPlatformProductId); + } else { + productId.value = ''; + } + + setTimeout(async () => { + if (gridApi && gridApi.reload) { + try { + await gridApi.reload(); + } catch (error) { + console.error('重新加载设备端物模型列表时出错:', error); + } + } + }, 100); + } + }, }; const gridOptions: VxeGridProps = { checkboxConfig: { highlight: true, - labelField: 'thingModelName', + labelField: 'deviceModelName', }, columns: tableSchema.value, height: 'auto', @@ -76,20 +101,40 @@ const gridOptions: VxeGridProps = { proxyConfig: { ajax: { query: async ({ page }, formValues) => { - const { data } = await postIoTplatformThingModelInfoPageAsync({ - query: { - input: { + // 优先使用表单值,如果没有则使用响应式变量 + const currentPlatform = formValues?.ioTPlatform || ioTPlatform.value; + const currentProductId = + formValues?.ioTPlatformProductId || productId.value; + + if (!currentPlatform || !currentProductId) { + return { + items: [], + totalCount: 0, + }; + } + + try { + const { data } = await postDeviceThingModelManagementPageAsync({ + body: { pageIndex: page.currentPage, pageSize: page.pageSize, - ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2, - ioTPlatformProductId: props.productId, - ...(formValues?.SearchKeyWords && { searchKeyWords: formValues.SearchKeyWords }), + ioTPlatform: + typeof currentPlatform === 'string' + ? Number.parseInt(currentPlatform) + : currentPlatform, + ioTPlatformProductId: String(currentProductId), + searchKeyWords: formValues?.SearchKeyWords, }, - }, - }); - // 更新数据状态,检查是否有数据 - hasData.value = data?.items && data.items.length > 0; - return data; + }); + + return data || { items: [], totalCount: 0 }; + } catch (error) { + console.error('查询设备端物模型列表失败:', error); + return { + items: [], + totalCount: 0, + }; + } }, }, }, @@ -99,9 +144,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions }); const editRow: Record = ref({}); -// 跟踪数据状态,用于控制按钮显示 -const hasData = ref(true); - const [ThingModelModal, thingModelModalApi] = useVbenModal({ draggable: true, footer: true, @@ -124,20 +166,6 @@ 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: { @@ -147,7 +175,7 @@ const [AddForm, addFormApi] = useVbenForm({ }, }, layout: 'horizontal', - schema: addThingModelFormSchema.value, + schema: addDeviceThingModelFormSchema.value, showCollapseButton: false, showDefaultActions: false, wrapperClass: 'grid-cols-2', @@ -162,98 +190,49 @@ const [EditForm, editFormApi] = useVbenForm({ }, }, layout: 'horizontal', - schema: editThingModelFormSchema.value, + schema: editDeviceThingModelFormSchema.value, showCollapseButton: false, showDefaultActions: false, 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], - async ([visible, productId, ioTPlatform]) => { - console.log('物模型模态框props变化:', { visible, productId, ioTPlatform }); - console.log('所有props:', props); - if (visible && productId) { - // 延迟执行,确保组件完全初始化 - setTimeout(async () => { - try { - // 设置表单筛选条件(如果有搜索关键词等筛选字段) - const filterValues: any = {}; - - // 注意:ioTPlatformProductId 已经在 API 调用中通过 props.productId 传递 - // 这里只需要设置查询表单中存在的字段(如 SearchKeyWords) - - console.log('设置筛选条件:', filterValues); - - // 设置筛选表单的值 - if (Object.keys(filterValues).length > 0) { - await gridApi.formApi.setValues(filterValues); - } - // 重新加载数据(即使没有筛选条件也要重新加载,因为 productId 可能已变化) - await gridApi.reload(); - } catch (error) { - console.error('设置筛选条件时出错:', error); - } - }, 100); - } - }, - { immediate: true }, -); - -// 新增和编辑提交的逻辑 +// 新增 / 编辑提交 async function submit() { const isEdit = !!editRow.value.id; const formApi = isEdit ? editFormApi : addFormApi; const api = isEdit - ? postIoTplatformThingModelInfoUpdateAsync - : postIoTplatformThingModelInfoCreateAsync; + ? postDeviceThingModelManagementUpdateAsync + : postDeviceThingModelManagementCreateAsync; + const { valid } = await formApi.validate(); if (!valid) return; - const formValues = await formApi.getValues(); + const formValues = await formApi.getValues(); + + // 表单中已经包含 ioTPlatform / ioTPlatformProductId,不再强制从查询条件取 const fetchParams: any = { ...formValues, - // 自动添加平台和产品信息 - ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2, - ioTPlatformProductId: props.productId, - // 编辑时需要添加ID ...(isEdit && { id: editRow.value.id }), }; try { - const resp = await api({ query: { input: fetchParams } }); + const resp = await api({ body: fetchParams }); if (resp.data) { Message.success( - editRow.value.id ? $t('common.editSuccess') : $t('common.addSuccess'), + isEdit ? $t('common.editSuccess') : $t('common.addSuccess'), ); thingModelModalApi.close(); editRow.value = {}; gridApi.reload(); } else { Message.error( - editRow.value.id ? $t('common.editFail') : $t('common.addFail'), + isEdit ? $t('common.editFail') : $t('common.addFail'), ); } } catch (error) { - console.error('提交失败:', error); + console.error('提交设备端物模型失败:', error); Message.error( - editRow.value.id ? $t('common.editFail') : $t('common.addFail'), + isEdit ? $t('common.editFail') : $t('common.addFail'), ); } } @@ -268,63 +247,11 @@ const openAddModal = async () => { thingModelModalApi.open(); }; -// 打开复制已有模型模态框 -const openCopyAnotherThingModelModal = async () => { - console.log('打开复制模态框,当前props:', { - productId: props.productId, - productName: props.productName, - ioTPlatform: props.ioTPlatform, - }); - copyModalApi.open(); -}; - -// 复制提交逻辑 -async function submitCopy() { - const { valid } = await copyFormApi.validate(); - if (!valid) return; - - const formValues = await copyFormApi.getValues(); - - console.log('复制提交参数:', { - formValues, - props: { - productId: props.productId, - productName: props.productName, - ioTPlatform: props.ioTPlatform, - }, - }); - - try { - const resp = await postIoTplatformThingModelInfoCopyAnotherThingModelAsync({ - query: { - input: { - ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2, - ioTPlatformProductId: props.productId, - sourceProductId: formValues.ioTPlatformProductId, - }, - }, - }); - - 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 { - const resp = await postIoTplatformThingModelInfoDeleteAsync({ - query: { - input: { id: record.id }, - }, + const resp = await postDeviceThingModelManagementDeleteAsync({ + body: { id: record.id }, }); if (resp.data) { Message.success($t('common.deleteSuccess')); @@ -333,49 +260,18 @@ async function onDel(record: any) { Message.error($t('common.deleteFail')); } } catch (error) { - console.error('删除失败:', error); + console.error('删除设备端物模型失败:', error); Message.error($t('common.deleteFail')); } } - -// 复制标准模型函数 -async function copyStandardThingModel() { - try { - const resp = await postIoTplatformThingModelInfoCopyStandardThingModel({ - query: { - input: { - ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2, - ioTPlatformProductId: props.productId, - }, - }, - }); - if (resp.data) { - Message.success('复制标准模型成功'); - gridApi.reload(); - } else { - Message.error('复制标准模型失败'); - } - } catch (error) { - console.error('复制标准模型失败:', error); - Message.error('复制标准模型失败'); - } -} - -// 关闭模态框 -function closeModal() { - emit('update:visible', false); - emit('close'); -} - + + - - - - + ]" + /> + + + + - - - - - - + + + diff --git a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts index b69b148..c21b74b 100644 --- a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts +++ b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts @@ -6,11 +6,95 @@ import dayjs from 'dayjs'; import { getCommonGetSelectList, - postOneNetProductListAsync, + postAggregationIoTplatformGetIoTplatformProductInfoAsync, } from '#/api-client'; import { $t } from '#/locales'; +// 查询表单配置 export const querySchema = computed(() => [ + { + component: 'ApiSelect', + fieldName: 'ioTPlatform', + label: $t('abp.deviceInfos.ioTPlatform'), + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + typeName: 'IoTPlatformTypeEnum', + }, + }, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: true, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'), + 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: 'ioTPlatformProductId', + label: $t('common.BelongingProductName'), + dependencies: { + show(values: any) { + return !!values.ioTPlatform; + }, + triggerFields: ['ioTPlatform'], + }, + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + // 聚合服务要求 JSON Body 传参 + params: { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + }, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + $t('common.BelongingProductName'), + 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; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; + }, + }, { component: 'Input', fieldName: 'SearchKeyWords', @@ -18,64 +102,55 @@ export const querySchema = computed(() => [ }, ]); +// 列表列配置 export const tableSchema = computed(() => [ { - field: 'filedType', - title: $t('abp.thingModelInfos.FiledType'), + field: 'deviceModelName', + title: '设备端物模型名称', + minWidth: 180, + showOverflow: 'tooltip', + }, + { + field: 'ioTPlatform', + title: $t('abp.deviceInfos.ioTPlatform'), minWidth: 120, showOverflow: 'tooltip', formatter: ({ cellValue }: { cellValue: any }) => { - const typeMap: Record = { - Property: '属性', - Service: '服务', - Event: '事件', + const map: Record = { + 1: 'CTWing', + 2: 'OneNET', }; - return typeMap[cellValue] || cellValue; + return map[cellValue] || cellValue || '-'; }, }, { - field: 'ioTPlatformRawFieldName', - title: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - minWidth: 150, + field: 'ioTPlatformProductId', + title: '平台产品ID', + minWidth: 160, showOverflow: 'tooltip', }, { - field: 'standardFieldName', - title: $t('abp.thingModelInfos.StandardFieldName'), - minWidth: 150, + field: 'scriptName', + title: '脚本函数名称', + minWidth: 160, showOverflow: 'tooltip', }, { - field: 'standardFieldDisplayName', - title: $t('abp.thingModelInfos.StandardFieldDisplayName'), - minWidth: 150, - showOverflow: 'tooltip', - }, - { - field: 'standardFieldValueType', - title: $t('abp.thingModelInfos.StandardFieldValueType'), + field: 'parsingSequence', + title: '解析顺序', minWidth: 120, showOverflow: 'tooltip', formatter: ({ cellValue }: { cellValue: any }) => { - const typeMap: Record = { - String: '字符串', - Int32: '整数', - Int64: '长整数', - Float: '浮点数', - Double: '双精度', - Boolean: '布尔值', - DateTime: '日期时间', - Object: 'JSON对象', - Array: '数组', - }; - return typeMap[cellValue] || cellValue; + if (cellValue === 1) return '正序'; + if (cellValue === 2) return '高低位反转'; + return cellValue ?? '-'; }, }, { - field: 'isValueNeedConvert', - title: $t('abp.thingModelInfos.IsValueNeedConvert'), - minWidth: 120, - slots: { default: 'isValueNeedConvert' }, + field: 'functionAnalysisFlag', + title: '解析启用', + minWidth: 100, + slots: { default: 'functionAnalysisFlag' }, }, { field: 'creationTime', @@ -94,21 +169,29 @@ export const tableSchema = computed(() => [ }, ]); -// 添加物模型表单schema -export const addThingModelFormSchema = computed(() => [ +// 新增设备端物模型表单 +export const addDeviceThingModelFormSchema = computed(() => [ + { + component: 'Input', + fieldName: 'deviceModelName', + label: '设备端物模型名称', + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), + componentProps: { + placeholder: $t('common.pleaseInput') + '设备端物模型名称', + }, + }, { component: 'ApiSelect', - fieldName: 'filedType', - label: $t('abp.thingModelInfos.FiledType'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), + fieldName: 'ioTPlatform', + label: $t('abp.deviceInfos.ioTPlatform'), + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { api: getCommonGetSelectList, params: { query: { - typeName: 'DataDictionaryTypeConst', + typeName: 'IoTPlatformTypeEnum', }, }, labelField: 'value', @@ -117,9 +200,8 @@ export const addThingModelFormSchema = computed(() => [ immediate: true, allowClear: true, placeholder: - $t('common.pleaseSelect') + $t('abp.thingModelInfos.FiledType'), + $t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'), afterFetch: (res: any) => { - // 确保返回的是数组格式 if (Array.isArray(res)) { return res; } @@ -133,270 +215,107 @@ export const addThingModelFormSchema = computed(() => [ }, }, }, - { - component: 'Input', - fieldName: 'ioTPlatformRawFieldName', - label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: { - placeholder: - $t('common.pleaseInput') + - $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - }, - }, - { - component: 'StandardThingModelCodeSelect', - fieldName: 'standardFieldDisplayName', - label: $t('abp.thingModelInfos.StandardFieldDisplayName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: (formValues: any) => ({ - // 传入联动的类型编码(运行时具体值) - typeCode: formValues?.filedType ?? null, - onResolve: (item: any | null) => { - // 选择后自动回填:名称=displayText,值类型=extendedAttribute(转大写) - formValues.standardFieldDisplayName = item?.displayText ?? ''; - formValues.standardFieldName = item?.code ?? ''; - formValues.standardFieldValueType = (item?.extendedAttribute ?? '') - .toString() - .toUpperCase(); - }, - placeholder: - $t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'), - }), - }, - { - component: 'Input', - fieldName: 'standardFieldName', - label: $t('abp.thingModelInfos.StandardFieldName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: { - placeholder: - $t('common.pleaseInput') + - $t('abp.thingModelInfos.StandardFieldDisplayName'), - }, - }, - { - component: 'ApiSelect', - fieldName: 'standardFieldValueType', - label: $t('abp.thingModelInfos.StandardFieldValueType'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: { - api: getCommonGetSelectList, - params: { - query: { - typeName: 'StandardThingModelDataTypeEnum', - }, - }, - labelField: 'value', - valueField: 'secondValue', - optionsPropName: 'options', - immediate: true, - allowClear: true, - placeholder: - $t('common.pleaseSelect') + - $t('abp.thingModelInfos.StandardFieldValueType'), - 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: 'Switch', - fieldName: 'isValueNeedConvert', - label: $t('abp.thingModelInfos.IsValueNeedConvert'), - defaultValue: false, - componentProps: { - style: { width: 'auto' }, - }, - }, -]); - -// 编辑物模型表单schema -export const editThingModelFormSchema = computed(() => [ - { - component: 'ApiSelect', - fieldName: 'filedType', - label: $t('abp.thingModelInfos.FiledType'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: { - api: getCommonGetSelectList, - params: { - query: { - typeName: 'DataDictionaryTypeConst', - }, - }, - labelField: 'value', - valueField: 'key', - optionsPropName: 'options', - immediate: true, - disabled: true, // 编辑时禁用 - placeholder: - $t('common.pleaseSelect') + $t('abp.thingModelInfos.FiledType'), - 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: 'Input', - fieldName: 'ioTPlatformRawFieldName', - label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: { - // disabled: true, // 编辑时禁用 - placeholder: - $t('common.pleaseInput') + - $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - }, - }, - { - component: 'StandardThingModelCodeSelect', - fieldName: 'standardFieldDisplayName', - label: $t('abp.thingModelInfos.StandardFieldDisplayName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: (formValues: any) => ({ - typeCode: formValues?.filedType ?? null, - disabled: true, // 编辑时禁用 - onResolve: (item: any | null) => { - formValues.standardFieldDisplayName = item?.displayText ?? ''; - formValues.standardFieldValueType = (item?.extendedAttribute ?? '') - .toString() - .toUpperCase(); - }, - placeholder: - $t('common.pleaseInput') + - $t('abp.thingModelInfos.StandardFieldDisplayName'), - }), - }, - { - component: 'Input', - fieldName: 'standardFieldName', - label: $t('abp.thingModelInfos.StandardFieldName'), - rules: z.string().min(1, $t('common.required')), - componentProps: { - disabled: true, // 编辑时禁用 - placeholder: - $t('common.pleaseSelect') + $t('abp.thingModelInfos.StandardFieldName'), - }, - }, - { - component: 'ApiSelect', - fieldName: 'standardFieldValueType', - label: $t('abp.thingModelInfos.StandardFieldValueType'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - componentProps: { - api: getCommonGetSelectList, - params: { - query: { - typeName: 'StandardThingModelDataTypeEnum', - }, - }, - optionsPropName: 'options', - immediate: true, - allowClear: true, - disabled: true, // 编辑时禁用 - placeholder: - $t('common.pleaseSelect') + - $t('abp.thingModelInfos.StandardFieldValueType'), - afterFetch: (res: any) => { - let items = []; - if (Array.isArray(res)) { - items = res; - } else if (res && Array.isArray(res.items)) { - items = res.items; - } else if (res && Array.isArray(res.data)) { - items = res.data; - } - // 转换选项值以匹配列表中的小写值 - return items.map((item: any) => ({ - ...item, - // 使用secondValue的小写版本作为value,保持label为原始value - value: item.secondValue || item.value, - label: item.value, // 显示文本 - })); - }, - }, - }, - { - component: 'Switch', - fieldName: 'isValueNeedConvert', - label: $t('abp.thingModelInfos.IsValueNeedConvert'), - componentProps: { - style: { width: 'auto' }, - }, - }, -]); - -// 复制已有模型表单schema -export const copyThingModelFormSchema = computed(() => [ { component: 'ApiSelect', fieldName: 'ioTPlatformProductId', - label: '选择要复制的产品', - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, '请选择要复制的产品'), - ), + label: $t('common.BelongingProductName'), + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + params: { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + }, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + $t('common.BelongingProductName'), + 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; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; + }, + }, + { + component: 'Input', + fieldName: 'scriptName', + label: '脚本函数名称', + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), componentProps: { - api: postOneNetProductListAsync, + placeholder: $t('common.pleaseInput') + '脚本函数名称', + }, + }, + { + component: 'Textarea', + fieldName: 'functionScript', + label: '脚本函数体', + componentProps: { + rows: 6, + placeholder: '请输入脚本函数体(用于解析MODBUS设备数据)', + }, + }, +]); + +// 编辑设备端物模型表单 +export const editDeviceThingModelFormSchema = computed(() => [ + { + component: 'Input', + fieldName: 'deviceModelName', + label: '设备端物模型名称', + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), + componentProps: { + placeholder: $t('common.pleaseInput') + '设备端物模型名称', + }, + }, + { + component: 'ApiSelect', + fieldName: 'ioTPlatform', + label: $t('abp.deviceInfos.ioTPlatform'), + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), + componentProps: { + api: getCommonGetSelectList, params: { query: { - pageIndex: 1, - pageSize: 1000, + typeName: 'IoTPlatformTypeEnum', }, }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', + labelField: 'value', + valueField: 'key', optionsPropName: 'options', immediate: true, allowClear: true, - placeholder: '请选择产品', + disabled: true, // 编辑时不允许修改平台 + placeholder: + $t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'), afterFetch: (res: any) => { - // 确保返回的是数组格式 if (Array.isArray(res)) { return res; } @@ -406,11 +325,76 @@ export const copyThingModelFormSchema = computed(() => [ if (res && Array.isArray(res.data)) { return res.data; } - if (res && Array.isArray(res.data.items)) { - return res.data.items; - } return []; }, }, }, + { + component: 'ApiSelect', + fieldName: 'ioTPlatformProductId', + label: $t('common.BelongingProductName'), + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + params: { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + }, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + disabled: true, // 编辑时不允许修改平台产品 + placeholder: + $t('common.pleaseSelect') + $t('common.BelongingProductName'), + 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; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; + }, + }, + { + component: 'Input', + fieldName: 'scriptName', + label: '脚本函数名称', + rules: z + .preprocess((v) => (v == null ? '' : v), z.string().min(1, $t('common.required'))), + componentProps: { + placeholder: $t('common.pleaseInput') + '脚本函数名称', + }, + }, + { + component: 'Textarea', + fieldName: 'functionScript', + label: '脚本函数体', + componentProps: { + rows: 6, + placeholder: '请输入脚本函数体(用于解析MODBUS设备数据)', + }, + }, ]); + +