feat(web): 增加模板节点

This commit is contained in:
v-zhangjc9
2025-07-12 22:55:19 +08:00
parent 02b2d44ccc
commit b0d41e0d88
5 changed files with 184 additions and 99 deletions

View File

@@ -1,6 +1,8 @@
import {type Edge, getIncomers, type Node} from '@xyflow/react'
import {find, has, isEqual, unique} from 'licia'
import type {Option} from 'amis/lib/Schema'
import {find, has, isEmpty, isEqual, unique} from 'licia'
import Queue from 'yocto-queue'
import type {InputFormOptions, InputFormOptionsGroup} from './types.ts'
export const getAllIncomerNodeById: (id: string, nodes: Node[], edges: Edge[]) => string[] = (id, nodes, edges) => {
let queue = new Queue<Node>()
@@ -36,3 +38,47 @@ export const getAllIncomerNodeOutputVariables: (id: string, nodes: Node[], edges
}
return incomerVariables
}
export const generateAllIncomerOutputVariablesFormOptions: (id: string, inputSchema: Record<string, Record<string, any>>, nodes: Node[], edges: Edge[], data: any) => Option[] = (id, inputSchema, nodes, edges, data) => {
let inputSchemaVariables: InputFormOptions[] = Object.keys(inputSchema).map(key => ({
label: `${key} (${inputSchema[key]?.label ?? ''})`,
value: key,
}))
let incomerIds = getAllIncomerNodeById(id, nodes, edges)
let incomerVariables: InputFormOptionsGroup[] = []
for (const incomerId of incomerIds) {
let nodeData = data[incomerId] ?? {}
let group = incomerId
if (has(nodeData, 'node') && has(nodeData.node, 'name')) {
group = `${nodeData.node.name} ${incomerId}`
}
if (has(nodeData, 'outputs')) {
let outputs = nodeData?.outputs ?? []
incomerVariables.push({
group: group,
variables: Object.keys(outputs).map(key => ({
value: `${incomerId}.${key}`,
label: key,
})),
})
}
}
let inputVariables = [
...(isEmpty(inputSchemaVariables) ? [] : [
{
group: '流程入参',
variables: inputSchemaVariables,
},
]),
...incomerVariables,
]
return [
...inputVariables.map(item => ({
label: item.group,
children: item.variables,
})),
]
}