feat(web): 节点描述和名称直接放在节点数据中

This commit is contained in:
v-zhangjc9
2025-07-10 16:34:29 +08:00
parent 333da7ef88
commit fad190567b
7 changed files with 58 additions and 36 deletions

View File

@@ -42,7 +42,7 @@ export function inputsFormColumns(
data: any,
): Schema[] {
let inputSchemaVariables: InputFormOptions[] = Object.keys(inputSchema).map(key => ({
label: inputSchema[key]?.label ?? '',
label: `${key} (${inputSchema[key]?.label ?? ''})`,
value: key,
}))
@@ -50,10 +50,14 @@ export function inputsFormColumns(
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: incomerId,
group: group,
variables: Object.keys(outputs).map(key => ({
value: `${incomerId}.${key}`,
label: key,
@@ -151,8 +155,6 @@ export function outputsFormColumns(editable: boolean = false, required: boolean
type AmisNodeProps = {
nodeProps: NodeProps
defaultNodeName: String
defaultNodeDescription?: String
extraNodeDescription?: JSX.Element
handler: JSX.Element
columnSchema?: () => Schema[]
@@ -187,8 +189,6 @@ export const NormalNodeHandler = () => {
const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
nodeProps,
defaultNodeName,
defaultNodeDescription,
extraNodeDescription,
handler,
columnSchema,
@@ -198,8 +198,8 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
const {id} = nodeProps
// @ts-ignore
const nodeData = getDataById(id)
const nodeName = isEmpty(nodeData?.node?.name) ? defaultNodeName : nodeData.node.name
const nodeDescription = isEmpty(nodeData?.node?.description) ? defaultNodeDescription : nodeData.node?.description
const nodeName = nodeData?.node?.name ?? ''
const nodeDescription = nodeData?.node?.description ?? ''
const [editDrawerOpen, setEditDrawerOpen] = useState(false)
const [editDrawerForm, setEditDrawerForm] = useState<JSX.Element>(<></>)

View File

@@ -66,8 +66,6 @@ const CodeNode = (props: NodeProps) => {
return (
<AmisNode
nodeProps={props}
defaultNodeName="代码执行"
defaultNodeDescription="执行自定义的处理代码"
columnSchema={columnsSchema}
handler={<NormalNodeHandler/>}
/>

View File

@@ -80,8 +80,6 @@ const KnowledgeNode = (props: NodeProps) => {
return (
<AmisNode
nodeProps={props}
defaultNodeName="知识库"
defaultNodeDescription="查询知识库获取外部知识"
columnSchema={columnsSchema}
handler={<NormalNodeHandler/>}
/>

View File

@@ -58,8 +58,6 @@ const LlmNode = (props: NodeProps) => {
return (
<AmisNode
nodeProps={props}
defaultNodeName="大模型"
defaultNodeDescription="使用大模型对话"
extraNodeDescription={
nodeData?.model
? <div className="mt-2 flex justify-between">

View File

@@ -1,15 +1,22 @@
import type {NodeProps} from '@xyflow/react'
import React, {useCallback} from 'react'
import AmisNode, {EndNodeHandler, outputsFormColumns} from './AmisNode.tsx'
import {useContextStore} from '../store/ContextStore.ts'
import {useDataStore} from '../store/DataStore.ts'
import {useFlowStore} from '../store/FlowStore.ts'
import AmisNode, {EndNodeHandler, inputsFormColumns} from './AmisNode.tsx'
const OutputNode = (props: NodeProps) => {
const columnsSchema = useCallback(() => outputsFormColumns(true), [props.id])
const {getNodes, getEdges} = useFlowStore()
const {getData} = useDataStore()
const {getInputSchema} = useContextStore()
const columnsSchema = useCallback(
() => inputsFormColumns(props.id, getInputSchema(), getNodes(), getEdges(), getData()),
[props.id],
)
return (
<AmisNode
nodeProps={props}
defaultNodeName="输出节点"
defaultNodeDescription="定义输出变量"
columnSchema={columnsSchema}
handler={<EndNodeHandler/>}
/>

View File

@@ -19,8 +19,6 @@ const SwitchNode = (props: NodeProps) => {
return (
<AmisNode
nodeProps={props}
defaultNodeName="分支节点"
defaultNodeDescription="根据不同的情况前往不同的分支"
extraNodeDescription={
<div className="mt-2">
{cases.map(item => (