@@ -63,9 +63,43 @@ const props = defineProps({
63
63
})
64
64
const settingVisible = ref (false )
65
65
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
+ })
67
81
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
+ }
69
103
settingVisible .value = true
70
104
}
71
105
@@ -123,15 +157,13 @@ const saveConfig = async () => {
123
157
return false
124
158
}
125
159
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
+ }))
135
167
}
136
168
settingVisible .value = false
137
169
return true
0 commit comments