fix: 修复HTTP任务中请求头不能使用EL表达式的问题
parent
e3e61359f9
commit
c50e0dee8c
|
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue