Skip to content

Commit c7b135e

Browse files
committed
优化代码 切换点击条件分支后带来的 条件切换问题
1 parent b2ddefe commit c7b135e

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

src/components/SimpleProcessDesignerV2/src/nodes-config/ConditionNodeConfig.vue

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,43 @@ const props = defineProps({
6363
})
6464
const settingVisible = ref(false)
6565
const currentNode = ref<SimpleFlowNode>(props.conditionNode)
66-
const condition = ref<any>()
66+
const condition = ref<any>({
67+
conditionType: ConditionType.RULE, // 设置默认值
68+
conditionExpression: '',
69+
conditionGroups: {
70+
and: true,
71+
conditions: [{
72+
and: true,
73+
rules: [{
74+
opCode: '==',
75+
leftSide: '',
76+
rightSide: ''
77+
}]
78+
}]
79+
}
80+
})
6781
const open = () => {
68-
condition.value = currentNode.value.conditionSetting
82+
// 如果有已存在的配置则使用,否则使用默认值
83+
if (currentNode.value.conditionSetting) {
84+
condition.value = JSON.parse(JSON.stringify(currentNode.value.conditionSetting))
85+
} else {
86+
// 重置为默认值
87+
condition.value = {
88+
conditionType: ConditionType.RULE,
89+
conditionExpression: '',
90+
conditionGroups: {
91+
and: true,
92+
conditions: [{
93+
and: true,
94+
rules: [{
95+
opCode: '==',
96+
leftSide: '',
97+
rightSide: ''
98+
}]
99+
}]
100+
}
101+
}
102+
}
69103
settingVisible.value = true
70104
}
71105
@@ -123,15 +157,13 @@ const saveConfig = async () => {
123157
return false
124158
}
125159
currentNode.value.showText = showText
126-
currentNode.value.conditionSetting!.conditionType = condition.value?.conditionType
127-
if (currentNode.value.conditionSetting?.conditionType === ConditionType.EXPRESSION) {
128-
currentNode.value.conditionSetting.conditionGroups = undefined
129-
currentNode.value.conditionSetting.conditionExpression = condition.value?.conditionExpression
130-
}
131-
if (currentNode.value.conditionSetting!.conditionType === ConditionType.RULE) {
132-
currentNode.value.conditionSetting!.conditionExpression = undefined
133-
currentNode.value.conditionSetting!.conditionGroups = condition.value?.conditionGroups
134-
}
160+
// 深拷贝保存的条件设置,避免引用问题
161+
currentNode.value.conditionSetting = JSON.parse(JSON.stringify({
162+
...currentNode.value.conditionSetting,
163+
conditionType: condition.value?.conditionType,
164+
conditionExpression: condition.value?.conditionType === ConditionType.EXPRESSION ? condition.value?.conditionExpression : undefined,
165+
conditionGroups: condition.value?.conditionType === ConditionType.RULE ? condition.value?.conditionGroups : undefined
166+
}))
135167
}
136168
settingVisible.value = false
137169
return true

0 commit comments

Comments
 (0)