From 9bd96a3d63e9b4f8d372a6f5eaf11ba0e25e76dc Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 25 Dec 2024 17:12:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E3=80=91IOT:=20=E7=A1=AE=E4=BF=9D=20ThingModel=20=E4=B8=AD=20d?= =?UTF-8?q?ataSpecs=20=E5=92=8C=20dataSpecsList=20=E4=B9=8B=E4=B8=AD?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E4=BC=A0=E5=85=A5=E4=B8=94=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/iot/thingmodel/ThingModelDataSpecs.vue | 5 +++-- src/views/iot/thingmodel/ThingModelForm.vue | 8 ++++++++ .../thingmodel/dataSpecs/ThingModelStructDataSpecs.vue | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/views/iot/thingmodel/ThingModelDataSpecs.vue b/src/views/iot/thingmodel/ThingModelDataSpecs.vue index 5bced55c..c0b9771c 100644 --- a/src/views/iot/thingmodel/ThingModelDataSpecs.vue +++ b/src/views/iot/thingmodel/ThingModelDataSpecs.vue @@ -121,8 +121,9 @@ const getDataTypeOptions = computed(() => { const handleChange = (dataType: any) => { property.value.dataSpecsList = [] property.value.dataSpecs = {} - - property.value.dataSpecs.dataType = dataType + // 不是列表型数据才设置 dataSpecs.dataType + ![DataSpecsDataType.ENUM, DataSpecsDataType.BOOL, DataSpecsDataType.STRUCT].includes(dataType) && + (property.value.dataSpecs.dataType = dataType) switch (dataType) { case DataSpecsDataType.ENUM: property.value.dataSpecsList.push({ diff --git a/src/views/iot/thingmodel/ThingModelForm.vue b/src/views/iot/thingmodel/ThingModelForm.vue index 173dab34..f178cdf8 100644 --- a/src/views/iot/thingmodel/ThingModelForm.vue +++ b/src/views/iot/thingmodel/ThingModelForm.vue @@ -46,6 +46,7 @@ import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' import { DataSpecsDataType, ThingModelFormRules } from './config' import { cloneDeep } from 'lodash-es' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' +import { isEmpty } from '@/utils/is' /** IoT 物模型数据表单 */ defineOptions({ name: 'IoTProductThingModelForm' }) @@ -103,6 +104,13 @@ const submitForm = async () => { data.dataType = data.property.dataType data.property.identifier = data.identifier data.property.name = data.name + // 处理 dataSpecs 为空的情况 + if (isEmpty(data.property.dataSpecs)) { + delete data.property.dataSpecs + } + if (isEmpty(data.property.dataSpecsList)) { + delete data.property.dataSpecsList + } if (formType.value === 'create') { await ThingModelApi.createThingModel(data) message.success(t('common.createSuccess')) diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue index 3ac7b296..354469f2 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue @@ -111,7 +111,7 @@ const submitForm = async () => { !!data.property.dataSpecs && Object.keys(data.property.dataSpecs).length > 1 ? data.property.dataSpecs : undefined, - dataSpecsList: data.property.dataSpecsList + dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList } // 查找是否已有相同 identifier 的项