From e1b2cb106a61bc727c2da7e18b773259e33e4f09 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Fri, 13 Dec 2024 18:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=91IOT:=20=E4=BA=A7=E5=93=81=E7=89=A9=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=EF=BC=8C30%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/ThingModel/ThingModelDataSpecs.vue | 13 +++++-- .../detail/ThingModel/ThingModelForm.vue | 9 ++--- .../product/detail/ThingModel/config.ts | 2 +- .../dataSpecs/ThingModelDataType.vue | 4 +-- .../dataSpecs/ThingModelEnumTypeDataSpecs.vue | 35 +++++++++++++------ .../ThingModelNumberTypeDataSpecs.vue | 14 ++++---- 6 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue b/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue index 33816a80..07005b00 100644 --- a/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue +++ b/src/views/iot/product/product/detail/ThingModel/ThingModelDataSpecs.vue @@ -33,10 +33,19 @@ const props = defineProps<{ modelValue: any }>() const emits = defineEmits(['update:modelValue']) const formData = useVModel(props, 'modelValue', emits) as Ref -/** 属性值的数据类型切换时 */ -const handleChange = () => { +/** 属性值的数据类型切换时初始化相关数据 */ +const handleChange = (dataType: any) => { formData.value.dataSpecsList = [] formData.value.dataSpecs = {} + + switch (dataType) { + case DataSpecsDataType.ENUM: + formData.value.dataSpecsList.push({ + dataType: 'ENUM', + name: '', // 枚举项的名称 + value: undefined // 枚举值 + }) + } } // dataType为INT的dataSpecs示例: // diff --git a/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue b/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue index d551cd4d..bc23dbeb 100644 --- a/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue +++ b/src/views/iot/product/product/detail/ThingModel/ThingModelForm.vue @@ -48,6 +48,7 @@ import { ThinkModelFunctionVO } from '@/api/iot/thinkmodelfunction' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' +import { DataSpecsDataType } from './config' defineOptions({ name: 'IoTProductThingModelForm' }) @@ -68,9 +69,9 @@ const formData = ref({ name: undefined, description: undefined, type: ProductFunctionTypeEnum.PROPERTY, - dataType: undefined, + dataType: DataSpecsDataType.INT, dataSpecsList: [], - dataSpecs: undefined, + dataSpecs: {}, accessMode: undefined }) const formRules = reactive({ @@ -164,9 +165,9 @@ const resetForm = () => { name: undefined, description: undefined, type: ProductFunctionTypeEnum.PROPERTY, - dataType: undefined, + dataType: DataSpecsDataType.INT, dataSpecsList: [], - dataSpecs: undefined, + dataSpecs: {}, accessMode: undefined } formRef.value?.resetFields() diff --git a/src/views/iot/product/product/detail/ThingModel/config.ts b/src/views/iot/product/product/detail/ThingModel/config.ts index fa89b9d3..e75fc082 100644 --- a/src/views/iot/product/product/detail/ThingModel/config.ts +++ b/src/views/iot/product/product/detail/ThingModel/config.ts @@ -21,7 +21,7 @@ export interface DataSpecsEnumDataVO { dataType: 'ENUM' | 'BOOL' defaultValue?: string // 默认值,可选 name: string // 枚举项的名称 - value: number // 枚举值 + value: number | undefined // 枚举值 } /** 属性值的数据类型 */ diff --git a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelDataType.vue b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelDataType.vue index 8c9e950c..cf26e5eb 100644 --- a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelDataType.vue +++ b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelDataType.vue @@ -30,8 +30,8 @@ const dataTypeOptions = [ { value: DataSpecsDataType.STRUCT, label: 'struct (结构体)' }, { value: DataSpecsDataType.ARRAY, label: 'array (数组)' } ] -const handleChange = () => { - emits('change') +const handleChange = (value: any) => { + emits('change', value) } diff --git a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue index db0a58b2..7b977ae6 100644 --- a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue +++ b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelEnumTypeDataSpecs.vue @@ -1,26 +1,41 @@ diff --git a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue index 7de57631..3920a0f5 100644 --- a/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue +++ b/src/views/iot/product/product/detail/ThingModel/dataSpecs/ThingModelNumberTypeDataSpecs.vue @@ -1,17 +1,17 @@