- {inputs.length > 0 && !isStartNode && (
+ {dataIns.length > 0 && !isStartNode && (
- {inputs.map((input, index) => (
+ {dataIns.map((input, index) => (
{input.name || `输入${index + 1}`}
@@ -171,9 +203,9 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
)}
- {outputs.length > 0 && !isEndNode && (
+ {dataOuts.length > 0 && !isEndNode && (
- {outputs.map((output, index) => (
+ {dataOuts.map((output, index) => (
{output.name || `输出${index + 1}`}
@@ -191,8 +223,8 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
{/* 根据节点类型渲染不同的句柄 */}
{isSpecialNode
- ? renderSpecialNodeHandles(isStartNode, isEndNode, inputs, outputs)
- : renderRegularNodeHandles(inputs, outputs)}
+ ? renderSpecialNodeHandles(isStartNode, isEndNode, dataIns, dataOuts, apiIns, apiOuts)
+ : renderRegularNodeHandles(dataIns, dataOuts, apiIns, apiOuts)}
>
);
};
diff --git a/src/pages/flowEditor/index.tsx b/src/pages/flowEditor/index.tsx
index 5f4bed4..19fb7fd 100644
--- a/src/pages/flowEditor/index.tsx
+++ b/src/pages/flowEditor/index.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useCallback, useRef } from 'react';
+import React, { useState, useCallback, useRef, useEffect } from 'react';
import {
ReactFlow,
applyNodeChanges,
@@ -12,7 +12,6 @@ import {
useReactFlow,
NodeTypes,
EdgeTypes,
- Panel,
SelectionMode
} from '@xyflow/react';
import '@xyflow/react/dist/style.css';
@@ -23,7 +22,7 @@ import DraggableNode from './node/draggableNode/DraggableNode';
import BasicNode from './node/basicNode/BasicNode';
import SideBar from './sideBar/sideBar';
import { convertFlowData } from '@/utils/convertFlowData';
-import { exampleFlowData } from '@/pages/flowEditor/test/exampleFlowData';
+import { exampleFlowData, mineList } from '@/pages/flowEditor/test/exampleFlowData';
import CustomEdge from './components/customEdge';
const nodeTypes: NodeTypes = {
@@ -38,14 +37,6 @@ const edgeTypes: EdgeTypes = {
custom: CustomEdge
};
-const { nodes: convertedNodes, edges: convertedEdges } = convertFlowData(exampleFlowData);
-
-// 为所有边添加类型
-const initialEdges: Edge[] = convertedEdges.map(edge => ({
- ...edge,
- type: 'custom'
-}));
-
const FlowEditorWithProvider: React.FC = () => {
return (
@@ -58,8 +49,8 @@ const FlowEditorWithProvider: React.FC = () => {
};
const FlowEditor: React.FC = () => {
- const [nodes, setNodes] = useState
(convertedNodes);
- const [edges, setEdges] = useState(initialEdges);
+ const [nodes, setNodes] = useState([]);
+ const [edges, setEdges] = useState([]);
const reactFlowInstance = useReactFlow();
const reactFlowWrapper = useRef(null);
@@ -109,6 +100,17 @@ const FlowEditor: React.FC = () => {
[reactFlowInstance]
);
+ useEffect(() => {
+ const { nodes: convertedNodes, edges: convertedEdges } = convertFlowData(exampleFlowData);
+ // 为所有边添加类型
+ const initialEdges: Edge[] = convertedEdges.map(edge => ({
+ ...edge,
+ type: 'custom'
+ }));
+ setNodes(convertedNodes);
+ setEdges(initialEdges);
+ }, []);
+
return (
{
data: {
title: nodeConfig.nodeName || nodeConfig.nodeId,
parameters: {
- inputs: nodeConfig.dataIns?.map((input: any) => ({
+ apiIns: [{
+ name: 'start',
+ desc: '',
+ dataType: '',
+ defaultValue: ''
+ }],
+ apiOuts: [{
+ name: nodeConfig.nodeId === 'end' ? 'end' : 'done',
+ desc: '',
+ dataType: '',
+ defaultValue: ''
+ }],
+ dataIns: nodeConfig.dataIns?.map((input: any) => ({
name: input.id,
desc: input.desc,
dataType: input.dataType,
defaultValue: input.defaultValue
})) || [],
- outputs: nodeConfig.dataOuts?.map((output: any) => ({
+ dataOuts: nodeConfig.dataOuts?.map((output: any) => ({
name: output.id,
desc: output.desc,
dataType: output.dataType,