import React, { useState } from "react"; import { Card, Input, Tag, Select, Button } from "antd"; import { DeleteOutlined } from "@ant-design/icons"; import { CleansingTemplate } from "../../cleansing.model"; import { Workflow } from "lucide-react"; import { OperatorI } from "@/pages/OperatorMarket/operator.model"; interface OperatorFlowProps { selectedOperators: OperatorI[]; configOperator: OperatorI | null; templates: CleansingTemplate[]; currentTemplate: CleansingTemplate | null; setCurrentTemplate: (template: CleansingTemplate | null) => void; removeOperator: (id: string) => void; setSelectedOperators: (operators: OperatorI[]) => void; setConfigOperator: (operator: OperatorI | null) => void; handleDragStart: ( e: React.DragEvent, operator: OperatorI, source: "sort" ) => void; handleItemDragOver: (e: React.DragEvent, itemId: string) => void; handleItemDragLeave: (e: React.DragEvent) => void; handleItemDrop: (e: React.DragEvent, index: number) => void; handleContainerDragOver: (e: React.DragEvent) => void; handleContainerDragLeave: (e: React.DragEvent) => void; handleDragEnd: (e: React.DragEvent) => void; handleDropToContainer: (e: React.DragEvent) => void; } const OperatorFlow: React.FC = ({ selectedOperators, configOperator, templates, currentTemplate, setSelectedOperators, setConfigOperator, removeOperator, setCurrentTemplate, handleDragStart, handleItemDragLeave, handleItemDragOver, handleItemDrop, handleContainerDragLeave, handleDropToContainer, handleDragEnd, }) => { const [editingIndex, setEditingIndex] = useState(null); // 添加编号修改处理函数 const handleIndexChange = (operatorId: string, newIndex: string) => { const index = Number.parseInt(newIndex); if (isNaN(index) || index < 1 || index > selectedOperators.length) { return; // 无效输入,不处理 } const currentIndex = selectedOperators.findIndex( (op) => op.id === operatorId ); if (currentIndex === -1) return; const targetIndex = index - 1; // 转换为0基索引 if (currentIndex === targetIndex) return; // 位置没有变化 const newOperators = [...selectedOperators]; const [movedOperator] = newOperators.splice(currentIndex, 1); newOperators.splice(targetIndex, 0, movedOperator); setSelectedOperators(newOperators); setEditingIndex(null); }; return (
{/* 工具栏 */}
算子编排({selectedOperators.length}){" "}
{/* 编排区域 */}
e.preventDefault()} onDragLeave={handleContainerDragLeave} onDrop={handleDropToContainer} > {selectedOperators.map((operator, index) => ( handleDragStart(e, operator, "sort")} onDragEnd={handleDragEnd} onDragOver={(e) => handleItemDragOver(e, operator.id)} onDragLeave={handleItemDragLeave} onDrop={(e) => handleItemDrop(e, index)} onClick={() => setConfigOperator(operator)} >
{/* 可编辑编号 */} ⋮⋮ {editingIndex === operator.id ? ( handleIndexChange(operator.id, e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") handleIndexChange( operator.id, (e.target as HTMLInputElement).value ); else if (e.key === "Escape") setEditingIndex(null); }} onClick={(e) => e.stopPropagation()} /> ) : ( { e.stopPropagation(); setEditingIndex(operator.id); }} > {index + 1} )} {/* 算子图标和名称 */}
{operator.name}
{/* 分类标签 */} 分类 {/* 参数状态指示 */} {Object.values(operator.configs).some( (param: any) => (param.type === "input" && !param.value) || (param.type === "checkbox" && Array.isArray(param.value) && param.value.length === 0) ) && 待配置} {/* 操作按钮 */} { e.stopPropagation(); removeOperator(operator.id); }} >
))} {selectedOperators.length === 0 && (
开始构建您的算子流程
从左侧算子库拖拽算子到此处,或点击算子添加
)}
); }; export default OperatorFlow;