fix: 修复HTTP任务中请求头不能使用EL表达式的问题

pull/837/head
zhanglc 2025-11-18 11:40:58 +08:00
parent e3e61359f9
commit c50e0dee8c
1 changed files with 38 additions and 13 deletions

View File

@ -139,22 +139,32 @@ const httpInitializing = ref(false)
const bpmnInstances = () => (window as any)?.bpmnInstances const bpmnInstances = () => (window as any)?.bpmnInstances
//
const isExpression = (value: string): boolean => {
if (!value) return false
// ${...} #{...}
return /\${[^}]+}/.test(value) || /#{[^}]+}/.test(value)
}
const collectHttpExtensionInfo = () => { const collectHttpExtensionInfo = () => {
const businessObject = bpmnElement.value?.businessObject const businessObject = bpmnElement.value?.businessObject
const extensionElements = businessObject?.extensionElements const extensionElements = businessObject?.extensionElements
const httpFields = new Map<string, string>() const httpFields = new Map<string, string>()
const httpFieldTypes = new Map<string, 'string' | 'expression'>()
const otherExtensions: any[] = [] const otherExtensions: any[] = []
extensionElements?.values?.forEach((item: any) => { extensionElements?.values?.forEach((item: any) => {
if (item?.$type === flowableFieldType && HTTP_FIELD_NAMES.includes(item.name)) { if (item?.$type === flowableFieldType && HTTP_FIELD_NAMES.includes(item.name)) {
const value = item.string ?? item.stringValue ?? item.expression ?? '' const value = item.string ?? item.stringValue ?? item.expression ?? ''
const fieldType = item.expression ? 'expression' : 'string'
httpFields.set(item.name, value) httpFields.set(item.name, value)
httpFieldTypes.set(item.name, fieldType)
} else { } else {
otherExtensions.push(item) otherExtensions.push(item)
} }
}) })
return { httpFields, otherExtensions } return { httpFields, httpFieldTypes, otherExtensions }
} }
const resetHttpDefaults = () => { const resetHttpDefaults = () => {
@ -168,7 +178,7 @@ const resetHttpDefaults = () => {
const resetHttpForm = () => { const resetHttpForm = () => {
httpInitializing.value = true httpInitializing.value = true
const { httpFields } = collectHttpExtensionInfo() const { httpFields } = collectHttpExtensionInfo()
const nextForm: Record<string, any> = { ...DEFAULT_HTTP_FORM } const nextForm = { ...DEFAULT_HTTP_FORM }
HTTP_FIELD_NAMES.forEach((name) => { HTTP_FIELD_NAMES.forEach((name) => {
const stored = httpFields.get(name) const stored = httpFields.get(name)
@ -228,7 +238,11 @@ const updateHttpExtensions = (force = false) => {
return return
} }
const { httpFields: existingFields, otherExtensions } = collectHttpExtensionInfo() const {
httpFields: existingFields,
httpFieldTypes: existingTypes,
otherExtensions
} = collectHttpExtensionInfo()
const desiredEntries: [string, string][] = [] const desiredEntries: [string, string][] = []
HTTP_FIELD_NAMES.forEach((name) => { HTTP_FIELD_NAMES.forEach((name) => {
@ -246,21 +260,32 @@ const updateHttpExtensions = (force = false) => {
desiredEntries.push([name, persisted]) desiredEntries.push([name, persisted])
}) })
if ( // string vs expression
!force && if (!force && desiredEntries.length === existingFields.size) {
desiredEntries.length === existingFields.size && let noChange = true
desiredEntries.every(([name, value]) => existingFields.get(name) === value) for (const [name, value] of desiredEntries) {
) { const existingValue = existingFields.get(name)
return const existingType = existingTypes.get(name)
const currentType = isExpression(value) ? 'expression' : 'string'
if (existingValue !== value || existingType !== currentType) {
noChange = false
break
}
}
if (noChange) {
return
}
} }
const moddle = bpmnInstances().moddle const moddle = bpmnInstances().moddle
const httpFieldElements = desiredEntries.map(([name, value]) => const httpFieldElements = desiredEntries.map(([name, value]) => {
moddle.create(flowableFieldType, { // 使 string expression
const isExpr = isExpression(value)
return moddle.create(flowableFieldType, {
name, name,
string: value ...(isExpr ? { expression: value } : { string: value })
}) })
) })
updateElementExtensions(bpmnElement.value, [...otherExtensions, ...httpFieldElements]) updateElementExtensions(bpmnElement.value, [...otherExtensions, ...httpFieldElements])
} }