|
|
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
|
|
|
|
import styles from '@/pages/flowEditor/node/style/base.module.less';
|
|
|
|
|
import { Handle, Position } from '@xyflow/react';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface NodeContentData {
|
|
|
|
|
parameters?: {
|
|
|
|
|
inputs?: any[];
|
|
|
|
|
@ -18,11 +17,17 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
|
|
|
|
|
const inputs = data.parameters?.inputs || [];
|
|
|
|
|
const outputs = data.parameters?.outputs || [];
|
|
|
|
|
const showFooter = data.showFooter || false;
|
|
|
|
|
|
|
|
|
|
// 判断节点类型
|
|
|
|
|
const isStartNode = data.type === 'start';
|
|
|
|
|
const isEndNode = data.type === 'end';
|
|
|
|
|
const isSpecialNode = isStartNode || isEndNode;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/*content栏*/}
|
|
|
|
|
<div className={styles['node-content']}>
|
|
|
|
|
{inputs.length > 0 && (
|
|
|
|
|
{inputs.length > 0 && !isStartNode && (
|
|
|
|
|
<div className={styles['node-inputs']}>
|
|
|
|
|
{inputs.map((input, index) => (
|
|
|
|
|
<div key={`input-${index}`} className={styles['node-input-label']}>
|
|
|
|
|
@ -32,7 +37,7 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{outputs.length > 0 && (
|
|
|
|
|
{outputs.length > 0 && !isEndNode && (
|
|
|
|
|
<div className={styles['node-outputs']}>
|
|
|
|
|
{outputs.map((output, index) => (
|
|
|
|
|
<div key={`output-${index}`} style={{ fontSize: '12px', padding: '2px 0' }}>
|
|
|
|
|
@ -50,45 +55,78 @@ const NodeContent = ({ data }: { data: NodeContentData }) => {
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* 默认连接端点*/}
|
|
|
|
|
<Handle
|
|
|
|
|
type={data.type === 'start' ? 'source' : 'target'}
|
|
|
|
|
position={data.type === 'start' ? Position.Right : Position.Left}
|
|
|
|
|
id={data.type === 'start' ? 'start-source' : 'end-target'}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: '40px'
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{/* 流程传输(开始/结束)只在一侧显示端点 */}
|
|
|
|
|
{isSpecialNode ? (
|
|
|
|
|
<>
|
|
|
|
|
<Handle
|
|
|
|
|
type={isStartNode ? 'source' : 'target'}
|
|
|
|
|
position={isStartNode ? Position.Right : Position.Left}
|
|
|
|
|
id={isStartNode ? 'start-source' : 'end-target'}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: '40px'
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/*输入参数连接端点*/}
|
|
|
|
|
{inputs.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={`input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${60 + index * 20}px`
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
{/* 为流程传输的参数也添加句柄 */}
|
|
|
|
|
{isStartNode && outputs.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={outputs[index].name || `output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${60 + index * 20}px`
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{/*输出参数连接端点*/}
|
|
|
|
|
{outputs.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={`output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
// top: `${80 + inputs.length * 20 + index * 20}px`
|
|
|
|
|
top: `${60 + index * 20}px`
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
{isEndNode && inputs.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={inputs[index].name || `input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${60 + index * 20}px`
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
/* 普通节点可以在两侧显示多个端点 */
|
|
|
|
|
<>
|
|
|
|
|
{/* 输入参数连接端点 */}
|
|
|
|
|
{inputs.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`input-handle-${index}`}
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={inputs[index].name || `input-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${40 + index * 20}px`
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{/* 输出参数连接端点 */}
|
|
|
|
|
{outputs.map((_, index) => (
|
|
|
|
|
<Handle
|
|
|
|
|
key={`output-handle-${index}`}
|
|
|
|
|
type="source"
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
id={outputs[index].name || `output-${index}`}
|
|
|
|
|
style={{
|
|
|
|
|
background: '#555',
|
|
|
|
|
top: `${40 + index * 20}px`
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|