26
26
<div >
27
27
<el-form ref =" formRef" :model =" configForm" label-position =" top" :rules =" formRules" >
28
28
<el-form-item label =" 触发器类型" prop =" type" >
29
- <el-select v-model =" configForm.type" >
29
+ <el-select v-model =" configForm.type" @change = " changeTriggerType " >
30
30
<el-option
31
31
v-for =" (item, index) in TRIGGER_TYPES"
32
32
:key =" index"
121
121
</el-button >
122
122
</el-form-item >
123
123
</div >
124
+
124
125
<!-- 表单数据修改触发器 -->
125
126
<div v-if =" configForm.type === TriggerTypeEnum.FORM_UPDATE" >
126
127
<div v-for =" (formSetting, index) in configForm.formSettings" :key =" index" >
150
151
type =" success"
151
152
effect =" light"
152
153
closable
153
- @close =" deleteFormUpdateCondition (formSetting)"
154
- @click =" openFormUpdateCondition (index, formSetting)"
154
+ @close =" deleteFormSettingCondition (formSetting)"
155
+ @click =" openFormSettingCondition (index, formSetting)"
155
156
>
156
157
{{ showConditionText(formSetting) }}
157
158
</el-tag >
160
161
v-else
161
162
type =" primary"
162
163
text
163
- @click =" addFormUpdateCondition (index, formSetting)"
164
+ @click =" addFormSettingCondition (index, formSetting)"
164
165
>
165
166
<Icon icon =" ep:link" class =" mr-5px" />添加条件
166
167
</el-button >
231
232
<Icon icon =" ep:setting" class =" mr-5px" />添加设置
232
233
</el-button >
233
234
</div >
235
+
236
+ <!-- 表单数据删除触发器 -->
237
+ <div v-if =" configForm.type === TriggerTypeEnum.FORM_DELETE" >
238
+ <div v-for =" (formSetting, index) in configForm.formSettings" :key =" index" >
239
+ <el-card class =" w-580px mt-4" >
240
+ <template #header >
241
+ <div class =" flex items-center justify-between" >
242
+ <div >删除表单设置 {{ index + 1 }}</div >
243
+ <el-button
244
+ type =" primary"
245
+ plain
246
+ circle
247
+ v-if =" configForm.formSettings!.length > 1"
248
+ @click =" deleteFormSetting(index)"
249
+ >
250
+ <Icon icon =" ep:close" />
251
+ </el-button >
252
+ </div >
253
+ </template >
254
+
255
+ <!-- 条件设置 -->
256
+ <ConditionDialog
257
+ :ref =" `condition-${index}`"
258
+ @update-condition =" (val) => handleConditionUpdate(index, val)"
259
+ />
260
+ <div class =" cursor-pointer" v-if =" formSetting.conditionType" >
261
+ <el-tag
262
+ type =" warning"
263
+ effect =" light"
264
+ closable
265
+ @close =" deleteFormSettingCondition(formSetting)"
266
+ @click =" openFormSettingCondition(index, formSetting)"
267
+ >
268
+ {{ showConditionText(formSetting) }}
269
+ </el-tag >
270
+ </div >
271
+ <el-button
272
+ v-else
273
+ type =" primary"
274
+ text
275
+ @click =" addFormSettingCondition(index, formSetting)"
276
+ >
277
+ <Icon icon =" ep:link" class =" mr-5px" />添加条件
278
+ </el-button >
279
+
280
+ <el-divider content-position =" left" >删除表单字段设置</el-divider >
281
+ <!-- 表单字段删除设置 -->
282
+ <div class =" flex flex-wrap gap-2" >
283
+ <el-select
284
+ v-model =" formSetting.deleteFields"
285
+ multiple
286
+ placeholder =" 请选择要删除的字段"
287
+ class =" w-full"
288
+ >
289
+ <el-option
290
+ v-for =" field in formFields"
291
+ :key =" field.field"
292
+ :label =" field.title"
293
+ :value =" field.field"
294
+ />
295
+ </el-select >
296
+ </div >
297
+ </el-card >
298
+ </div >
299
+
300
+ <!-- 添加新的设置 -->
301
+ <el-button class =" mt-6" type =" primary" text @click =" addFormSetting" >
302
+ <Icon icon =" ep:setting" class =" mr-5px" />添加设置
303
+ </el-button >
304
+ </div >
234
305
</el-form >
235
306
</div >
236
307
<template #footer >
@@ -292,7 +363,8 @@ const configForm = ref<TriggerSetting>({
292
363
formSettings: [
293
364
{
294
365
conditionGroups: DEFAULT_CONDITION_GROUP_VALUE ,
295
- updateFormFields: {}
366
+ updateFormFields: {},
367
+ deleteFields: []
296
368
}
297
369
]
298
370
})
@@ -308,6 +380,46 @@ const optionalUpdateFormFields = computed(() => {
308
380
}))
309
381
})
310
382
383
+ let originalSetting: TriggerSetting | undefined
384
+
385
+ /** 触发器类型改变了 */
386
+ const changeTriggerType = () => {
387
+ if (configForm .value .type === TriggerTypeEnum .HTTP_REQUEST ) {
388
+ configForm .value .httpRequestSetting = originalSetting ?.httpRequestSetting || {
389
+ url: ' ' ,
390
+ header: [],
391
+ body: [],
392
+ response: []
393
+ }
394
+ configForm .value .formSettings = undefined
395
+ } else if (configForm .value .type === TriggerTypeEnum .FORM_UPDATE ) {
396
+ configForm .value .formSettings =
397
+ originalSetting ?.type === TriggerTypeEnum .FORM_UPDATE && originalSetting .formSettings
398
+ ? originalSetting .formSettings
399
+ : [
400
+ {
401
+ conditionGroups: DEFAULT_CONDITION_GROUP_VALUE ,
402
+ updateFormFields: {},
403
+ deleteFields: []
404
+ }
405
+ ]
406
+ configForm .value .httpRequestSetting = undefined
407
+ } else if (configForm .value .type === TriggerTypeEnum .FORM_DELETE ) {
408
+ console .log (' originalSetting?.type' , originalSetting ?.type )
409
+ configForm .value .formSettings =
410
+ originalSetting ?.type === TriggerTypeEnum .FORM_DELETE && originalSetting .formSettings
411
+ ? originalSetting .formSettings
412
+ : [
413
+ {
414
+ conditionGroups: DEFAULT_CONDITION_GROUP_VALUE ,
415
+ updateFormFields: undefined ,
416
+ deleteFields: []
417
+ }
418
+ ]
419
+ configForm .value .httpRequestSetting = undefined
420
+ }
421
+ }
422
+
311
423
/** 添加 HTTP 请求返回值设置项 */
312
424
const addHttpResponseSetting = (responseSetting : Record <string , string >[]) => {
313
425
responseSetting .push ({
@@ -325,7 +437,8 @@ const deleteHttpResponseSetting = (responseSetting: Record<string, string>[], in
325
437
const addFormSetting = () => {
326
438
configForm .value .formSettings ! .push ({
327
439
conditionGroups: DEFAULT_CONDITION_GROUP_VALUE ,
328
- updateFormFields: {}
440
+ updateFormFields: {},
441
+ deleteFields: []
329
442
})
330
443
}
331
444
@@ -335,16 +448,16 @@ const deleteFormSetting = (index: number) => {
335
448
}
336
449
337
450
/** 添加条件配置 */
338
- const addFormUpdateCondition = (index : number , formSetting : FormTriggerSetting ) => {
451
+ const addFormSettingCondition = (index : number , formSetting : FormTriggerSetting ) => {
339
452
const conditionDialog = proxy .$refs [` condition-${index } ` ][0 ]
340
453
conditionDialog .open (formSetting )
341
454
}
342
455
/** 删除条件配置 */
343
- const deleteFormUpdateCondition = (formSetting : FormTriggerSetting ) => {
456
+ const deleteFormSettingCondition = (formSetting : FormTriggerSetting ) => {
344
457
formSetting .conditionType = undefined
345
458
}
346
459
/** 打开条件配置弹窗 */
347
- const openFormUpdateCondition = (index : number , formSetting : FormTriggerSetting ) => {
460
+ const openFormSettingCondition = (index : number , formSetting : FormTriggerSetting ) => {
348
461
const conditionDialog = proxy .$refs [` condition-${index } ` ][0 ]
349
462
conditionDialog .open (formSetting )
350
463
}
@@ -397,9 +510,18 @@ const saveConfig = async () => {
397
510
currentNode .value .showText = showText
398
511
if (configForm .value .type === TriggerTypeEnum .HTTP_REQUEST ) {
399
512
configForm .value .formSettings = undefined
400
- }
401
- if (configForm .value .type === TriggerTypeEnum .FORM_UPDATE ) {
513
+ } else if (configForm .value .type === TriggerTypeEnum .FORM_UPDATE ) {
514
+ configForm .value .httpRequestSetting = undefined
515
+ // 清理删除字段相关的数据
516
+ configForm .value .formSettings ?.forEach ((setting ) => {
517
+ setting .deleteFields = undefined
518
+ })
519
+ } else if (configForm .value .type === TriggerTypeEnum .FORM_DELETE ) {
402
520
configForm .value .httpRequestSetting = undefined
521
+ // 清理修改字段相关的数据
522
+ configForm .value .formSettings ?.forEach ((setting ) => {
523
+ setting .updateFormFields = undefined
524
+ })
403
525
}
404
526
currentNode .value .triggerSetting = configForm .value
405
527
settingVisible .value = false
@@ -419,13 +541,22 @@ const getShowText = (): string => {
419
541
}
420
542
}
421
543
showText = ' 修改表单数据'
544
+ } else if (configForm .value .type === TriggerTypeEnum .FORM_DELETE ) {
545
+ for (const [index, setting] of configForm .value .formSettings ! .entries ()) {
546
+ if (! setting .deleteFields || setting .deleteFields .length === 0 ) {
547
+ message .warning (` 请选择表单设置${index + 1 }要删除的字段 ` )
548
+ return ' '
549
+ }
550
+ }
551
+ showText = ' 删除表单数据'
422
552
}
423
553
return showText
424
554
}
425
555
426
556
/** 显示触发器节点配置, 由父组件传过来 */
427
557
const showTriggerNodeConfig = (node : SimpleFlowNode ) => {
428
558
nodeName .value = node .name
559
+ originalSetting = node .triggerSetting
429
560
if (node .triggerSetting ) {
430
561
configForm .value = {
431
562
type: node .triggerSetting .type ,
@@ -438,7 +569,8 @@ const showTriggerNodeConfig = (node: SimpleFlowNode) => {
438
569
formSettings: node .triggerSetting .formSettings || [
439
570
{
440
571
conditionGroups: DEFAULT_CONDITION_GROUP_VALUE ,
441
- updateFormFields: {}
572
+ updateFormFields: {},
573
+ deleteFields: []
442
574
}
443
575
]
444
576
}
0 commit comments