diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue index b6efdf8b..92f518b5 100644 --- a/src/views/iot/device/index.vue +++ b/src/views/iot/device/index.vue @@ -733,12 +733,32 @@ const openRuleForm = async (row: DevicePointRuleVO & { pointRulesVOList?: any[] if (list.length) { const first = list[0] as any - ruleForm.fieldRule = (first.rule ?? row.fieldRule) as any - ruleForm.ruleAttributeId = first.id as any + const firstRule = first.rule ?? row.fieldRule + const firstAttrId = (() => { + if (first && first.code != null) { + const target = ruleAttributeOptions.value.find( + (item) => item.attributeCode === first.code + ) + return target?.id + } + if (first && first.id != null) return first.id + return undefined + })() + ruleForm.fieldRule = firstRule as any + ruleForm.ruleAttributeId = firstAttrId as any ruleForm.ruleOperator = first.operator as any ruleForm.ruleValue = first.operatorRule as any extraPointRules.value = list.slice(1).map((item: any) => ({ - id: item.id, + id: (() => { + if (item && item.code != null) { + const target = ruleAttributeOptions.value.find( + (opt) => opt.attributeCode === item.code + ) + return target?.id + } + if (item && item.id != null) return item.id + return undefined + })(), rule: item.rule, operator: item.operator, operatorRule: item.operatorRule, @@ -764,18 +784,25 @@ const handleRuleSubmit = async () => { const pointRulesVOList: any[] = [] if (ruleForm.ruleAttributeId && ruleForm.ruleOperator) { - pointRulesVOList.push({ - id: ruleForm.ruleAttributeId, - rule: ruleForm.fieldRule, - operator: ruleForm.ruleOperator, - operatorRule: ruleForm.ruleValue, - }) + const attr = ruleAttributeOptions.value.find( + (item) => item.id === ruleForm.ruleAttributeId + ) + if (attr && attr.attributeCode) { + pointRulesVOList.push({ + code: attr.attributeCode, + rule: ruleForm.fieldRule, + operator: ruleForm.ruleOperator, + operatorRule: ruleForm.ruleValue, + }) + } } extraPointRules.value.forEach((item) => { if (!item.id || !item.operator) return + const attr = ruleAttributeOptions.value.find((opt) => opt.id === item.id) + if (!attr || !attr.attributeCode) return pointRulesVOList.push({ - id: item.id, + code: attr.attributeCode, rule: item.rule ?? ruleForm.fieldRule, operator: item.operator, operatorRule: item.operatorRule, diff --git a/src/views/iot/devicemodel/index.vue b/src/views/iot/devicemodel/index.vue index 68ded9fe..8f9475f2 100644 --- a/src/views/iot/devicemodel/index.vue +++ b/src/views/iot/devicemodel/index.vue @@ -674,12 +674,32 @@ const openRuleForm = async (row: DeviceModelRuleVO & { pointRulesVOList?: any[] if (list.length) { const first = list[0] as any - ruleForm.fieldRule = (first.rule ?? row.fieldRule) as any - ruleForm.ruleAttributeId = first.id as any + const firstRule = first.rule ?? row.fieldRule + const firstAttrId = (() => { + if (first && first.code != null) { + const target = ruleAttributeOptions.value.find( + (item) => item.attributeCode === first.code + ) + return target?.id + } + if (first && first.id != null) return first.id + return undefined + })() + ruleForm.fieldRule = firstRule as any + ruleForm.ruleAttributeId = firstAttrId as any ruleForm.ruleOperator = first.operator as any ruleForm.ruleValue = first.operatorRule as any extraPointRules.value = list.slice(1).map((item: any) => ({ - id: item.id, + id: (() => { + if (item && item.code != null) { + const target = ruleAttributeOptions.value.find( + (opt) => opt.attributeCode === item.code + ) + return target?.id + } + if (item && item.id != null) return item.id + return undefined + })(), rule: item.rule, operator: item.operator, operatorRule: item.operatorRule, @@ -705,18 +725,25 @@ const handleRuleSubmit = async () => { const pointRulesVOList: any[] = [] if (ruleForm.ruleAttributeId && ruleForm.ruleOperator) { + const attr = ruleAttributeOptions.value.find( + (item) => item.id === ruleForm.ruleAttributeId + ) + if (attr && attr.attributeCode) { pointRulesVOList.push({ - id: ruleForm.ruleAttributeId, + code: attr.attributeCode, rule: ruleForm.fieldRule, operator: ruleForm.ruleOperator, operatorRule: ruleForm.ruleValue, }) + } } extraPointRules.value.forEach((item) => { if (!item.id || !item.operator) return + const attr = ruleAttributeOptions.value.find((opt) => opt.id === item.id) + if (!attr || !attr.attributeCode) return pointRulesVOList.push({ - id: item.id, + code: attr.attributeCode, rule: item.rule ?? ruleForm.fieldRule, operator: item.operator, operatorRule: item.operatorRule, @@ -727,7 +754,6 @@ const handleRuleSubmit = async () => { id: ruleForm.id, identifier: ruleForm.identifier, fieldName: ruleForm.fieldName, - fieldRule: ruleForm.fieldRule, defaultValue: ruleForm.defaultValue, modelId: ruleForm.modelId, pointRulesVOList,