Skip to content

Commit 163fc68

Browse files
committed
【功能新增】 新增异步Http 请求触发器
1 parent bfe4336 commit 163fc68

File tree

2 files changed

+102
-73
lines changed

2 files changed

+102
-73
lines changed

src/components/SimpleProcessDesignerV2/src/consts.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,11 @@ export enum TriggerTypeEnum {
754754
/**
755755
* 表单数据删除触发器
756756
*/
757-
FORM_DELETE = 3
757+
FORM_DELETE = 3,
758+
/**
759+
* 发起异步 HTTP 请求
760+
*/
761+
ASYNC_HTTP_REQUEST = 4
758762
}
759763

760764
/**
@@ -789,6 +793,7 @@ export type FormTriggerSetting = {
789793

790794
export const TRIGGER_TYPES: DictDataVO[] = [
791795
{ label: 'HTTP 请求', value: TriggerTypeEnum.HTTP_REQUEST },
796+
{ label: '异步 HTTP 请求', value: TriggerTypeEnum.ASYNC_HTTP_REQUEST },
792797
{ label: '修改表单数据', value: TriggerTypeEnum.FORM_UPDATE },
793798
{ label: '删除表单数据', value: TriggerTypeEnum.FORM_DELETE }
794799
]

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

Lines changed: 96 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
</el-form-item>
3838
<!-- HTTP 请求触发器 -->
3939
<div
40-
v-if="configForm.type === TriggerTypeEnum.HTTP_REQUEST && configForm.httpRequestSetting"
40+
v-if="
41+
(configForm.type === TriggerTypeEnum.HTTP_REQUEST ||
42+
configForm.type === TriggerTypeEnum.ASYNC_HTTP_REQUEST) &&
43+
configForm.httpRequestSetting
44+
"
4145
>
4246
<el-form-item>
4347
<el-alert
@@ -58,68 +62,72 @@
5862
:bind="'httpRequestSetting'"
5963
/>
6064
<!-- 返回值设置-->
61-
<el-form-item label="返回值">
62-
<el-alert
63-
title="通过请求返回值, 可以修改流程表单的值"
64-
type="warning"
65-
show-icon
66-
:closable="false"
67-
/>
68-
</el-form-item>
69-
<el-form-item>
70-
<div
71-
class="flex pt-2"
72-
v-for="(item, index) in configForm.httpRequestSetting.response"
73-
:key="index"
74-
>
75-
<div class="mr-2">
76-
<el-form-item
77-
:prop="`httpRequestSetting.response.${index}.key`"
78-
:rules="{
79-
required: true,
80-
message: '表单字段不能为空',
81-
trigger: 'blur'
82-
}"
83-
>
84-
<el-select class="w-160px!" v-model="item.key" placeholder="请选择表单字段">
85-
<el-option
86-
v-for="(field, fIdx) in formFields"
87-
:key="fIdx"
88-
:label="field.title"
89-
:value="field.field"
90-
:disabled="!field.required"
91-
/>
92-
</el-select>
93-
</el-form-item>
94-
</div>
95-
<div class="mr-2">
96-
<el-form-item
97-
:prop="`httpRequestSetting.response.${index}.value`"
98-
:rules="{
99-
required: true,
100-
message: '请求返回字段不能为空',
101-
trigger: 'blur'
102-
}"
103-
>
104-
<el-input class="w-160px" v-model="item.value" placeholder="请求返回字段" />
105-
</el-form-item>
106-
</div>
107-
<div class="mr-1 pt-1 cursor-pointer">
108-
<Icon
109-
icon="ep:delete"
110-
:size="18"
111-
@click="deleteHttpResponseSetting(configForm.httpRequestSetting.response!, index)"
112-
/>
65+
<div v-if="configForm.type === TriggerTypeEnum.HTTP_REQUEST">
66+
<el-form-item label="返回值">
67+
<el-alert
68+
title="通过请求返回值, 可以修改流程表单的值"
69+
type="warning"
70+
show-icon
71+
:closable="false"
72+
/>
73+
</el-form-item>
74+
<el-form-item>
75+
<div
76+
class="flex pt-2"
77+
v-for="(item, index) in configForm.httpRequestSetting.response"
78+
:key="index"
79+
>
80+
<div class="mr-2">
81+
<el-form-item
82+
:prop="`httpRequestSetting.response.${index}.key`"
83+
:rules="{
84+
required: true,
85+
message: '表单字段不能为空',
86+
trigger: 'blur'
87+
}"
88+
>
89+
<el-select class="w-160px!" v-model="item.key" placeholder="请选择表单字段">
90+
<el-option
91+
v-for="(field, fIdx) in formFields"
92+
:key="fIdx"
93+
:label="field.title"
94+
:value="field.field"
95+
:disabled="!field.required"
96+
/>
97+
</el-select>
98+
</el-form-item>
99+
</div>
100+
<div class="mr-2">
101+
<el-form-item
102+
:prop="`httpRequestSetting.response.${index}.value`"
103+
:rules="{
104+
required: true,
105+
message: '请求返回字段不能为空',
106+
trigger: 'blur'
107+
}"
108+
>
109+
<el-input class="w-160px" v-model="item.value" placeholder="请求返回字段" />
110+
</el-form-item>
111+
</div>
112+
<div class="mr-1 pt-1 cursor-pointer">
113+
<Icon
114+
icon="ep:delete"
115+
:size="18"
116+
@click="
117+
deleteHttpResponseSetting(configForm.httpRequestSetting.response!, index)
118+
"
119+
/>
120+
</div>
113121
</div>
114-
</div>
115-
<el-button
116-
type="primary"
117-
text
118-
@click="addHttpResponseSetting(configForm.httpRequestSetting.response!)"
119-
>
120-
<Icon icon="ep:plus" class="mr-5px" />添加一行
121-
</el-button>
122-
</el-form-item>
122+
<el-button
123+
type="primary"
124+
text
125+
@click="addHttpResponseSetting(configForm.httpRequestSetting.response!)"
126+
>
127+
<Icon icon="ep:plus" class="mr-5px" />添加一行
128+
</el-button>
129+
</el-form-item>
130+
</div>
123131
</div>
124132

125133
<!-- 表单数据修改触发器 -->
@@ -385,14 +393,28 @@ let originalSetting: TriggerSetting | undefined
385393
/** 触发器类型改变了 */
386394
const changeTriggerType = () => {
387395
if (configForm.value.type === TriggerTypeEnum.HTTP_REQUEST) {
388-
configForm.value.httpRequestSetting = originalSetting?.httpRequestSetting || {
389-
url: '',
390-
header: [],
391-
body: [],
392-
response: []
393-
}
396+
configForm.value.httpRequestSetting =
397+
originalSetting?.type === TriggerTypeEnum.HTTP_REQUEST && originalSetting.httpRequestSetting
398+
? originalSetting.httpRequestSetting
399+
: {
400+
url: '',
401+
header: [],
402+
body: [],
403+
response: []
404+
}
394405
configForm.value.formSettings = undefined
395-
} else if (configForm.value.type === TriggerTypeEnum.FORM_UPDATE) {
406+
} else if (configForm.value.type === TriggerTypeEnum.ASYNC_HTTP_REQUEST) {
407+
configForm.value.httpRequestSetting =
408+
originalSetting?.type === TriggerTypeEnum.ASYNC_HTTP_REQUEST && originalSetting.httpRequestSetting
409+
? originalSetting.httpRequestSetting
410+
: {
411+
url: '',
412+
header: [],
413+
body: [],
414+
response: []
415+
}
416+
configForm.value.formSettings = undefined
417+
}else if (configForm.value.type === TriggerTypeEnum.FORM_UPDATE) {
396418
configForm.value.formSettings =
397419
originalSetting?.type === TriggerTypeEnum.FORM_UPDATE && originalSetting.formSettings
398420
? originalSetting.formSettings
@@ -405,7 +427,6 @@ const changeTriggerType = () => {
405427
]
406428
configForm.value.httpRequestSetting = undefined
407429
} else if (configForm.value.type === TriggerTypeEnum.FORM_DELETE) {
408-
console.log('originalSetting?.type', originalSetting?.type)
409430
configForm.value.formSettings =
410431
originalSetting?.type === TriggerTypeEnum.FORM_DELETE && originalSetting.formSettings
411432
? originalSetting.formSettings
@@ -531,7 +552,10 @@ const saveConfig = async () => {
531552
/** 获取节点展示内容 */
532553
const getShowText = (): string => {
533554
let showText = ''
534-
if (configForm.value.type === TriggerTypeEnum.HTTP_REQUEST) {
555+
if (
556+
configForm.value.type === TriggerTypeEnum.HTTP_REQUEST ||
557+
configForm.value.type === TriggerTypeEnum.ASYNC_HTTP_REQUEST
558+
) {
535559
showText = `${configForm.value.httpRequestSetting?.url}`
536560
} else if (configForm.value.type === TriggerTypeEnum.FORM_UPDATE) {
537561
for (const [index, setting] of configForm.value.formSettings!.entries()) {
@@ -556,7 +580,7 @@ const getShowText = (): string => {
556580
/** 显示触发器节点配置, 由父组件传过来 */
557581
const showTriggerNodeConfig = (node: SimpleFlowNode) => {
558582
nodeName.value = node.name
559-
originalSetting = node.triggerSetting
583+
originalSetting = node.triggerSetting ? JSON.parse(JSON.stringify(node.triggerSetting)) : {}
560584
if (node.triggerSetting) {
561585
configForm.value = {
562586
type: node.triggerSetting.type,

0 commit comments

Comments
 (0)