feat(web): 入参增加类型
This commit is contained in:
@@ -3,8 +3,9 @@ import type {Option} from 'amis/lib/Schema'
|
||||
import {find, has, isEqual, max, min, unique} from 'licia'
|
||||
import {type DependencyList, type MouseEvent as ReactMouseEvent, useCallback, useRef} from 'react'
|
||||
import Queue from 'yocto-queue'
|
||||
import {originTypeMap} from '../../pages/ai/task/InputSchema.tsx'
|
||||
import {useFlowStore} from './store/FlowStore.ts'
|
||||
import type {OutputVariable} from './types.ts'
|
||||
import {type OutputVariable} from './types.ts'
|
||||
|
||||
export const getAllIncomerNodeById: (id: string, nodes: Node[], edges: Edge[]) => string[] = (id, nodes, edges) => {
|
||||
let queue = new Queue<Node>()
|
||||
@@ -24,6 +25,7 @@ export const getAllIncomerNodeOutputVariables: (id: string, inputSchema: Record<
|
||||
let inputSchemaVariables: OutputVariable[] = Object.keys(inputSchema).map(key => ({
|
||||
group: '流程入参',
|
||||
name: `${key}${inputSchema[key]?.label ? ` (${inputSchema[key].label})` : ''}`,
|
||||
type: originTypeMap[inputSchema[key]?.type ?? ''],
|
||||
variable: key,
|
||||
}))
|
||||
|
||||
@@ -53,6 +55,7 @@ export const getAllIncomerNodeOutputVariables: (id: string, inputSchema: Record<
|
||||
incomerVariables.push({
|
||||
group: group,
|
||||
name: key,
|
||||
type: outputs[key].type,
|
||||
variable: `${incomerId}.${key}`,
|
||||
})
|
||||
}
|
||||
@@ -65,13 +68,15 @@ export const getAllIncomerNodeOutputVariables: (id: string, inputSchema: Record<
|
||||
{
|
||||
group: '循环入参',
|
||||
name: 'loopIndex (当前迭代索引)',
|
||||
type: 'number',
|
||||
variable: 'loopIndex',
|
||||
},
|
||||
} as OutputVariable,
|
||||
{
|
||||
group: '循环入参',
|
||||
name: 'loopItem (当前迭代对象)',
|
||||
type: 'object',
|
||||
variable: 'loopItem',
|
||||
},
|
||||
} as OutputVariable,
|
||||
] : []),
|
||||
...incomerVariables,
|
||||
]
|
||||
@@ -95,6 +100,25 @@ export const generateAllIncomerOutputVariablesFormOptions: (id: string, inputSch
|
||||
}))
|
||||
}
|
||||
|
||||
export const generateAllIncomerOutputVariablesConditions: (id: string, inputSchema: Record<string, Record<string, any>>, nodes: Node[], edges: Edge[], data: any) => Option[] = (id, inputSchema, nodes, edges, data) => {
|
||||
let optionMap: Record<string, Option[]> = {}
|
||||
for (const item of getAllIncomerNodeOutputVariables(id, inputSchema, nodes, edges, data)) {
|
||||
if (!optionMap[item.group]) {
|
||||
optionMap[item.group] = []
|
||||
}
|
||||
optionMap[item.group].push({
|
||||
label: item.name,
|
||||
type: item.type,
|
||||
name: item.variable,
|
||||
})
|
||||
}
|
||||
return Object.keys(optionMap)
|
||||
.map(key => ({
|
||||
label: key,
|
||||
children: optionMap[key],
|
||||
}))
|
||||
}
|
||||
|
||||
// 处理循环节点的边界问题
|
||||
export const useNodeDrag = (deps: DependencyList) => {
|
||||
const currentPosition = useRef({x: 0, y: 0} as { x: number, y: number })
|
||||
|
||||
@@ -8,6 +8,7 @@ import {amisRender, commonInfo, horizontalFormOptions} from '../../../util/amis.
|
||||
import {generateAllIncomerOutputVariablesFormOptions} from '../Helper.tsx'
|
||||
import {useDataStore} from '../store/DataStore.ts'
|
||||
import {useFlowStore} from '../store/FlowStore.ts'
|
||||
import {OutputVariableTypeMap} from '../types.ts'
|
||||
|
||||
export function inputsFormColumns(
|
||||
nodeId: string,
|
||||
@@ -70,24 +71,11 @@ export function outputsFormColumns(editable: boolean = false, required: boolean
|
||||
label: '参数',
|
||||
required: true,
|
||||
selectFirst: true,
|
||||
options: [
|
||||
{
|
||||
label: '文本',
|
||||
value: 'string',
|
||||
},
|
||||
{
|
||||
label: '数字',
|
||||
value: 'number',
|
||||
},
|
||||
{
|
||||
label: '文本数组',
|
||||
value: 'array-string',
|
||||
},
|
||||
{
|
||||
label: '对象数组',
|
||||
value: 'array-object',
|
||||
},
|
||||
],
|
||||
options: Object.keys(OutputVariableTypeMap).map(key => ({
|
||||
// @ts-ignore
|
||||
label: OutputVariableTypeMap[key],
|
||||
value: key,
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import {Handle, type NodeProps, Position} from '@xyflow/react'
|
||||
import {Tag} from 'antd'
|
||||
import React from 'react'
|
||||
import React, {useCallback} from 'react'
|
||||
import {generateAllIncomerOutputVariablesConditions} from '../Helper.tsx'
|
||||
import {useContextStore} from '../store/ContextStore.ts'
|
||||
import {useDataStore} from '../store/DataStore.ts'
|
||||
import {useFlowStore} from '../store/FlowStore.ts'
|
||||
import AmisNode, {nodeClassName} from './AmisNode.tsx'
|
||||
|
||||
const cases = [
|
||||
@@ -16,6 +20,25 @@ const cases = [
|
||||
]
|
||||
|
||||
const SwitchNode = (props: NodeProps) => {
|
||||
const {getNodes, getEdges} = useFlowStore()
|
||||
const {getData} = useDataStore()
|
||||
const {getInputSchema} = useContextStore()
|
||||
|
||||
const columnsSchema = useCallback(() => [
|
||||
{
|
||||
type: 'condition-builder',
|
||||
name: 'condition',
|
||||
label: '判断条件',
|
||||
fields: generateAllIncomerOutputVariablesConditions(
|
||||
props.id,
|
||||
getInputSchema(),
|
||||
getNodes(),
|
||||
getEdges(),
|
||||
getData(),
|
||||
),
|
||||
},
|
||||
], [props.id])
|
||||
|
||||
return (
|
||||
<AmisNode
|
||||
className={nodeClassName('switch')}
|
||||
@@ -29,6 +52,7 @@ const SwitchNode = (props: NodeProps) => {
|
||||
))}
|
||||
</div>
|
||||
}
|
||||
columnSchema={columnsSchema}
|
||||
handler={
|
||||
<>
|
||||
<Handle type="target" position={Position.Left}/>
|
||||
|
||||
@@ -29,6 +29,17 @@ export type FlowEditorProps = {
|
||||
onGraphDataChange: (graphData: GraphData) => void,
|
||||
}
|
||||
|
||||
export type OutputVariableType = 'text' | 'boolean' | 'number' | 'object' | 'array-text' | 'array-object'
|
||||
|
||||
export const OutputVariableTypeMap: Record<OutputVariableType, string> = {
|
||||
'text': '文本',
|
||||
'boolean': '布尔值',
|
||||
'number': '数字',
|
||||
'object': '对象',
|
||||
'array-text': '文本数组',
|
||||
'array-object': '对象数组',
|
||||
}
|
||||
|
||||
export type NodeDefine = {
|
||||
key: string,
|
||||
group: string,
|
||||
@@ -42,5 +53,6 @@ export type NodeDefine = {
|
||||
export type OutputVariable = {
|
||||
group: string,
|
||||
name: string | undefined,
|
||||
type: OutputVariableType,
|
||||
variable: string,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user