【功能新增】Http 请求触发器,增加返回值设置

pull/686/head
jason 2025-01-26 13:14:16 +08:00
parent 5f5ae354d2
commit 475385bd43
4 changed files with 119 additions and 18 deletions

View File

@ -371,13 +371,13 @@ export enum TimeUnitType {
/** /**
* *
*/ */
export type ConditionSetting = { export type ConditionSetting = {
// 条件类型 // 条件类型
conditionType?: ConditionType, conditionType?: ConditionType
// 条件表达式 // 条件表达式
conditionExpression?: string, conditionExpression?: string
// 条件组 // 条件组
conditionGroups?: ConditionGroup, conditionGroups?: ConditionGroup
// 是否默认的条件 // 是否默认的条件
defaultFlow?: boolean defaultFlow?: boolean
} }
@ -726,7 +726,7 @@ export enum TriggerTypeEnum {
/** /**
* HTTP * HTTP
*/ */
HTTP_REQUEST = 1, HTTP_REQUEST = 1
} }
/** /**
@ -739,6 +739,8 @@ export type HttpRequestTriggerSetting = {
header?: HttpRequestParam[] header?: HttpRequestParam[]
// 请求体参数设置 // 请求体参数设置
body?: HttpRequestParam[] body?: HttpRequestParam[]
// 请求响应设置
response?: Record<string, string>[]
} }
export const TRIGGER_TYPES: DictDataVO[] = [ export const TRIGGER_TYPES: DictDataVO[] = [

View File

@ -14,7 +14,8 @@ import {
AssignStartUserHandlerType, AssignStartUserHandlerType,
AssignEmptyHandlerType, AssignEmptyHandlerType,
FieldPermissionType, FieldPermissionType,
HttpRequestParam HttpRequestParam,
ProcessVariableEnum
} from './consts' } from './consts'
import { parseFormFields } from '@/components/FormCreate/src/utils' import { parseFormFields } from '@/components/FormCreate/src/utils'
@ -106,13 +107,28 @@ export function useFormFieldsPermission(defaultPermission: FieldPermissionType)
} }
} }
/** /**
* @description * @description
*/ */
export function useFormFields() { export function useFormFields() {
const formFields = inject<Ref<string[]>>('formFields', ref([])) // 流程表单字段 const formFields = inject<Ref<string[]>>('formFields', ref([])) // 流程表单字段
return parseFormCreateFields(unref(formFields)) return parseFormCreateFields(unref(formFields))
} }
/**
* @description
*/
export function useFormFieldsAndStartUser() {
const injectFormFields = inject<Ref<string[]>>('formFields', ref([])) // 流程表单字段
const formFields = parseFormCreateFields(unref(injectFormFields))
// 添加发起人
formFields.unshift({
field: ProcessVariableEnum.START_USER_ID,
title: '发起人',
required: true
})
return formFields
}
export type UserTaskFormType = { export type UserTaskFormType = {
candidateStrategy: CandidateStrategy candidateStrategy: CandidateStrategy
approveMethod: ApproveMethodType approveMethod: ApproveMethodType

View File

@ -35,6 +35,7 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- HTTP 请求触发器 -->
<div <div
v-if="configForm.type === TriggerTypeEnum.HTTP_REQUEST && configForm.httpRequestSetting" v-if="configForm.type === TriggerTypeEnum.HTTP_REQUEST && configForm.httpRequestSetting"
> >
@ -46,14 +47,79 @@
:closable="false" :closable="false"
/> />
</el-form-item> </el-form-item>
<!-- 请求地址-->
<el-form-item label="请求地址" prop="httpRequestSetting.url"> <el-form-item label="请求地址" prop="httpRequestSetting.url">
<el-input v-model="configForm.httpRequestSetting.url" /> <el-input v-model="configForm.httpRequestSetting.url" />
</el-form-item> </el-form-item>
<!-- 请求头请求体设置-->
<HttpRequestParamSetting <HttpRequestParamSetting
:header="configForm.httpRequestSetting.header" :header="configForm.httpRequestSetting.header"
:body="configForm.httpRequestSetting.body" :body="configForm.httpRequestSetting.body"
:bind="'httpRequestSetting'" :bind="'httpRequestSetting'"
/> />
<!-- 返回值设置-->
<el-form-item label="返回值">
<el-alert
title="通过请求返回值, 可以修改流程表单的值"
type="warning"
show-icon
:closable="false"
/>
</el-form-item>
<el-form-item>
<div
class="flex pt-2"
v-for="(item, index) in configForm.httpRequestSetting.response"
:key="index"
>
<div class="mr-2">
<el-form-item
:prop="`httpRequestSetting.response.${index}.key`"
:rules="{
required: true,
message: '表单字段不能为空',
trigger: 'blur'
}"
>
<el-select class="w-160px!" v-model="item.key" placeholder="请选择表单字段">
<el-option
v-for="(field, fIdx) in formFieldOptions"
:key="fIdx"
:label="field.title"
:value="field.field"
:disabled="!field.required"
/>
</el-select>
</el-form-item>
</div>
<div class="mr-2">
<el-form-item
:prop="`httpRequestSetting.response.${index}.value`"
:rules="{
required: true,
message: '请求返回字段不能为空',
trigger: 'blur'
}"
>
<el-input class="w-160px" v-model="item.value" placeholder="请求返回字段" />
</el-form-item>
</div>
<div class="mr-1 pt-1 cursor-pointer">
<Icon
icon="ep:delete"
:size="18"
@click="deleteHttpResponseSetting(configForm.httpRequestSetting.response!, index)"
/>
</div>
</div>
<el-button
type="primary"
text
@click="addHttpResponseSetting(configForm.httpRequestSetting.response!)"
>
<Icon icon="ep:plus" class="mr-5px" />添加一行
</el-button>
</el-form-item>
</div> </div>
</el-form> </el-form>
</div> </div>
@ -68,7 +134,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { SimpleFlowNode, NodeType, TriggerSetting, TRIGGER_TYPES, TriggerTypeEnum } from '../consts' import { SimpleFlowNode, NodeType, TriggerSetting, TRIGGER_TYPES, TriggerTypeEnum } from '../consts'
import { useWatchNode, useDrawer, useNodeName } from '../node' import { useWatchNode, useDrawer, useNodeName, useFormFields } from '../node'
import HttpRequestParamSetting from './components/HttpRequestParamSetting.vue' import HttpRequestParamSetting from './components/HttpRequestParamSetting.vue'
defineOptions({ defineOptions({
@ -91,9 +157,7 @@ const formRef = ref() // 表单 Ref
// //
const formRules = reactive({ const formRules = reactive({
type: [{ required: true, message: '触发器类型不能为空', trigger: 'change' }], type: [{ required: true, message: '触发器类型不能为空', trigger: 'change' }],
httpRequestSetting: { 'httpRequestSetting.url': [{ required: true, message: '请求地址不能为空', trigger: 'blur' }]
url: [{ required: true, message: '请求地址不能为空', trigger: 'blur' }]
}
}) })
// //
const configForm = ref<TriggerSetting>({ const configForm = ref<TriggerSetting>({
@ -101,9 +165,25 @@ const configForm = ref<TriggerSetting>({
httpRequestSetting: { httpRequestSetting: {
url: '', url: '',
header: [], header: [],
body: [] body: [],
response: []
} }
}) })
//
const formFieldOptions = useFormFields()
/** 添加 HTTP 请求返回值设置项*/
const addHttpResponseSetting = (responseSetting: Record<string, string>[]) => {
responseSetting.push({
key: '',
value: ''
})
}
/** 删除 HTTP 请求返回值设置项 */
const deleteHttpResponseSetting = (responseSetting: Record<string, string>[], index: number) => {
responseSetting.splice(index, 1)
}
/** 保存配置 */ /** 保存配置 */
const saveConfig = async () => { const saveConfig = async () => {

View File

@ -142,7 +142,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { HttpRequestParam, BPM_HTTP_REQUEST_PARAM_TYPES, BpmHttpRequestParamTypeEnum } from '../../consts' import { HttpRequestParam, BPM_HTTP_REQUEST_PARAM_TYPES, BpmHttpRequestParamTypeEnum } from '../../consts'
import { useFormFields } from '../../node' import { useFormFieldsAndStartUser } from '../../node'
defineOptions({ defineOptions({
name: 'HttpRequestParamSetting' name: 'HttpRequestParamSetting'
}) })
@ -164,16 +164,19 @@ const props = defineProps({
} }
}) })
const formFieldOptions = useFormFields() //
const formFieldOptions = useFormFieldsAndStartUser()
const addHttpRequestParam = (arr: ListenerParam[]) => { /** 添加请求配置项 */
const addHttpRequestParam = (arr: HttpRequestParam[]) => {
arr.push({ arr.push({
key: '', key: '',
type: ListenerParamTypeEnum.FIXED_VALUE, type: BpmHttpRequestParamTypeEnum.FIXED_VALUE,
value: '' value: ''
}) })
} }
const deleteHttpRequestParam = (arr: ListenerParam[], index: number) => {
/** 删除请求配置项 */
const deleteHttpRequestParam = (arr: HttpRequestParam[], index: number) => {
arr.splice(index, 1) arr.splice(index, 1)
} }
</script> </script>