|
|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import styles from '@/pages/flowEditor/node/style/base.module.less';
|
|
|
|
|
import { Handle, Position, useStore } from '@xyflow/react';
|
|
|
|
|
import { Divider } from '@arco-design/web-react';
|
|
|
|
|
|
|
|
|
|
interface NodeContentData {
|
|
|
|
|
parameters?: {
|
|
|
|
|
inputs?: any[];
|
|
|
|
|
outputs?: any[];
|
|
|
|
|
dataIns?: any[];
|
|
|
|
|
dataOuts?: any[];
|
|
|
|
|
apiIns?: any[];
|
|
|
|
|
apiOuts?: any[];
|
|
|
|
|
};
|
|
|
|
|
showFooter?: boolean;
|
|
|
|
|
type?: string;
|
|
|
|
|
@ -15,31 +16,54 @@ interface NodeContentData {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 渲染特殊节点(开始/结束节点)的句柄
|
|
|
|
|
const renderSpecialNodeHandles = (isStartNode: boolean, isEndNode: boolean, inputs: any[], outputs: any[]) => {
|
|
|
|
|
const renderSpecialNodeHandles = (isStartNode: boolean, isEndNode: boolean, dataIns: any[], dataOuts: any[], apiIns: any[], apiOuts: any[]) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Handle
|
|
|
|
|
type={isStartNode ? 'source' : 'target'}
|
|
|
|
|
position={isStartNode ? Position.Right : Position.Left}
|
|
|
|
|
id={isStartNode ? 'start-source' : 'end-target'}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: '40px',
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
{isStartNode ?
|
|
|
|
|
apiOuts.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`start-output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={apiOuts[index].name || `start-output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: `${40 + index * 20}px`,
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
:
|
|
|
|
|
apiIns.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`end-input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={apiIns[index].name || `end-input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: `${40 + index * 20}px`,
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{/* 为特殊节点的参数也添加句柄 */}
|
|
|
|
|
{isStartNode && outputs.map((_, index) => (
|
|
|
|
|
{isStartNode && dataOuts.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={outputs[index].name || `output-${index}`}
|
|
|
|
|
id={dataOuts[index].name || `output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${60 + index * 20}px`,
|
|
|
|
|
@ -52,12 +76,12 @@ const renderSpecialNodeHandles = (isStartNode: boolean, isEndNode: boolean, inpu
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{isEndNode && inputs.map((_, index) => (
|
|
|
|
|
{isEndNode && dataIns.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={inputs[index].name || `input-${index}`}
|
|
|
|
|
id={dataIns[index].name || `input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${60 + index * 20}px`,
|
|
|
|
|
@ -74,45 +98,51 @@ const renderSpecialNodeHandles = (isStartNode: boolean, isEndNode: boolean, inpu
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 渲染普通节点的句柄
|
|
|
|
|
const renderRegularNodeHandles = (inputs: any[], outputs: any[]) => {
|
|
|
|
|
const renderRegularNodeHandles = (dataIns: any[], dataOuts: any[], apiIns: any[], apiOuts: any[]) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Handle
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id="start-source"
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: '40px',
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
<Handle
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id="end-target"
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: '40px',
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
{apiOuts.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={apiOuts[index].name || `output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: `${40 + index * 20}px`,
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
{apiIns.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={apiIns[index].name || `input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#2290f6',
|
|
|
|
|
top: `${40 + index * 20}px`,
|
|
|
|
|
width: '8px',
|
|
|
|
|
height: '8px',
|
|
|
|
|
border: '2px solid #fff',
|
|
|
|
|
boxShadow: '0 0 4px rgba(0,0,0,0.2)'
|
|
|
|
|
}}
|
|
|
|
|
className="node-handle"
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{/* 输入参数连接端点 */}
|
|
|
|
|
{inputs.map((_, index) => (
|
|
|
|
|
{dataIns.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={inputs[index].name || `input-${index}`}
|
|
|
|
|
id={dataIns[index].name || `input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${40 + (index + 1) * 20}px`,
|
|
|
|
|
@ -126,12 +156,12 @@ const renderRegularNodeHandles = (inputs: any[], outputs: any[]) => {
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{/* 输出参数连接端点 */}
|
|
|
|
|
{outputs.map((_, index) => (
|
|
|
|
|
{dataOuts.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={outputs[index].name || `output-${index}`}
|
|
|
|
|
id={dataOuts[index].name || `output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${40 + (index + 1) * 20}px`,
|
|
|
|
|
@ -148,8 +178,10 @@ const renderRegularNodeHandles = (inputs: any[], outputs: any[]) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const NodeContent = ({ data }: { data: NodeContentData }) => {
|
|
|
|
|
const inputs = data.parameters?.inputs || [];
|
|
|
|
|
const outputs = data.parameters?.outputs || [];
|
|
|
|
|
const apiIns = data.parameters?.apiIns || [];
|
|
|
|
|
const apiOuts = data.parameters?.apiOuts || [];
|
|
|
|
|
const dataIns = data.parameters?.dataIns || [];
|
|
|
|
|
const dataOuts = data.parameters?.dataOuts || [];
|
|
|
|
|
const showFooter = data.showFooter || false;
|
|
|
|
|
|
|
|
|
|
// 判断节点类型
|
|
|
|
|
@ -161,9 +193,9 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
|
|
|
|
|
<>
|
|
|
|
|
{/*content栏*/}
|
|
|
|
|
<div className={styles['node-content']}>
|
|
|
|
|
{inputs.length > 0 && !isStartNode && (
|
|
|
|
|
{dataIns.length > 0 && !isStartNode && (
|
|
|
|
|
<div className={styles['node-inputs']}>
|
|
|
|
|
{inputs.map((input, index) => (
|
|
|
|
|
{dataIns.map((input, index) => (
|
|
|
|
|
<div key={`input-${index}`} className={styles['node-input-label']}>
|
|
|
|
|
{input.name || `输入${index + 1}`}
|
|
|
|
|
</div>
|
|
|
|
|
@ -171,9 +203,9 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{outputs.length > 0 && !isEndNode && (
|
|
|
|
|
{dataOuts.length > 0 && !isEndNode && (
|
|
|
|
|
<div className={styles['node-outputs']}>
|
|
|
|
|
{outputs.map((output, index) => (
|
|
|
|
|
{dataOuts.map((output, index) => (
|
|
|
|
|
<div key={`output-${index}`} style={{ fontSize: '12px', padding: '2px 0' }}>
|
|
|
|
|
{output.name || `输出${index + 1}`}
|
|
|
|
|
</div>
|
|
|
|
|
@ -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)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|