From 9bd96a3d63e9b4f8d372a6f5eaf11ba0e25e76dc Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 25 Dec 2024 17:12:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E3=80=91IOT:=20=E7=A1=AE=E4=BF=9D=20ThingModel=20?= =?UTF-8?q?=E4=B8=AD=20dataSpecs=20=E5=92=8C=20dataSpecsList=20=E4=B9=8B?= =?UTF-8?q?=E4=B8=AD=E5=BF=85=E9=A1=BB=E4=BC=A0=E5=85=A5=E4=B8=94=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=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 的项 From d7c33b454f5df8fca194461692d7c0c55b6b41e2 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 25 Dec 2024 18:35:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E3=80=91IOT:=20ThingModel=20=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=92=8C=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/thingmodel/index.ts | 64 ++- src/utils/dict.ts | 2 +- src/views/iot/thingmodel/ThingModelEvent.vue | 39 ++ src/views/iot/thingmodel/ThingModelForm.vue | 57 +- ...elDataSpecs.vue => ThingModelProperty.vue} | 13 +- .../iot/thingmodel/ThingModelService.vue | 36 ++ .../dataSpecs/ThingModelNumberDataSpecs.vue | 8 +- .../dataSpecs/ThingModelStructDataSpecs.vue | 4 +- src/views/iot/utils/constants.ts | 531 ------------------ 9 files changed, 186 insertions(+), 568 deletions(-) create mode 100644 src/views/iot/thingmodel/ThingModelEvent.vue rename src/views/iot/thingmodel/{ThingModelDataSpecs.vue => ThingModelProperty.vue} (92%) create mode 100644 src/views/iot/thingmodel/ThingModelService.vue diff --git a/src/api/iot/thingmodel/index.ts b/src/api/iot/thingmodel/index.ts index 8e2b69ad..3c21ee80 100644 --- a/src/api/iot/thingmodel/index.ts +++ b/src/api/iot/thingmodel/index.ts @@ -11,7 +11,7 @@ export interface ThingModelData { productId?: number // 产品编号 productKey?: string // 产品标识 dataType: string // 数据类型,与 dataSpecs 的 dataType 保持一致 - type: ProductFunctionTypeEnum // 功能类型 + type: number // 功能类型 property: ThingModelProperty // 属性 event?: ThingModelEvent // 事件 service?: ThingModelService // 服务 @@ -38,18 +38,58 @@ export interface ThingModelService { [key: string]: any } -// IOT 产品功能(物模型)类型枚举类 -export enum ProductFunctionTypeEnum { - PROPERTY = 1, // 属性 - SERVICE = 2, // 服务 - EVENT = 3 // 事件 -} +// IOT 产品物模型类型枚举类 +export const ThingModelType = { + PROPERTY: 1, // 属性 + SERVICE: 2, // 服务 + EVENT: 3 // 事件 +} as const -// IOT 产品功能(物模型)访问模式枚举类 -export enum ProductFunctionAccessModeEnum { - READ_WRITE = 'rw', // 读写 - READ_ONLY = 'r' // 只读 -} +// IOT 产品物模型访问模式枚举类 +export const ThingModelAccessMode = { + READ_WRITE: { + label: '读写', + value: 'rw' + }, + READ_ONLY: { + label: '只读', + value: 'r' + } +} as const + +// IOT 产品物模型服务调用方式枚举 +export const ThingModelServiceCallType = { + ASYNC: { + label: '异步调用', + value: 'async' + }, + SYNC: { + label: '同步调用', + value: 'sync' + } +} as const + +// IOT 产品物模型事件类型枚举 +export const ThingModelServiceEventType = { + INFO: { + label: '信息', + value: 'info' + }, + ALERT: { + label: '告警', + value: 'alert' + }, + ERROR: { + label: '故障', + value: 'error' + } +} as const + +// IOT 产品物模型参数是输入参数还是输出参数 +export const ThingModelParamDirection = { + INPUT: 'input', // 输入参数 + OUTPUT: 'output' // 输出参数 +} as const // IoT 产品物模型 API export const ThingModelApi = { diff --git a/src/utils/dict.ts b/src/utils/dict.ts index eae50a27..c1823631 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -238,7 +238,7 @@ export enum DICT_TYPE { IOT_DEVICE_STATUS = 'iot_device_status', // IOT 设备状态 IOT_PRODUCT_THING_MODEL_TYPE = 'iot_product_thing_model_type', // IOT 产品功能类型 IOT_DATA_TYPE = 'iot_data_type', // IOT 数据类型 - IOT_UNIT_TYPE = 'iot_unit_type', // IOT 单位类型 + IOT_PRODUCT_THING_MODEL_UNIT = 'iot_product_thing_model_unit', // IOT 物模型单位 IOT_RW_TYPE = 'iot_rw_type', // IOT 读写类型 IOT_PLUGIN_DEPLOY_TYPE = 'iot_plugin_deploy_type', // IOT 插件部署类型 IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态 diff --git a/src/views/iot/thingmodel/ThingModelEvent.vue b/src/views/iot/thingmodel/ThingModelEvent.vue new file mode 100644 index 00000000..7a49b2e7 --- /dev/null +++ b/src/views/iot/thingmodel/ThingModelEvent.vue @@ -0,0 +1,39 @@ + + + + + diff --git a/src/views/iot/thingmodel/ThingModelForm.vue b/src/views/iot/thingmodel/ThingModelForm.vue index f178cdf8..c821f540 100644 --- a/src/views/iot/thingmodel/ThingModelForm.vue +++ b/src/views/iot/thingmodel/ThingModelForm.vue @@ -25,10 +25,17 @@ - + + + +