import React from 'react'; import { NodeCategory } from '../types'; import { NODE_DEFINITIONS } from '../nodes'; import type { WorkflowNodeDefinition } from '../nodes/types'; // 图标映射函数 const getNodeIcon = (iconName: string): string => { const iconMap: Record = { 'play-circle': '▶️', 'stop-circle': '⏹️', 'user': '👤', 'api': '⚙️', 'code': '📜', 'build': '🚀', 'jenkins': '🔨', 'gateway': '💎' }; return iconMap[iconName] || '📋'; }; interface NodePanelProps { className?: string; } const NodePanel: React.FC = ({ className = '' }) => { // 按分类分组节点 const nodesByCategory = NODE_DEFINITIONS.reduce((acc, node) => { if (!acc[node.category]) { acc[node.category] = []; } acc[node.category].push(node); return acc; }, {} as Record); // 拖拽开始处理 const handleDragStart = (event: React.DragEvent, nodeDefinition: WorkflowNodeDefinition) => { event.dataTransfer.setData('application/reactflow', JSON.stringify({ nodeType: nodeDefinition.nodeType, nodeDefinition })); event.dataTransfer.effectAllowed = 'move'; }; // 渲染节点项 const renderNodeItem = (nodeDefinition: WorkflowNodeDefinition) => (
{ e.currentTarget.style.background = '#f9fafb'; e.currentTarget.style.borderColor = nodeDefinition.uiConfig.style.fill; e.currentTarget.style.transform = 'translateX(2px)'; }} onMouseLeave={(e) => { e.currentTarget.style.background = 'white'; e.currentTarget.style.borderColor = '#e5e7eb'; e.currentTarget.style.transform = 'translateX(0)'; }} onDragStart={(e) => { e.currentTarget.style.cursor = 'grabbing'; handleDragStart(e, nodeDefinition); }} onDragEnd={(e) => { e.currentTarget.style.cursor = 'grab'; }} >
{getNodeIcon(nodeDefinition.uiConfig.style.icon)}
{nodeDefinition.nodeName}
{nodeDefinition.description}
); // 分类标题映射 const categoryTitles = { [NodeCategory.EVENT]: '🎯 事件节点', [NodeCategory.TASK]: '📋 任务节点', [NodeCategory.GATEWAY]: '🔀 网关节点', [NodeCategory.CONTAINER]: '📦 容器节点' }; return (

节点面板

拖拽节点到画布创建工作流

{Object.entries(nodesByCategory).map(([category, nodes]) => (
{categoryTitles[category as NodeCategory]}
{nodes.map(renderNodeItem)}
))}
{/* 使用提示 */}
💡 提示:
• 拖拽节点到画布创建
• 双击节点进行配置
• 连接节点创建流程
); }; export default NodePanel;