diff --git a/apps/web-antd/src/api-client/schemas.gen.ts b/apps/web-antd/src/api-client/schemas.gen.ts index 0b52c2b..e3ae5bd 100644 --- a/apps/web-antd/src/api-client/schemas.gen.ts +++ b/apps/web-antd/src/api-client/schemas.gen.ts @@ -1312,20 +1312,23 @@ export const CopyIoTPlatformThingModelToDeviceInputSchema = { } as const; export const CopyStandardThingModelInputSchema = { + required: ['filedTypes', 'ioTPlatform', 'ioTPlatformProductId'], type: 'object', properties: { - filedType: { - type: 'string', - description: '物联网平台中对应产品物模型属性或者事件类型 JiShe.ServicePro.Core.DataDictionaryTypeConst', - nullable: true + filedTypes: { + type: 'array', + items: { + type: 'string' + }, + description: '物联网平台中对应产品物模型属性或者事件类型 JiShe.ServicePro.Core.DataDictionaryTypeConst' }, ioTPlatform: { '$ref': '#/components/schemas/IoTPlatformTypeEnum' }, ioTPlatformProductId: { + minLength: 1, type: 'string', - description: '平台产品ID', - nullable: true + description: '平台产品ID' }, dataDictionaries: { type: 'array', @@ -2990,6 +2993,11 @@ export const DeviceThingModelPropertyInfoDtoSchema = { description: '反转获取数量', format: 'int32', nullable: true + }, + filedTypeName: { + type: 'string', + description: '物模型属性或者事件类型名称', + nullable: true } }, additionalProperties: false, @@ -5492,6 +5500,11 @@ export const IoTPlatformThingModelInfoDtoSchema = { type: 'string', description: '物联网平台中对应产品物模型标识符扩展,用于扩展结构体类型', nullable: true + }, + filedTypeName: { + type: 'string', + description: '物模型属性或者事件类型名称', + nullable: true } }, additionalProperties: false, diff --git a/apps/web-antd/src/api-client/services.gen.ts b/apps/web-antd/src/api-client/services.gen.ts index f472a47..6d23fd7 100644 --- a/apps/web-antd/src/api-client/services.gen.ts +++ b/apps/web-antd/src/api-client/services.gen.ts @@ -547,7 +547,7 @@ export const postDeviceThingModelManagementBuildAnalysisScriptAsync = (options?: Options) => { return (options?.client ?? client).post({ diff --git a/apps/web-antd/src/api-client/types.gen.ts b/apps/web-antd/src/api-client/types.gen.ts index 8a2d918..e9d0ef3 100644 --- a/apps/web-antd/src/api-client/types.gen.ts +++ b/apps/web-antd/src/api-client/types.gen.ts @@ -302,12 +302,12 @@ export type CopyStandardThingModelInput = { /** * 物联网平台中对应产品物模型属性或者事件类型 JiShe.ServicePro.Core.DataDictionaryTypeConst */ - filedType?: (string) | null; - ioTPlatform?: IoTPlatformTypeEnum; + filedTypes: Array<(string)>; + ioTPlatform: IoTPlatformTypeEnum; /** * 平台产品ID */ - ioTPlatformProductId?: (string) | null; + ioTPlatformProductId: string; /** * 标准物模型集合 */ @@ -1712,6 +1712,10 @@ export type DeviceThingModelPropertyInfoDto = { * 反转获取数量 */ reversalTakeNumber?: (number) | null; + /** + * 物模型属性或者事件类型名称 + */ + filedTypeName?: (string) | null; }; export type DeviceThingModelPropertyInfoDtoPagedResultDto = { @@ -2782,6 +2786,10 @@ export type IoTPlatformThingModelInfoDto = { * 物联网平台中对应产品物模型标识符扩展,用于扩展结构体类型 */ ioTPlatformRawFieldExtension?: (string) | null; + /** + * 物模型属性或者事件类型名称 + */ + filedTypeName?: (string) | null; }; export type IoTPlatformThingModelInfoDtoPagedResultDto = { diff --git a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/DeviceThingModelPropertyModal.vue b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/DeviceThingModelPropertyModal.vue index a2fd490..027dfb3 100644 --- a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/DeviceThingModelPropertyModal.vue +++ b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/DeviceThingModelPropertyModal.vue @@ -44,7 +44,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ gridOptions: { columns: [ { - field: 'filedType', + field: 'filedTypeName', title: '物模型类型', minWidth: 160, showOverflow: 'tooltip', @@ -223,6 +223,7 @@ const [EditPropertyFormModal, editPropertyFormModalApi] = useVbenModal({ // 快速复制平台端物模型属性弹窗 const [CopyPropertyModal, copyPropertyModalApi] = useVbenModal({ draggable: true, + centered: true, footer: true, showCancelButton: true, showConfirmButton: true, @@ -598,16 +599,16 @@ watch( }, ); -// 快速复制表单(选择平台和产品) +// 快速复制表单(选择平台和产品,纵向单列布局) const [CopyPropertyForm, copyPropertyFormApi] = useVbenForm({ collapsed: false, commonConfig: { labelWidth: 140, componentProps: { - class: 'w-4/5', + class: 'w-full', }, }, - layout: 'horizontal', + layout: 'vertical', schema: [ { component: 'ApiSelect', @@ -690,7 +691,7 @@ const [CopyPropertyForm, copyPropertyFormApi] = useVbenForm({ ], showCollapseButton: false, showDefaultActions: false, - wrapperClass: 'grid-cols-2', + wrapperClass: 'grid-cols-1', }); // 快速复制设备端物模型表单 diff --git a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue index bbc709f..8ff1483 100644 --- a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue +++ b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/index.vue @@ -634,14 +634,14 @@ onMounted(async () => { auth: ['AbpIdentity.Users.Update'], onClick: openPropertyModal.bind(null, row), }, + { + label: '指令管理', + type: 'link', + size: 'small', + auth: ['AbpIdentity.Users.Update'], + onClick: openCommandModal.bind(null, row), + }, ]" :drop-down-actions="[ - { - label: '指令管理', - type: 'link', - size: 'small', - auth: ['AbpIdentity.Users.Update'], - onClick: openCommandModal.bind(null, row), - }, { label: row.functionAnalysisFlag ? '禁用解析' : '启用解析', type: 'input', diff --git a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts index 787c1d5..3e64323 100644 --- a/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts +++ b/apps/web-antd/src/views/thingmodelinfo/deviceThingModelManagement/schema.ts @@ -152,7 +152,7 @@ export const tableSchema = computed(() => [ { field: 'action', title: $t('common.action'), - width: 160, + width: 250, fixed: 'right', slots: { default: 'action' }, }, diff --git a/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/index.vue b/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/index.vue index 3d8c994..daea60b 100644 --- a/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/index.vue +++ b/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/index.vue @@ -23,8 +23,9 @@ import { TableAction } from '#/components/table-action'; import { $t } from '#/locales'; import { - getAddThingModelFormSchema, + copyStandardThingModelFormSchema, copyThingModelFormSchema, + getAddThingModelFormSchema, getEditThingModelFormSchema, querySchema, tableSchema, @@ -44,26 +45,28 @@ const ioTPlatform = ref((route.query.ioTPlatform as string) || '2'); 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, + ioTPlatform: route.query.ioTPlatform + ? String(route.query.ioTPlatform) + : undefined, + ioTPlatformProductId: route.query.productId + ? String(route.query.productId) + : undefined, }, submitOnChange: false, handleValuesChange: async (values, changedFields) => { // 当平台类型变化时,清空产品ID - if (changedFields.includes('ioTPlatform')) { - if (values.ioTPlatform) { - ioTPlatform.value = String(values.ioTPlatform); - // 清空产品ID,因为平台变化了 - if (gridApi?.formApi) { - await gridApi.formApi.setValues({ - ioTPlatformProductId: undefined, - }); - } - productId.value = ''; - productName.value = ''; + if (changedFields.includes('ioTPlatform') && values.ioTPlatform) { + ioTPlatform.value = String(values.ioTPlatform); + // 清空产品ID,因为平台变化了 + if (gridApi?.formApi) { + await gridApi.formApi.setValues({ + ioTPlatformProductId: undefined, + }); } + productId.value = ''; + productName.value = ''; } - + // 当产品ID变化时,更新响应式变量并重新加载数据 if (changedFields.includes('ioTPlatformProductId')) { if (values.ioTPlatformProductId) { @@ -74,7 +77,7 @@ const formOptions: VbenFormProps = { productId.value = ''; productName.value = ''; } - + // 延迟重新加载数据,确保表单值已更新 await nextTick(); setTimeout(async () => { @@ -115,7 +118,7 @@ const gridOptions: VxeGridProps = { : formValues || {}; // 优先使用从表单API获取的值(最新的),如果没有则使用传入的formValues - const finalFormValues = { ...(formValues || {}), ...currentFormValues }; + const finalFormValues = { ...formValues, ...currentFormValues }; const currentPlatform = finalFormValues?.ioTPlatform; const currentProductId = finalFormValues?.ioTPlatformProductId; @@ -135,7 +138,9 @@ const gridOptions: VxeGridProps = { // 添加平台参数(必须) if (currentPlatform) { - queryParams.ioTPlatform = Number.parseInt(String(currentPlatform)) as 1 | 2; + queryParams.ioTPlatform = Number.parseInt( + String(currentPlatform), + ) as 1 | 2; } // 添加产品ID参数(必须) @@ -184,29 +189,31 @@ const [ThingModelModal, thingModelModalApi] = useVbenModal({ await nextTick(); const formApi = editRow.value.id ? editFormApi : addFormApi; const isEdit = !!editRow.value.id; - + // 编辑时从选中对象获取,新增时从搜索表单获取 let platformValue: 1 | 2; let productIdValue: string; - + if (isEdit) { // 编辑时从 editRow.value 获取 platformValue = editRow.value.ioTPlatform - ? (typeof editRow.value.ioTPlatform === 'string' - ? Number.parseInt(editRow.value.ioTPlatform) - : editRow.value.ioTPlatform) as 1 | 2 - : Number.parseInt(ioTPlatform.value) as 1 | 2; + ? ((typeof editRow.value.ioTPlatform === 'string' + ? Number.parseInt(editRow.value.ioTPlatform) + : editRow.value.ioTPlatform) as 1 | 2) + : (Number.parseInt(ioTPlatform.value) as 1 | 2); productIdValue = editRow.value.ioTPlatformProductId || productId.value; } else { // 新增时从搜索表单获取最新的值 - const formValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {}; + const formValues = gridApi?.formApi + ? await gridApi.formApi.getValues() + : {}; platformValue = formValues.ioTPlatform - ? (typeof formValues.ioTPlatform === 'string' - ? Number.parseInt(formValues.ioTPlatform) - : formValues.ioTPlatform) as 1 | 2 - : Number.parseInt(ioTPlatform.value) as 1 | 2; + ? ((typeof formValues.ioTPlatform === 'string' + ? Number.parseInt(formValues.ioTPlatform) + : formValues.ioTPlatform) as 1 | 2) + : (Number.parseInt(ioTPlatform.value) as 1 | 2); productIdValue = formValues.ioTPlatformProductId || productId.value; - + // 同步更新响应式变量 if (formValues.ioTPlatform) { ioTPlatform.value = String(formValues.ioTPlatform); @@ -215,23 +222,25 @@ const [ThingModelModal, thingModelModalApi] = useVbenModal({ productId.value = String(formValues.ioTPlatformProductId); } } - + console.log('设置表单值:', { isEdit, platformValue, productIdValue, editRowValue: isEdit ? editRow.value : null, }); - + await formApi.setValues({ ...(isEdit ? editRow.value : {}), _ioTPlatform: platformValue, _ioTPlatformProductId: productIdValue, }); - + // 手动触发平台物模型编码字段的重新加载 setTimeout(() => { - const fieldRef = formApi.getFieldComponentRef('ioTPlatformRawFieldName'); + const fieldRef = formApi.getFieldComponentRef( + 'ioTPlatformRawFieldName', + ); if (fieldRef && typeof fieldRef.updateParam === 'function') { fieldRef.updateParam({ body: { @@ -262,12 +271,29 @@ const [CopyModal, copyModalApi] = useVbenModal({ }, }); +// 复制标准模型弹窗 +const [CopyStandardModal, copyStandardModalApi] = useVbenModal({ + draggable: true, + footer: true, + showCancelButton: true, + showConfirmButton: true, + onConfirm: submitCopyStandard, + onBeforeClose: () => { + return true; + }, + onCancel: () => { + copyStandardModalApi.close(); + }, +}); + // 创建新增表单 schema(传入获取平台和产品ID的函数,作为后备方案) // 注意:实际使用时,值会从表单的 _ioTPlatform 和 _ioTPlatformProductId 字段获取 const addThingModelFormSchema = getAddThingModelFormSchema( () => { // 作为后备方案,返回响应式变量的值 - return ioTPlatform.value ? Number.parseInt(ioTPlatform.value) as 1 | 2 : undefined; + return ioTPlatform.value + ? (Number.parseInt(ioTPlatform.value) as 1 | 2) + : undefined; }, () => { // 作为后备方案,返回响应式变量的值 @@ -301,7 +327,9 @@ const editThingModelFormSchema = getEditThingModelFormSchema( : editRow.value.ioTPlatform; } // 如果没有,使用响应式变量 - return ioTPlatform.value ? Number.parseInt(ioTPlatform.value) as 1 | 2 : undefined; + return ioTPlatform.value + ? (Number.parseInt(ioTPlatform.value) as 1 | 2) + : undefined; }, () => { // 编辑时优先从 editRow 获取 @@ -340,6 +368,22 @@ const [CopyForm, copyFormApi] = useVbenForm({ wrapperClass: 'grid-cols-2', }); +// 复制标准模型表单(多选物模型类型) +const [CopyStandardForm, copyStandardFormApi] = useVbenForm({ + collapsed: false, + commonConfig: { + labelWidth: 160, + componentProps: { + class: 'w-4/5', + }, + }, + layout: 'horizontal', + schema: copyStandardThingModelFormSchema.value, + showCollapseButton: false, + showDefaultActions: false, + wrapperClass: 'grid-cols-1', +}); + // 监听路由参数变化,自动加载数据 watch( () => [route.query.productId, route.query.ioTPlatform], @@ -353,7 +397,7 @@ watch( if (route.query.productName) { productName.value = route.query.productName as string; } - + // 延迟执行,确保组件完全初始化 if (gridApi) { setTimeout(async () => { @@ -380,7 +424,7 @@ onMounted(async () => { if (route.query.ioTPlatform) { ioTPlatform.value = route.query.ioTPlatform as string; } - + // 延迟加载数据,确保表格已初始化 // 即使没有 productId,也要触发一次查询,让表格显示空白状态 await nextTick(); @@ -425,7 +469,7 @@ async function submit() { const { valid } = await formApi.validate(); if (!valid) return; - const formValues = await formApi.getValues(); + const formValues = await formApi.getValues(); const fetchParams: any = { ...formValues, // 自动添加平台和产品信息 @@ -451,9 +495,6 @@ async function submit() { } } catch (error) { console.error('提交失败:', error); - Message.error( - editRow.value.id ? $t('common.editFail') : $t('common.addFail'), - ); } } @@ -461,12 +502,12 @@ async function onEdit(record: any) { editRow.value = record; // 编辑时从选中对象获取平台和产品ID const platformValue = record.ioTPlatform - ? (typeof record.ioTPlatform === 'string' - ? Number.parseInt(record.ioTPlatform) - : record.ioTPlatform) as 1 | 2 - : Number.parseInt(ioTPlatform.value) as 1 | 2; + ? ((typeof record.ioTPlatform === 'string' + ? Number.parseInt(record.ioTPlatform) + : record.ioTPlatform) as 1 | 2) + : (Number.parseInt(ioTPlatform.value) as 1 | 2); const productIdValue = record.ioTPlatformProductId || productId.value; - + thingModelModalApi.open(); await nextTick(); setTimeout(async () => { @@ -475,9 +516,11 @@ async function onEdit(record: any) { _ioTPlatform: platformValue, _ioTPlatformProductId: productIdValue, }); - + // 手动触发平台物模型编码字段的重新加载 - const fieldRef = editFormApi.getFieldComponentRef('ioTPlatformRawFieldName'); + const fieldRef = editFormApi.getFieldComponentRef( + 'ioTPlatformRawFieldName', + ); if (fieldRef && typeof fieldRef.updateParam === 'function') { fieldRef.updateParam({ body: { @@ -494,12 +537,12 @@ const openAddModal = async () => { // 打开新增弹窗时,从搜索表单中获取平台和产品ID(确保是最新的值) const formValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {}; const platformValue = formValues.ioTPlatform - ? (typeof formValues.ioTPlatform === 'string' - ? Number.parseInt(formValues.ioTPlatform) - : formValues.ioTPlatform) as 1 | 2 - : Number.parseInt(ioTPlatform.value) as 1 | 2; + ? ((typeof formValues.ioTPlatform === 'string' + ? Number.parseInt(formValues.ioTPlatform) + : formValues.ioTPlatform) as 1 | 2) + : (Number.parseInt(ioTPlatform.value) as 1 | 2); const productIdValue = formValues.ioTPlatformProductId || productId.value; - + // 更新响应式变量(保持同步) if (formValues.ioTPlatform) { ioTPlatform.value = String(formValues.ioTPlatform); @@ -507,7 +550,7 @@ const openAddModal = async () => { if (formValues.ioTPlatformProductId) { productId.value = String(formValues.ioTPlatformProductId); } - + thingModelModalApi.open(); // 确保值已设置 await nextTick(); @@ -516,7 +559,7 @@ const openAddModal = async () => { _ioTPlatform: platformValue, _ioTPlatformProductId: productIdValue, }); - + // 手动触发平台物模型编码字段的重新加载 const fieldRef = addFormApi.getFieldComponentRef('ioTPlatformRawFieldName'); if (fieldRef && typeof fieldRef.updateParam === 'function') { @@ -580,7 +623,59 @@ async function submitCopy() { } } catch (error) { console.error('复制模型失败:', error); - Message.error('复制模型失败'); + } +} + +// 打开复制标准模型模态框(逻辑与“复制已有模型”保持一致) +const openCopyStandardThingModelModal = () => { + console.log('打开复制标准模型模态框,当前参数:', { + productId: productId.value, + productName: productName.value, + ioTPlatform: ioTPlatform.value, + }); + copyStandardModalApi.open(); +}; + +// 复制标准模型提交逻辑(带物模型类型多选) +async function submitCopyStandard() { + // 检查是否有产品ID + if (!productId.value) { + Message.error('产品ID不存在,无法复制标准模型'); + return; + } + + const { valid } = await copyStandardFormApi.validate(); + if (!valid) return; + + const formValues = await copyStandardFormApi.getValues(); + + console.log('复制标准模型提交参数:', { + formValues, + params: { + productId: productId.value, + productName: productName.value, + ioTPlatform: ioTPlatform.value, + }, + }); + + try { + const resp = await postIoTplatformThingModelInfoCopyStandardThingModel({ + body: { + ioTPlatform: Number.parseInt(ioTPlatform.value) as 1 | 2, + ioTPlatformProductId: productId.value, + // 按物模型类型多选复制(使用字段 filedTypes,值为字典 key 列表) + filedTypes: formValues.filedTypes, + }, + }); + if (resp.data) { + Message.success('复制标准模型成功'); + copyStandardModalApi.close(); + gridApi.reload(); + } else { + Message.error('复制标准模型失败'); + } + } catch (error) { + console.error('复制标准模型失败:', error); } } @@ -598,36 +693,10 @@ async function onDel(record: any) { } } catch (error) { console.error('删除失败:', error); - Message.error($t('common.deleteFail')); } } -// 复制标准模型函数 -async function copyStandardThingModel() { - // 检查是否有产品ID - if (!productId.value) { - Message.error('产品ID不存在,无法复制标准模型'); - return; - } - - try { - const resp = await postIoTplatformThingModelInfoCopyStandardThingModel({ - body: { - ioTPlatform: Number.parseInt(ioTPlatform.value) as 1 | 2, - ioTPlatformProductId: productId.value, - }, - }); - if (resp.data) { - Message.success('复制标准模型成功'); - gridApi.reload(); - } else { - Message.error('复制标准模型失败'); - } - } catch (error) { - console.error('复制标准模型失败:', error); - Message.error('复制标准模型失败'); - } -} +// 旧的“复制标准模型”直调接口函数已不再使用,保留逻辑由新的弹窗 + submitCopyStandard 代替 diff --git a/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/schema.ts b/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/schema.ts index b324bfb..db00c58 100644 --- a/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/schema.ts +++ b/apps/web-antd/src/views/thingmodelinfo/ioTPlatformThingModelInfo/schema.ts @@ -105,7 +105,7 @@ export const querySchema = computed(() => [ export const tableSchema = computed(() => [ { - field: 'filedType', + field: 'filedTypeName', title: $t('abp.thingModelInfos.FiledType'), minWidth: 120, showOverflow: 'tooltip', @@ -180,601 +180,617 @@ export const tableSchema = computed(() => [ ]); // 添加物模型表单schema -export const getAddThingModelFormSchema = (getPlatform: () => number | string | undefined, getProductId: () => string | undefined) => 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, - allowClear: 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: '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: '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: 'ioTPlatformRawFieldName', - label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - dependencies: { - triggerFields: ['_ioTPlatform', '_ioTPlatformProductId'], - componentProps: (formValues: any) => { - // 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的) - let platform = formValues?._ioTPlatform; - let productId = formValues?._ioTPlatformProductId; - - // 如果表单值中没有,尝试从其他字段获取 - if (!platform && formValues?.ioTPlatform) { - platform = typeof formValues.ioTPlatform === 'string' - ? Number.parseInt(formValues.ioTPlatform) - : formValues.ioTPlatform; - } - if (!productId && formValues?.ioTPlatformProductId) { - productId = formValues.ioTPlatformProductId; - } - - // 如果还是没有,尝试从外部函数获取(作为后备方案) - if (!platform) { - const externalPlatform = getPlatform(); - if (externalPlatform) { - platform = typeof externalPlatform === 'string' - ? Number.parseInt(externalPlatform) - : externalPlatform; - } - } - if (!productId) { - const externalProductId = getProductId(); - if (externalProductId) { - productId = String(externalProductId); - } - } - - // 确保平台类型是数字 - if (platform && typeof platform === 'string') { - platform = Number.parseInt(platform); - } - - // 调试信息 - console.log('平台物模型编码下拉框配置:', { - platform, - productId, - hasApi: !!(platform && productId), - fromForm: { - _ioTPlatform: formValues?._ioTPlatform, - _ioTPlatformProductId: formValues?._ioTPlatformProductId, - ioTPlatform: formValues?.ioTPlatform, - ioTPlatformProductId: formValues?.ioTPlatformProductId, +export const getAddThingModelFormSchema = ( + getPlatform: () => number | string | undefined, + getProductId: () => string | undefined, +) => + 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, + allowClear: 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: '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: '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: 'ioTPlatformRawFieldName', + label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), + rules: z.preprocess( + (v) => (v == null ? '' : v), + z.string().min(1, $t('common.required')), + ), + dependencies: { + triggerFields: ['_ioTPlatform', '_ioTPlatformProductId'], + componentProps: (formValues: any) => { + // 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的) + let platform = formValues?._ioTPlatform; + let productId = formValues?._ioTPlatformProductId; - return { - api: - platform && productId - ? postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync - : null, - params: - platform && productId - ? { - body: { - ioTPlatformType: - typeof platform === 'string' - ? Number.parseInt(platform) - : platform, - ioTPlatformProductId: String(productId), - }, - } - : {}, - labelField: 'value', - valueField: 'key', - optionsPropName: 'options', - immediate: !!(platform && productId), // 当有平台和产品ID时立即加载 - allowClear: true, - placeholder: - $t('common.pleaseSelect') + - $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - 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; + // 如果表单值中没有,尝试从其他字段获取 + if (!platform && formValues?.ioTPlatform) { + platform = + typeof formValues.ioTPlatform === 'string' + ? Number.parseInt(formValues.ioTPlatform) + : formValues.ioTPlatform; + } + if (!productId && formValues?.ioTPlatformProductId) { + productId = formValues.ioTPlatformProductId; + } + + // 如果还是没有,尝试从外部函数获取(作为后备方案) + if (!platform) { + const externalPlatform = getPlatform(); + if (externalPlatform) { + platform = + typeof externalPlatform === 'string' + ? Number.parseInt(externalPlatform) + : externalPlatform; } - // 存储原始数据映射,用于后续查找 secondValue - const optionMap = new Map(); - items.forEach((item: any) => { - if (item.key) { - optionMap.set(item.key, item.secondValue); + } + if (!productId) { + const externalProductId = getProductId(); + if (externalProductId) { + productId = String(externalProductId); + } + } + + // 确保平台类型是数字 + if (platform && typeof platform === 'string') { + platform = Number.parseInt(platform); + } + + // 调试信息 + console.log('平台物模型编码下拉框配置:', { + platform, + productId, + hasApi: !!(platform && productId), + fromForm: { + _ioTPlatform: formValues?._ioTPlatform, + _ioTPlatformProductId: formValues?._ioTPlatformProductId, + ioTPlatform: formValues?.ioTPlatform, + ioTPlatformProductId: formValues?.ioTPlatformProductId, + }, + }); + + return { + api: + platform && productId + ? postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync + : null, + params: + platform && productId + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + ioTPlatformProductId: String(productId), + }, + } + : {}, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: !!(platform && productId), // 当有平台和产品ID时立即加载 + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.thingModelInfos.IoTPlatformRawFieldName'), + 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; } - }); - (formValues as any)._platformPropertyMap = optionMap; - return items; - }, - onChange: (value: string) => { - // 选择后自动设置平台物模型数值类型为选中项的 secondValue - const optionMap = (formValues as any)._platformPropertyMap; - if (optionMap && value) { - let secondValue = optionMap.get(value); - if (secondValue) { - // 兼容 BOOL / BOOLEAN 差异,统一转换为后端 / 枚举使用的 BOOLEAN - if ( - typeof secondValue === 'string' && - secondValue.toUpperCase() === 'BOOL' - ) { - secondValue = 'BOOLEAN'; - } - formValues.ioTPlatformRawFieldDataType = secondValue; - } - } - }, - }; - }, - }, - }, - { - component: 'Switch', - fieldName: 'isValueNeedConvert', - label: $t('abp.thingModelInfos.IsValueNeedConvert'), - defaultValue: false, - componentProps: { - style: { width: 'auto' }, - }, - }, - { - component: 'ApiSelect', - fieldName: 'ioTPlatformRawFieldDataType', - label: '平台物模型值类型', - componentProps: { - api: getCommonGetSelectList, - params: { - query: { - typeName: 'StandardThingModelDataTypeEnum', + // 存储原始数据映射,用于后续查找 secondValue + const optionMap = new Map(); + items.forEach((item: any) => { + if (item.key) { + optionMap.set(item.key, item.secondValue); + } + }); + (formValues as any)._platformPropertyMap = optionMap; + return items; + }, + onChange: (value: string) => { + // 选择后自动设置平台物模型数值类型为选中项的 secondValue + const optionMap = (formValues as any)._platformPropertyMap; + if (optionMap && value) { + let secondValue = optionMap.get(value); + if (secondValue) { + // 兼容 BOOL / BOOLEAN 差异,统一转换为后端 / 枚举使用的 BOOLEAN + if ( + typeof secondValue === 'string' && + secondValue.toUpperCase() === 'BOOL' + ) { + secondValue = 'BOOLEAN'; + } + formValues.ioTPlatformRawFieldDataType = secondValue; + } + } + }, + }; }, }, - labelField: 'value', - valueField: 'secondValue', - 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 []; + }, + { + component: 'Switch', + fieldName: 'isValueNeedConvert', + label: $t('abp.thingModelInfos.IsValueNeedConvert'), + defaultValue: false, + componentProps: { + style: { width: 'auto' }, }, }, - }, - { - component: 'Switch', - fieldName: 'isSpecialIdentifier', - label: '是否特殊物模型标识符', - defaultValue: false, - componentProps: { - style: { width: 'auto' }, + { + component: 'ApiSelect', + fieldName: 'ioTPlatformRawFieldDataType', + label: '平台物模型值类型', + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + typeName: 'StandardThingModelDataTypeEnum', + }, + }, + labelField: 'value', + valueField: 'secondValue', + 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 []; + }, + }, }, - }, - { - component: 'Textarea', - fieldName: 'ioTPlatformRawFieldExtension', - label: '平台物模型值类型扩展', - componentProps: { - rows: 4, - placeholder: '请输入平台原始字段扩展信息(用于扩展结构体类型,JSON格式)', + { + component: 'Switch', + fieldName: 'isSpecialIdentifier', + label: '是否特殊物模型标识符', + defaultValue: false, + componentProps: { + style: { width: 'auto' }, + }, }, - }, -]); + { + component: 'Textarea', + fieldName: 'ioTPlatformRawFieldExtension', + label: '平台物模型值类型扩展', + componentProps: { + rows: 4, + placeholder: + '请输入平台原始字段扩展信息(用于扩展结构体类型,JSON格式)', + }, + }, + ]); // 编辑物模型表单schema -export const getEditThingModelFormSchema = (getPlatform: () => number | string | undefined, getProductId: () => string | undefined) => 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: '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: '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: 'ioTPlatformRawFieldName', - label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - rules: z.preprocess( - (v) => (v == null ? '' : v), - z.string().min(1, $t('common.required')), - ), - dependencies: { - triggerFields: ['_ioTPlatform', '_ioTPlatformProductId'], - componentProps: (formValues: any) => { - // 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的) - let platform = formValues?._ioTPlatform; - let productId = formValues?._ioTPlatformProductId; - - // 如果表单值中没有,尝试从其他字段获取 - if (!platform && formValues?.ioTPlatform) { - platform = typeof formValues.ioTPlatform === 'string' - ? Number.parseInt(formValues.ioTPlatform) - : formValues.ioTPlatform; - } - if (!productId && formValues?.ioTPlatformProductId) { - productId = formValues.ioTPlatformProductId; - } - - // 如果还是没有,尝试从外部函数获取(作为后备方案) - if (!platform) { - const externalPlatform = getPlatform(); - if (externalPlatform) { - platform = typeof externalPlatform === 'string' - ? Number.parseInt(externalPlatform) - : externalPlatform; - } - } - if (!productId) { - const externalProductId = getProductId(); - if (externalProductId) { - productId = String(externalProductId); - } - } - - // 确保平台类型是数字 - if (platform && typeof platform === 'string') { - platform = Number.parseInt(platform); - } - - // 调试信息 - console.log('平台物模型编码下拉框配置:', { - platform, - productId, - hasApi: !!(platform && productId), - fromForm: { - _ioTPlatform: formValues?._ioTPlatform, - _ioTPlatformProductId: formValues?._ioTPlatformProductId, - ioTPlatform: formValues?.ioTPlatform, - ioTPlatformProductId: formValues?.ioTPlatformProductId, +export const getEditThingModelFormSchema = ( + getPlatform: () => number | string | undefined, + getProductId: () => string | undefined, +) => + 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: '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: '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: 'ioTPlatformRawFieldName', + label: $t('abp.thingModelInfos.IoTPlatformRawFieldName'), + rules: z.preprocess( + (v) => (v == null ? '' : v), + z.string().min(1, $t('common.required')), + ), + dependencies: { + triggerFields: ['_ioTPlatform', '_ioTPlatformProductId'], + componentProps: (formValues: any) => { + // 优先从表单值获取(这是最可靠的方式,因为值是在打开弹窗时设置的) + let platform = formValues?._ioTPlatform; + let productId = formValues?._ioTPlatformProductId; - return { - api: - platform && productId - ? postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync - : null, - params: - platform && productId - ? { - body: { - ioTPlatformType: - typeof platform === 'string' - ? Number.parseInt(platform) - : platform, - ioTPlatformProductId: String(productId), - }, - } - : {}, - labelField: 'value', - valueField: 'key', - optionsPropName: 'options', - immediate: !!(platform && productId), // 当有平台和产品ID时立即加载 - allowClear: true, - placeholder: - $t('common.pleaseSelect') + - $t('abp.thingModelInfos.IoTPlatformRawFieldName'), - 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; + // 如果表单值中没有,尝试从其他字段获取 + if (!platform && formValues?.ioTPlatform) { + platform = + typeof formValues.ioTPlatform === 'string' + ? Number.parseInt(formValues.ioTPlatform) + : formValues.ioTPlatform; + } + if (!productId && formValues?.ioTPlatformProductId) { + productId = formValues.ioTPlatformProductId; + } + + // 如果还是没有,尝试从外部函数获取(作为后备方案) + if (!platform) { + const externalPlatform = getPlatform(); + if (externalPlatform) { + platform = + typeof externalPlatform === 'string' + ? Number.parseInt(externalPlatform) + : externalPlatform; } - // 存储原始数据映射,用于后续查找 secondValue - const optionMap = new Map(); - items.forEach((item: any) => { - if (item.key) { - optionMap.set(item.key, item.secondValue); + } + if (!productId) { + const externalProductId = getProductId(); + if (externalProductId) { + productId = String(externalProductId); + } + } + + // 确保平台类型是数字 + if (platform && typeof platform === 'string') { + platform = Number.parseInt(platform); + } + + // 调试信息 + console.log('平台物模型编码下拉框配置:', { + platform, + productId, + hasApi: !!(platform && productId), + fromForm: { + _ioTPlatform: formValues?._ioTPlatform, + _ioTPlatformProductId: formValues?._ioTPlatformProductId, + ioTPlatform: formValues?.ioTPlatform, + ioTPlatformProductId: formValues?.ioTPlatformProductId, + }, + }); + + return { + api: + platform && productId + ? postAggregationIoTplatformGetIoTplatformProductPropertyInfoAsync + : null, + params: + platform && productId + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + ioTPlatformProductId: String(productId), + }, + } + : {}, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: !!(platform && productId), // 当有平台和产品ID时立即加载 + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.thingModelInfos.IoTPlatformRawFieldName'), + 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; } - }); - (formValues as any)._platformPropertyMap = optionMap; - return items; - }, - onChange: (value: string) => { - // 选择后自动设置平台物模型数值类型为选中项的 secondValue - const optionMap = (formValues as any)._platformPropertyMap; - if (optionMap && value) { - let secondValue = optionMap.get(value); - if (secondValue) { - // 兼容 BOOL / BOOLEAN 差异,统一转换为后端 / 枚举使用的 BOOLEAN - if ( - typeof secondValue === 'string' && - secondValue.toUpperCase() === 'BOOL' - ) { - secondValue = 'BOOLEAN'; - } - formValues.ioTPlatformRawFieldDataType = secondValue; - } - } - }, - }; - }, - }, - }, - { - component: 'Switch', - fieldName: 'isValueNeedConvert', - label: $t('abp.thingModelInfos.IsValueNeedConvert'), - componentProps: { - style: { width: 'auto' }, - }, - }, - { - component: 'ApiSelect', - fieldName: 'ioTPlatformRawFieldDataType', - label: '平台物模型值类型', - componentProps: { - api: getCommonGetSelectList, - params: { - query: { - typeName: 'StandardThingModelDataTypeEnum', + // 存储原始数据映射,用于后续查找 secondValue + const optionMap = new Map(); + items.forEach((item: any) => { + if (item.key) { + optionMap.set(item.key, item.secondValue); + } + }); + (formValues as any)._platformPropertyMap = optionMap; + return items; + }, + onChange: (value: string) => { + // 选择后自动设置平台物模型数值类型为选中项的 secondValue + const optionMap = (formValues as any)._platformPropertyMap; + if (optionMap && value) { + let secondValue = optionMap.get(value); + if (secondValue) { + // 兼容 BOOL / BOOLEAN 差异,统一转换为后端 / 枚举使用的 BOOLEAN + if ( + typeof secondValue === 'string' && + secondValue.toUpperCase() === 'BOOL' + ) { + secondValue = 'BOOLEAN'; + } + formValues.ioTPlatformRawFieldDataType = secondValue; + } + } + }, + }; }, }, - labelField: 'value', - valueField: 'secondValue', - 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 []; + }, + { + component: 'Switch', + fieldName: 'isValueNeedConvert', + label: $t('abp.thingModelInfos.IsValueNeedConvert'), + componentProps: { + style: { width: 'auto' }, }, }, - }, - { - component: 'Switch', - fieldName: 'isSpecialIdentifier', - label: '是否特殊物模型标识符', - componentProps: { - style: { width: 'auto' }, + { + component: 'ApiSelect', + fieldName: 'ioTPlatformRawFieldDataType', + label: '平台物模型值类型', + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + typeName: 'StandardThingModelDataTypeEnum', + }, + }, + labelField: 'value', + valueField: 'secondValue', + 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 []; + }, + }, }, - }, - { - component: 'Textarea', - fieldName: 'ioTPlatformRawFieldExtension', - label: '平台物模型值类型扩展', - componentProps: { - rows: 4, - placeholder: '请输入平台原始字段扩展信息(用于扩展结构体类型,JSON格式)', + { + component: 'Switch', + fieldName: 'isSpecialIdentifier', + label: '是否特殊物模型标识符', + componentProps: { + style: { width: 'auto' }, + }, }, - }, -]); + { + component: 'Textarea', + fieldName: 'ioTPlatformRawFieldExtension', + label: '平台物模型值类型扩展', + componentProps: { + rows: 4, + placeholder: + '请输入平台原始字段扩展信息(用于扩展结构体类型,JSON格式)', + }, + }, + ]); // 复制已有模型表单schema export const copyThingModelFormSchema = computed(() => [ @@ -819,3 +835,46 @@ export const copyThingModelFormSchema = computed(() => [ }, }, ]); + +// 复制标准模型(按物模型类型多选)表单 schema +export const copyStandardThingModelFormSchema = computed(() => [ + { + component: 'ApiSelect', + fieldName: 'filedTypes', + label: '选择要复制的物模型类型', + rules: z.preprocess( + (v) => (v == null ? [] : v), + z.array(z.string()).min(1, '请至少选择一个物模型类型'), + ), + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + // 与物模型字段类型相同的数据字典(Property / Service / Event) + typeName: 'DataDictionaryTypeConst', + }, + }, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: true, + allowClear: true, + mode: 'multiple', + placeholder: '请选择要复制的物模型类型(可多选)', + maxTagCount: 'responsive', + 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 []; + }, + }, + }, +]);