83
83
>
84
84
<el-select class =" w-160px!" v-model =" item.key" placeholder =" 请选择表单字段" >
85
85
<el-option
86
- v-for =" (field, fIdx) in formFieldOptions "
86
+ v-for =" (field, fIdx) in formFields "
87
87
:key =" fIdx"
88
88
:label =" field.title"
89
89
:value =" field.field"
121
121
</el-button >
122
122
</el-form-item >
123
123
</div >
124
+ <div
125
+ v-if ="
126
+ configForm.type === TriggerTypeEnum.UPDATE_NORMAL_FORM && configForm.normalFormSetting
127
+ "
128
+ >
129
+ <el-divider content-position =" left" >修改表单设置</el-divider >
130
+ <div
131
+ class =" flex items-center"
132
+ v-for =" key in Object.keys(configForm.normalFormSetting.updateFormFields!)"
133
+ :key =" key"
134
+ >
135
+ <div class =" mr-2 flex items-center" >
136
+ <el-form-item >
137
+ <el-select
138
+ class =" w-160px!"
139
+ :model-value =" key"
140
+ @update:model-value =" (newKey) => updateFormFieldKey(key, newKey)"
141
+ placeholder =" 请选择表单字段"
142
+ :disabled =" key !== ''"
143
+ >
144
+ <el-option
145
+ v-for =" (field, fIdx) in optionalUpdateFormFields"
146
+ :key =" fIdx"
147
+ :label =" field.title"
148
+ :value =" field.field"
149
+ :disabled =" field.disabled"
150
+ />
151
+ </el-select >
152
+ </el-form-item >
153
+ </div >
154
+ <div class =" mx-2" ><el-form-item >的值设置为</el-form-item ></div >
155
+ <div class =" mr-2" >
156
+ <el-form-item
157
+ :prop =" `normalFormSetting.updateFormFields.${key}`"
158
+ :rules =" {
159
+ required: true,
160
+ message: '值不能为空',
161
+ trigger: 'blur'
162
+ }"
163
+ >
164
+ <el-input
165
+ class =" w-160px"
166
+ v-model =" configForm.normalFormSetting.updateFormFields![key]"
167
+ placeholder =" 请输入"
168
+ :disabled =" !key"
169
+ />
170
+ </el-form-item >
171
+ </div >
172
+ <div class =" mr-1 pt-1 cursor-pointer" >
173
+ <el-form-item >
174
+ <Icon icon =" ep:delete" :size =" 18" @click =" deleteFormFieldSetting(key)" />
175
+ </el-form-item >
176
+ </div >
177
+ </div >
178
+ <el-button type =" primary" text @click =" addFormFieldSetting()" >
179
+ <Icon icon =" ep:plus" class =" mr-5px" />添加修改字段
180
+ </el-button >
181
+ </div >
124
182
</el-form >
125
183
</div >
126
184
<template #footer >
@@ -146,6 +204,7 @@ const props = defineProps({
146
204
required: true
147
205
}
148
206
})
207
+ const message = useMessage () // 消息弹窗
149
208
// 抽屉配置
150
209
const { settingVisible, closeDrawer, openDrawer } = useDrawer ()
151
210
// 当前节点
@@ -167,10 +226,28 @@ const configForm = ref<TriggerSetting>({
167
226
header: [],
168
227
body: [],
169
228
response: []
170
- }
229
+ },
230
+ normalFormSetting: { updateFormFields: {} }
171
231
})
172
232
// 流程表单字段
173
- const formFieldOptions = useFormFields ()
233
+ const formFields = useFormFields ()
234
+
235
+ // 可选的修改的表单字段
236
+ const optionalUpdateFormFields = computed (() => {
237
+ const usedFields = Object .keys (configForm .value .normalFormSetting ?.updateFormFields || {})
238
+ return formFields .map ((field ) => ({
239
+ title: field .title ,
240
+ field: field .field ,
241
+ disabled: usedFields .includes (field .field )
242
+ }))
243
+ })
244
+
245
+ const updateFormFieldKey = (oldKey : string , newKey : string ) => {
246
+ if (! configForm .value .normalFormSetting ?.updateFormFields ) return
247
+ const value = configForm .value .normalFormSetting .updateFormFields [oldKey ]
248
+ delete configForm .value .normalFormSetting .updateFormFields [oldKey ]
249
+ configForm .value .normalFormSetting .updateFormFields [newKey ] = value
250
+ }
174
251
175
252
/** 添加 HTTP 请求返回值设置项*/
176
253
const addHttpResponseSetting = (responseSetting : Record <string , string >[]) => {
@@ -185,6 +262,19 @@ const deleteHttpResponseSetting = (responseSetting: Record<string, string>[], in
185
262
responseSetting .splice (index , 1 )
186
263
}
187
264
265
+ /** 添加修改表单设置项 */
266
+ const addFormFieldSetting = () => {
267
+ if (configForm .value .normalFormSetting ! .updateFormFields === undefined ) {
268
+ configForm .value .normalFormSetting ! .updateFormFields = {}
269
+ }
270
+ configForm .value .normalFormSetting ! .updateFormFields [' ' ] = undefined
271
+ }
272
+ /** 删除修改表单设置项 */
273
+ const deleteFormFieldSetting = (key : string ) => {
274
+ if (! configForm .value .normalFormSetting ?.updateFormFields ) return
275
+ delete configForm .value .normalFormSetting .updateFormFields [key ]
276
+ }
277
+
188
278
/** 保存配置 */
189
279
const saveConfig = async () => {
190
280
if (! formRef ) return false
@@ -194,15 +284,29 @@ const saveConfig = async () => {
194
284
if (! showText ) return false
195
285
currentNode .value .name = nodeName .value !
196
286
currentNode .value .showText = showText
287
+ if (configForm .value .type === TriggerTypeEnum .HTTP_REQUEST ) {
288
+ configForm .value .normalFormSetting = undefined
289
+ }
290
+ if (configForm .value .type === TriggerTypeEnum .UPDATE_NORMAL_FORM ) {
291
+ configForm .value .httpRequestSetting = undefined
292
+ }
197
293
currentNode .value .triggerSetting = configForm .value
198
294
settingVisible .value = false
199
295
return true
200
296
}
297
+
201
298
/** 获取节点展示内容 */
202
299
const getShowText = (): string => {
203
300
let showText = ' '
204
301
if (configForm .value .type === TriggerTypeEnum .HTTP_REQUEST ) {
205
- showText = ` ${configForm .value .httpRequestSetting .url } `
302
+ showText = ` ${configForm .value .httpRequestSetting ?.url } `
303
+ } else if (configForm .value .type === TriggerTypeEnum .UPDATE_NORMAL_FORM ) {
304
+ const updatefields = Object .keys (configForm .value .normalFormSetting ?.updateFormFields || {})
305
+ if (updatefields .length === 0 ) {
306
+ message .warning (' 请设置修改表单字段' )
307
+ } else {
308
+ showText = ' 修改表单数据'
309
+ }
206
310
}
207
311
return showText
208
312
}
@@ -211,8 +315,16 @@ const getShowText = (): string => {
211
315
const showTriggerNodeConfig = (node : SimpleFlowNode ) => {
212
316
nodeName .value = node .name
213
317
if (node .triggerSetting ) {
214
- configForm .value .type = node .triggerSetting .type
215
- configForm .value .httpRequestSetting = node .triggerSetting .httpRequestSetting
318
+ configForm .value = {
319
+ type: node .triggerSetting .type ,
320
+ httpRequestSetting: node .triggerSetting .httpRequestSetting || {
321
+ url: ' ' ,
322
+ header: [],
323
+ body: [],
324
+ response: []
325
+ },
326
+ normalFormSetting: node .triggerSetting .normalFormSetting || { updateFormFields: {} }
327
+ }
216
328
}
217
329
}
218
330
0 commit comments