【代码完善】IOT: 确保 ThingModel 中 dataSpecs 和 dataSpecsList 之中必须传入且只能传入一个
parent
4569491012
commit
9bd96a3d63
|
@ -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({
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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 的项
|
||||
|
|
Loading…
Reference in New Issue