Skip to content

Commit 9bd96a3

Browse files
author
puhui999
committed
【代码完善】IOT: 确保 ThingModel 中 dataSpecs 和 dataSpecsList 之中必须传入且只能传入一个
1 parent 4569491 commit 9bd96a3

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/views/iot/thingmodel/ThingModelDataSpecs.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ const getDataTypeOptions = computed(() => {
121121
const handleChange = (dataType: any) => {
122122
property.value.dataSpecsList = []
123123
property.value.dataSpecs = {}
124-
125-
property.value.dataSpecs.dataType = dataType
124+
// 不是列表型数据才设置 dataSpecs.dataType
125+
![DataSpecsDataType.ENUM, DataSpecsDataType.BOOL, DataSpecsDataType.STRUCT].includes(dataType) &&
126+
(property.value.dataSpecs.dataType = dataType)
126127
switch (dataType) {
127128
case DataSpecsDataType.ENUM:
128129
property.value.dataSpecsList.push({

src/views/iot/thingmodel/ThingModelForm.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
4646
import { DataSpecsDataType, ThingModelFormRules } from './config'
4747
import { cloneDeep } from 'lodash-es'
4848
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
49+
import { isEmpty } from '@/utils/is'
4950
5051
/** IoT 物模型数据表单 */
5152
defineOptions({ name: 'IoTProductThingModelForm' })
@@ -103,6 +104,13 @@ const submitForm = async () => {
103104
data.dataType = data.property.dataType
104105
data.property.identifier = data.identifier
105106
data.property.name = data.name
107+
// 处理 dataSpecs 为空的情况
108+
if (isEmpty(data.property.dataSpecs)) {
109+
delete data.property.dataSpecs
110+
}
111+
if (isEmpty(data.property.dataSpecsList)) {
112+
delete data.property.dataSpecsList
113+
}
106114
if (formType.value === 'create') {
107115
await ThingModelApi.createThingModel(data)
108116
message.success(t('common.createSuccess'))

src/views/iot/thingmodel/dataSpecs/ThingModelStructDataSpecs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const submitForm = async () => {
111111
!!data.property.dataSpecs && Object.keys(data.property.dataSpecs).length > 1
112112
? data.property.dataSpecs
113113
: undefined,
114-
dataSpecsList: data.property.dataSpecsList
114+
dataSpecsList: isEmpty(data.property.dataSpecsList) ? undefined : data.property.dataSpecsList
115115
}
116116
117117
// 查找是否已有相同 identifier 的项

0 commit comments

Comments
 (0)