feat(web): 完成前序节点输出变量注入

This commit is contained in:
v-zhangjc9
2025-07-07 19:50:22 +08:00
parent f523fc7638
commit 3afdff0a05
5 changed files with 82 additions and 33 deletions

View File

@@ -1,27 +1,33 @@
import {CopyFilled, DeleteFilled, EditFilled} from '@ant-design/icons'
import {
type Edge,
Handle,
type HandleProps,
type Node,
type NodeProps,
Position,
useNodeConnections,
} from '@xyflow/react'
import {Handle, type HandleProps, type Node, type NodeProps, Position, useNodeConnections} from '@xyflow/react'
import type {Schema} from 'amis'
import {Button, Card} from 'antd'
import {isEmpty, isEqual, isNil} from 'licia'
import {has, isEmpty, isEqual, isNil} from 'licia'
import {type JSX} from 'react'
import styled from 'styled-components'
import {horizontalFormOptions} from '../../../util/amis.tsx'
import {useContextStore} from '../store/ContextStore.ts'
import {useDataStore} from '../store/DataStore.ts'
import {useFlowStore} from '../store/FlowStore.ts'
export type AmisNodeType = 'normal' | 'start' | 'end'
export function inputsFormColumns(props: ColumnsSchemaProps): Schema[] {
console.log('props', props)
let incomers = props.getAllIncomerNodeById(props.nodeId)
let groups = []
for (const incomer of incomers) {
let data = props.getNodeDataById(incomer.id)
if (has(data, 'outputs')) {
let outputs = data?.outputs ?? []
groups.push({
label: incomer.id,
children: Object.keys(outputs).map(key => ({
key: `${incomer.id}.${key}`,
label: key,
})),
})
}
}
return [
{
type: 'input-kvs',
@@ -40,7 +46,17 @@ export function inputsFormColumns(props: ColumnsSchemaProps): Schema[] {
name: 'type',
label: '变量',
required: true,
options: [],
selectMode: 'group',
options: [
{
label: '流程参数',
children: Object.keys(props.inputSchema).map(key => ({
label: props.inputSchema[key]?.label ?? '',
value: key,
})),
},
...groups,
],
},
],
},
@@ -108,10 +124,11 @@ export const LimitHandler = (props: HandleProps & { limit: number }) => {
type ColumnsSchemaProps = {
// getInputSchema: () => Record<string, Record<string, any>>,
inputSchema: Record<string, Record<string, any>>,
nodeId: string,
nodeData: any,
getNodes: () => Node[],
getEdges: () => Edge[],
getNodeDataById: (id: string) => any,
getAllIncomerNodeById: (id: string) => Node[],
}
type AmisNodeProps = {
@@ -145,10 +162,10 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
}) => {
const {
removeNode,
getNodes,
getEdges,
getAllIncomerNodeById,
} = useFlowStore()
const {getDataById} = useDataStore()
const {inputSchema} = useContextStore()
const {id, data} = nodeProps
const {editNode} = data
@@ -199,14 +216,11 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
},
...(
columnSchema?.({
// @ts-ignore
// getInputSchema,
inputSchema,
nodeId: id,
nodeData,
// @ts-ignore
getNodes,
// @ts-ignore
getEdges,
getNodeDataById: getDataById,
getAllIncomerNodeById,
}) ?? []
),
],