Skip to content

Commit 9b62862

Browse files
author
puhui999
committed
【功能完善】IOT: ThingModel 服务和事件
1 parent 5391720 commit 9b62862

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/views/iot/thingmodel/ThingModelForm.vue

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,15 @@ defineExpose({ open, close: () => (dialogVisible.value = false) })
113113
/** 提交表单 */
114114
const emit = defineEmits(['success'])
115115
const submitForm = async () => {
116+
debugger
116117
await formRef.value.validate()
117118
formLoading.value = true
118119
try {
119120
const data = cloneDeep(formData.value) as ThingModelData
120121
// 信息补全
121122
data.productId = product!.value.id
122123
data.productKey = product!.value.productKey
123-
data.dataType = data.property.dataType
124-
data.property.identifier = data.identifier
125-
data.property.name = data.name
126-
removeExtraAttributes(data)
124+
fillExtraAttributes(data)
127125
if (formType.value === 'create') {
128126
await ThingModelApi.createThingModel(data)
129127
message.success(t('common.createSuccess'))
@@ -138,29 +136,46 @@ const submitForm = async () => {
138136
}
139137
}
140138
141-
/** 删除额外的属性 */
142-
const removeExtraAttributes = (data: any) => {
143-
// 处理 dataSpecs 为空的情况
144-
if (isEmpty(data.property.dataSpecs)) {
145-
delete data.property.dataSpecs
146-
}
147-
if (isEmpty(data.property.dataSpecsList)) {
148-
delete data.property.dataSpecsList
149-
}
139+
/** 填写额外的属性 */
140+
const fillExtraAttributes = (data: any) => {
150141
// 处理不同类型的情况
142+
// 属性
151143
if (data.type === ThingModelType.PROPERTY) {
144+
removeDataSpecs(data.property)
145+
data.dataType = data.property.dataType
146+
data.property.identifier = data.identifier
147+
data.property.name = data.name
152148
delete data.service
153149
delete data.event
154150
}
151+
// 服务
155152
if (data.type === ThingModelType.SERVICE) {
153+
removeDataSpecs(data.service)
154+
data.dataType = data.service.dataType
155+
data.service.identifier = data.identifier
156+
data.service.name = data.name
156157
delete data.property
157158
delete data.event
158159
}
160+
// 事件
159161
if (data.type === ThingModelType.EVENT) {
162+
removeDataSpecs(data.event)
163+
data.dataType = data.event.dataType
164+
data.event.identifier = data.identifier
165+
data.event.name = data.name
160166
delete data.property
161167
delete data.service
162168
}
163169
}
170+
/** 处理 dataSpecs 为空的情况 */
171+
const removeDataSpecs = (val: any) => {
172+
if (isEmpty(val.dataSpecs)) {
173+
delete val.dataSpecs
174+
}
175+
if (isEmpty(val.dataSpecsList)) {
176+
delete val.dataSpecsList
177+
}
178+
}
164179
165180
/** 重置表单 */
166181
const resetForm = () => {

0 commit comments

Comments
 (0)