From 4f1c79ba6ddca43f2aaa32573e8bac7064cca11d Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 20 Feb 2025 16:30:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=91IoT:=20=E7=89=A9=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.ts | 6 +- .../device/detail/DeviceDetailsSimulator.vue | 82 ++----------------- src/views/iot/thingmodel/ThingModelEvent.vue | 11 ++- .../iot/thingmodel/ThingModelProperty.vue | 16 +++- .../iot/thingmodel/ThingModelService.vue | 9 +- .../thingmodel/components/DataDefinition.vue | 61 ++++++++++++++ src/views/iot/thingmodel/components/index.ts | 3 + src/views/iot/thingmodel/config.ts | 25 +++--- .../dataSpecs/ThingModelArrayDataSpecs.vue | 4 +- .../dataSpecs/ThingModelStructDataSpecs.vue | 3 + src/views/iot/thingmodel/index.vue | 63 +------------- 11 files changed, 128 insertions(+), 155 deletions(-) create mode 100644 src/views/iot/thingmodel/components/DataDefinition.vue create mode 100644 src/views/iot/thingmodel/components/index.ts diff --git a/src/utils/index.ts b/src/utils/index.ts index 059571e7..74c6548d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,4 @@ -import { toNumber } from 'lodash-es' +import {toNumber} from 'lodash-es' /** * @@ -118,7 +118,7 @@ export function toAnyString() { /** * 生成指定长度的随机字符串 - * + * * @param length 字符串长度 */ export function generateRandomStr(length: number): string { @@ -459,7 +459,7 @@ export function jsonParse(str: string) { try { return JSON.parse(str) } catch (e) { - console.error(`str[${str}] 不是一个 JSON 字符串`) + // console.error(`str[${str}] 不是一个 JSON 字符串`) return '' } } diff --git a/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue b/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue index ecf704af..0ce918aa 100644 --- a/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue +++ b/src/views/iot/device/device/detail/DeviceDetailsSimulator.vue @@ -7,7 +7,7 @@ - + @@ -29,70 +29,11 @@ - + @@ -100,7 +41,7 @@
- 发送 + 发送
@@ -151,7 +92,7 @@ - + @@ -201,18 +142,13 @@ - diff --git a/src/views/iot/thingmodel/components/index.ts b/src/views/iot/thingmodel/components/index.ts new file mode 100644 index 00000000..66c692ba --- /dev/null +++ b/src/views/iot/thingmodel/components/index.ts @@ -0,0 +1,3 @@ +import DataDefinition from './DataDefinition.vue' + +export { DataDefinition } diff --git a/src/views/iot/thingmodel/config.ts b/src/views/iot/thingmodel/config.ts index 3343020b..5d075def 100644 --- a/src/views/iot/thingmodel/config.ts +++ b/src/views/iot/thingmodel/config.ts @@ -1,4 +1,4 @@ -import { isEmpty } from '@/utils/is' +import {isEmpty} from '@/utils/is' /** dataSpecs 数值型数据结构 */ export interface DataSpecsNumberDataVO { @@ -21,7 +21,7 @@ export interface DataSpecsEnumOrBoolDataVO { } /** 属性值的数据类型 */ -// TODO @puhui999:这个枚举类,要不放到 dict 里? +// TODO @puhui999:这个枚举类,要不放到 dict 里? 这个全是当常量来使用的不好放 dict 里 🤣 export const DataSpecsDataType = { INT: 'int', FLOAT: 'float', @@ -37,15 +37,15 @@ export const DataSpecsDataType = { /** 物体模型数据类型配置项 */ // TODO @puhui999:搞到字典里;label 只使用()部分,就是整数型、单精度浮点型等,这种哈。这样,拼接 value(label) 就可以渲染出来,通用性更强 export const dataTypeOptions = [ - { value: DataSpecsDataType.INT, label: 'int32 (整数型)' }, - { value: DataSpecsDataType.FLOAT, label: 'float (单精度浮点型)' }, - { value: DataSpecsDataType.DOUBLE, label: 'double (双精度浮点型)' }, - { value: DataSpecsDataType.ENUM, label: 'enum(枚举型)' }, - { value: DataSpecsDataType.BOOL, label: 'bool (布尔型)' }, - { value: DataSpecsDataType.TEXT, label: 'text (文本型)' }, - { value: DataSpecsDataType.DATE, label: 'date (时间型)' }, - { value: DataSpecsDataType.STRUCT, label: 'struct (结构体)' }, - { value: DataSpecsDataType.ARRAY, label: 'array (数组)' } + { value: DataSpecsDataType.INT, label: '整数型' }, + { value: DataSpecsDataType.FLOAT, label: '单精度浮点型' }, + { value: DataSpecsDataType.DOUBLE, label: '双精度浮点型' }, + { value: DataSpecsDataType.ENUM, label: '枚举型' }, + { value: DataSpecsDataType.BOOL, label: '布尔型' }, + { value: DataSpecsDataType.TEXT, label: '文本型' }, + { value: DataSpecsDataType.DATE, label: '时间型' }, + { value: DataSpecsDataType.STRUCT, label: '结构体' }, + { value: DataSpecsDataType.ARRAY, label: '数组' } ] /** 获得物体模型数据类型配置项名称 */ @@ -53,7 +53,8 @@ export const getDataTypeOptionsLabel = (value: string) => { if (isEmpty(value)) { return value } - return dataTypeOptions.find((option) => option.value === value)?.label + const dataType = dataTypeOptions.find((option) => option.value === value) + return dataType && `${dataType.value}(${dataType.label})` } // IOT 产品物模型类型枚举类 diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue index faeb3d44..04a975a1 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelArrayDataSpecs.vue @@ -4,15 +4,15 @@ diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue index eeff830a..6088743a 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue @@ -118,6 +118,9 @@ const submitForm = async () => { } // 查找是否已有相同 identifier 的项 + if (isEmpty(dataSpecsList.value)) { + dataSpecsList.value = [] + } const existingIndex = dataSpecsList.value.findIndex( (spec) => spec.identifier === data.identifier ) diff --git a/src/views/iot/thingmodel/index.vue b/src/views/iot/thingmodel/index.vue index 431851af..9ddd449a 100644 --- a/src/views/iot/thingmodel/index.vue +++ b/src/views/iot/thingmodel/index.vue @@ -64,59 +64,7 @@ @@ -158,13 +106,8 @@ import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import ThingModelForm from './ThingModelForm.vue' import { ProductVO } from '@/api/iot/product/product' import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants' -import { - DataSpecsDataType, - getCallTypeByValue, - getDataTypeOptionsLabel, - getEventTypeByValue, - ThingModelType -} from './config' +import { getDataTypeOptionsLabel } from './config' +import { DataDefinition } from './components' defineOptions({ name: 'IoTThingModel' }) -- Gitee From 0afa0bb1651676fcdf3ca52a4e52a5384fa4b25d Mon Sep 17 00:00:00 2001 From: puhui999 Date: Thu, 20 Feb 2025 16:57:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E7=BC=BA=E9=99=B7=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E3=80=91IoT:=20=E7=89=A9=E6=A8=A1=E5=9E=8B=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=B7=B2=E7=BB=8F=E6=B7=BB=E5=8A=A0=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93=EF=BC=8C=E9=87=8C=E9=9D=A2=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8A=A0=E4=B8=8D=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataSpecs/ThingModelStructDataSpecs.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue b/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue index 6088743a..fb2258c1 100644 --- a/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue +++ b/src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue @@ -5,7 +5,6 @@ :rules="[{ required: true, validator: validateList, trigger: 'change' }]" label="JSON 对象" > -
{ } // 查找是否已有相同 identifier 的项 - if (isEmpty(dataSpecsList.value)) { - dataSpecsList.value = [] - } const existingIndex = dataSpecsList.value.findIndex( (spec) => spec.identifier === data.identifier ) @@ -158,6 +154,13 @@ const validateList = (_: any, __: any, callback: any) => { } callback() } + +/** 组件初始化 */ +onMounted(async () => { + await nextTick() + // 预防 dataSpecsList 空指针 + isEmpty(dataSpecsList.value) && (dataSpecsList.value = []) +})