@@ -47,6 +47,7 @@ import { SimpleFlowNode, ConditionType } from '../consts'
47
47
import { getDefaultConditionNodeName } from ' ../utils'
48
48
import { useFormFieldsAndStartUser , getConditionShowText } from ' ../node'
49
49
import Condition from ' ./components/Condition.vue'
50
+ import { cloneDeep } from ' lodash-es'
50
51
const message = useMessage () // 消息弹窗
51
52
defineOptions ({
52
53
name: ' ConditionNodeConfig'
@@ -63,9 +64,43 @@ const props = defineProps({
63
64
})
64
65
const settingVisible = ref (false )
65
66
const currentNode = ref <SimpleFlowNode >(props .conditionNode )
66
- const condition = ref <any >()
67
+ const condition = ref <any >({
68
+ conditionType: ConditionType .RULE , // 设置默认值
69
+ conditionExpression: ' ' ,
70
+ conditionGroups: {
71
+ and: true ,
72
+ conditions: [{
73
+ and: true ,
74
+ rules: [{
75
+ opCode: ' ==' ,
76
+ leftSide: ' ' ,
77
+ rightSide: ' '
78
+ }]
79
+ }]
80
+ }
81
+ })
67
82
const open = () => {
68
- condition .value = currentNode .value .conditionSetting
83
+ // 如果有已存在的配置则使用,否则使用默认值
84
+ if (currentNode .value .conditionSetting ) {
85
+ condition .value = cloneDeep (currentNode .value .conditionSetting )
86
+ } else {
87
+ // 重置为默认值
88
+ condition .value = {
89
+ conditionType: ConditionType .RULE ,
90
+ conditionExpression: ' ' ,
91
+ conditionGroups: {
92
+ and: true ,
93
+ conditions: [{
94
+ and: true ,
95
+ rules: [{
96
+ opCode: ' ==' ,
97
+ leftSide: ' ' ,
98
+ rightSide: ' '
99
+ }]
100
+ }]
101
+ }
102
+ }
103
+ }
69
104
settingVisible .value = true
70
105
}
71
106
@@ -123,15 +158,13 @@ const saveConfig = async () => {
123
158
return false
124
159
}
125
160
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
- }
161
+ // 使用 cloneDeep 进行深拷贝
162
+ currentNode .value .conditionSetting = cloneDeep ({
163
+ ... currentNode .value .conditionSetting ,
164
+ conditionType: condition .value ?.conditionType ,
165
+ conditionExpression: condition .value ?.conditionType === ConditionType .EXPRESSION ? condition .value ?.conditionExpression : undefined ,
166
+ conditionGroups: condition .value ?.conditionType === ConditionType .RULE ? condition .value ?.conditionGroups : undefined
167
+ })
135
168
}
136
169
settingVisible .value = false
137
170
return true
0 commit comments