Skip to content

Commit bfe4336

Browse files
committed
【功能新增】 新增删除表单数据触发器
1 parent b2ddefe commit bfe4336

File tree

3 files changed

+158
-18
lines changed

3 files changed

+158
-18
lines changed

src/components/SimpleProcessDesignerV2/src/consts.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,13 @@ export enum TriggerTypeEnum {
748748
*/
749749
HTTP_REQUEST = 1,
750750
/**
751-
* 流程表单更新触发器
751+
* 表单数据更新触发器
752752
*/
753-
FORM_UPDATE = 2
753+
FORM_UPDATE = 2,
754+
/**
755+
* 表单数据删除触发器
756+
*/
757+
FORM_DELETE = 3
754758
}
755759

756760
/**
@@ -777,11 +781,14 @@ export type FormTriggerSetting = {
777781
conditionExpression?: string
778782
// 条件组
779783
conditionGroups?: ConditionGroup
780-
// 更新表单字段
781-
updateFormFields?: Record<string, any>
784+
// 更新表单字段配置
785+
updateFormFields?: Record<string, any>,
786+
// 删除表单字段配置
787+
deleteFields?: string[]
782788
}
783789

784790
export const TRIGGER_TYPES: DictDataVO[] = [
785791
{ label: 'HTTP 请求', value: TriggerTypeEnum.HTTP_REQUEST },
786-
{ label: '修改表单数据', value: TriggerTypeEnum.FORM_UPDATE }
792+
{ label: '修改表单数据', value: TriggerTypeEnum.FORM_UPDATE },
793+
{ label: '删除表单数据', value: TriggerTypeEnum.FORM_DELETE }
787794
]

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

Lines changed: 144 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div>
2727
<el-form ref="formRef" :model="configForm" label-position="top" :rules="formRules">
2828
<el-form-item label="触发器类型" prop="type">
29-
<el-select v-model="configForm.type">
29+
<el-select v-model="configForm.type" @change="changeTriggerType">
3030
<el-option
3131
v-for="(item, index) in TRIGGER_TYPES"
3232
:key="index"
@@ -121,6 +121,7 @@
121121
</el-button>
122122
</el-form-item>
123123
</div>
124+
124125
<!-- 表单数据修改触发器 -->
125126
<div v-if="configForm.type === TriggerTypeEnum.FORM_UPDATE">
126127
<div v-for="(formSetting, index) in configForm.formSettings" :key="index">
@@ -150,8 +151,8 @@
150151
type="success"
151152
effect="light"
152153
closable
153-
@close="deleteFormUpdateCondition(formSetting)"
154-
@click="openFormUpdateCondition(index, formSetting)"
154+
@close="deleteFormSettingCondition(formSetting)"
155+
@click="openFormSettingCondition(index, formSetting)"
155156
>
156157
{{ showConditionText(formSetting) }}
157158
</el-tag>
@@ -160,7 +161,7 @@
160161
v-else
161162
type="primary"
162163
text
163-
@click="addFormUpdateCondition(index, formSetting)"
164+
@click="addFormSettingCondition(index, formSetting)"
164165
>
165166
<Icon icon="ep:link" class="mr-5px" />添加条件
166167
</el-button>
@@ -231,6 +232,76 @@
231232
<Icon icon="ep:setting" class="mr-5px" />添加设置
232233
</el-button>
233234
</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>
234305
</el-form>
235306
</div>
236307
<template #footer>
@@ -292,7 +363,8 @@ const configForm = ref<TriggerSetting>({
292363
formSettings: [
293364
{
294365
conditionGroups: DEFAULT_CONDITION_GROUP_VALUE,
295-
updateFormFields: {}
366+
updateFormFields: {},
367+
deleteFields: []
296368
}
297369
]
298370
})
@@ -308,6 +380,46 @@ const optionalUpdateFormFields = computed(() => {
308380
}))
309381
})
310382
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+
311423
/** 添加 HTTP 请求返回值设置项 */
312424
const addHttpResponseSetting = (responseSetting: Record<string, string>[]) => {
313425
responseSetting.push({
@@ -325,7 +437,8 @@ const deleteHttpResponseSetting = (responseSetting: Record<string, string>[], in
325437
const addFormSetting = () => {
326438
configForm.value.formSettings!.push({
327439
conditionGroups: DEFAULT_CONDITION_GROUP_VALUE,
328-
updateFormFields: {}
440+
updateFormFields: {},
441+
deleteFields: []
329442
})
330443
}
331444
@@ -335,16 +448,16 @@ const deleteFormSetting = (index: number) => {
335448
}
336449
337450
/** 添加条件配置 */
338-
const addFormUpdateCondition = (index: number, formSetting: FormTriggerSetting) => {
451+
const addFormSettingCondition = (index: number, formSetting: FormTriggerSetting) => {
339452
const conditionDialog = proxy.$refs[`condition-${index}`][0]
340453
conditionDialog.open(formSetting)
341454
}
342455
/** 删除条件配置 */
343-
const deleteFormUpdateCondition = (formSetting: FormTriggerSetting) => {
456+
const deleteFormSettingCondition = (formSetting: FormTriggerSetting) => {
344457
formSetting.conditionType = undefined
345458
}
346459
/** 打开条件配置弹窗 */
347-
const openFormUpdateCondition = (index: number, formSetting: FormTriggerSetting) => {
460+
const openFormSettingCondition = (index: number, formSetting: FormTriggerSetting) => {
348461
const conditionDialog = proxy.$refs[`condition-${index}`][0]
349462
conditionDialog.open(formSetting)
350463
}
@@ -397,9 +510,18 @@ const saveConfig = async () => {
397510
currentNode.value.showText = showText
398511
if (configForm.value.type === TriggerTypeEnum.HTTP_REQUEST) {
399512
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) {
402520
configForm.value.httpRequestSetting = undefined
521+
// 清理修改字段相关的数据
522+
configForm.value.formSettings?.forEach((setting) => {
523+
setting.updateFormFields = undefined
524+
})
403525
}
404526
currentNode.value.triggerSetting = configForm.value
405527
settingVisible.value = false
@@ -419,13 +541,22 @@ const getShowText = (): string => {
419541
}
420542
}
421543
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 = '删除表单数据'
422552
}
423553
return showText
424554
}
425555
426556
/** 显示触发器节点配置, 由父组件传过来 */
427557
const showTriggerNodeConfig = (node: SimpleFlowNode) => {
428558
nodeName.value = node.name
559+
originalSetting = node.triggerSetting
429560
if (node.triggerSetting) {
430561
configForm.value = {
431562
type: node.triggerSetting.type,
@@ -438,7 +569,8 @@ const showTriggerNodeConfig = (node: SimpleFlowNode) => {
438569
formSettings: node.triggerSetting.formSettings || [
439570
{
440571
conditionGroups: DEFAULT_CONDITION_GROUP_VALUE,
441-
updateFormFields: {}
572+
updateFormFields: {},
573+
deleteFields: []
442574
}
443575
]
444576
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<!-- TODO @jason:有可能,它里面套 Condition 么? -->
1+
<!-- TODO @jason:有可能,它里面套 Condition 么? -->
2+
<!-- TODO 怕影响其它节点功能,后面看看如何如何复用 Condtion -->
23
<template>
34
<Dialog v-model="dialogVisible" title="条件配置" width="600px" :fullscreen="false">
45
<div class="h-410px">

0 commit comments

Comments
 (0)