diff --git a/frontend/src/pages/Workflow2/Design/components/FlowCanvas.tsx b/frontend/src/pages/Workflow2/Design/components/FlowCanvas.tsx index 9bac3560..ac713b9f 100644 --- a/frontend/src/pages/Workflow2/Design/components/FlowCanvas.tsx +++ b/frontend/src/pages/Workflow2/Design/components/FlowCanvas.tsx @@ -26,6 +26,7 @@ interface FlowCanvasProps { onEdgeClick?: (event: React.MouseEvent, edge: any) => void; onDrop?: (event: React.DragEvent) => void; onDragOver?: (event: React.DragEvent) => void; + onViewportChange?: () => void; className?: string; } @@ -38,6 +39,7 @@ const FlowCanvas: React.FC = ({ onEdgeClick, onDrop, onDragOver, + onViewportChange, className = '' }) => { const [nodes, , onNodesStateChange] = useNodesState(initialNodes); @@ -133,6 +135,7 @@ const FlowCanvas: React.FC = ({ onEdgeClick={onEdgeClick} onDrop={handleDrop} onDragOver={handleDragOver} + onMove={onViewportChange} nodeTypes={nodeTypes} isValidConnection={isValidConnection} fitView diff --git a/frontend/src/pages/Workflow2/Design/components/WorkflowToolbar.tsx b/frontend/src/pages/Workflow2/Design/components/WorkflowToolbar.tsx index a4ba1db0..68896d6a 100644 --- a/frontend/src/pages/Workflow2/Design/components/WorkflowToolbar.tsx +++ b/frontend/src/pages/Workflow2/Design/components/WorkflowToolbar.tsx @@ -1,11 +1,10 @@ import React from 'react'; -import { Button, Space, Divider, Tooltip } from 'antd'; +import { Button, Divider, Tooltip } from 'antd'; import { SaveOutlined, UndoOutlined, RedoOutlined, CopyOutlined, - ScissorOutlined, DeleteOutlined, ZoomInOutlined, ZoomOutOutlined, @@ -20,8 +19,6 @@ interface WorkflowToolbarProps { onUndo?: () => void; onRedo?: () => void; onCopy?: () => void; - onCut?: () => void; - onPaste?: () => void; onDelete?: () => void; onZoomIn?: () => void; onZoomOut?: () => void; @@ -40,8 +37,6 @@ const WorkflowToolbar: React.FC = ({ onUndo, onRedo, onCopy, - onCut, - onPaste, onDelete, onZoomIn, onZoomOut, @@ -67,7 +62,7 @@ const WorkflowToolbar: React.FC = ({ boxShadow: '0 1px 2px rgba(0, 0, 0, 0.05)' }} > - {/* 左侧:标题和返回按钮 */} + {/* 左侧:返回按钮和标题 */}
- {/* 中间:主要操作按钮 */} -
- - {/* 保存 */} - - - + {/* 右侧:操作按钮区域 */} +
+ {/* 撤销/重做 */} + +
- - {/* 右侧:状态信息 */} -
+ {/* 缩放比例显示 */}
- 缩放: {Math.round(zoom * 100)}% -
-
- React Flow + {Math.round(zoom * 100)}%
+ + + + {/* 保存按钮(最右侧) */} + + +
); diff --git a/frontend/src/pages/Workflow2/Design/index.tsx b/frontend/src/pages/Workflow2/Design/index.tsx index bab09389..73e952a6 100644 --- a/frontend/src/pages/Workflow2/Design/index.tsx +++ b/frontend/src/pages/Workflow2/Design/index.tsx @@ -34,6 +34,7 @@ const WorkflowDesignInner: React.FC = () => { } = useReactFlow(); const [workflowTitle, setWorkflowTitle] = useState('新建工作流'); + const [currentZoom, setCurrentZoom] = useState(1); // 当前缩放比例 const reactFlowWrapper = useRef(null); // 当前工作流ID @@ -67,6 +68,11 @@ const WorkflowDesignInner: React.FC = () => { loadData(); }, [currentWorkflowId, loadWorkflow, setNodes, setEdges]); + // 初始化缩放比例 + useEffect(() => { + setCurrentZoom(getZoom()); + }, [getZoom]); + // 自动适应视图 useEffect(() => { // 延迟执行fitView以确保节点已渲染 @@ -77,10 +83,12 @@ const WorkflowDesignInner: React.FC = () => { minZoom: 1.0, // 最小缩放100% maxZoom: 1.0 // 最大缩放100%,确保默认100% }); + // 更新zoom显示 + setTimeout(() => setCurrentZoom(getZoom()), 850); }, 100); return () => clearTimeout(timer); - }, [fitView]); + }, [fitView, getZoom]); // 初始化示例节点 - 优化位置和布局 const initialNodes: FlowNode[] = [ @@ -217,15 +225,21 @@ const WorkflowDesignInner: React.FC = () => { const handleFitView = useCallback(() => { fitView({ padding: 0.2, duration: 800 }); - }, [fitView]); + // 延迟更新zoom值以获取最新的缩放比例 + setTimeout(() => setCurrentZoom(getZoom()), 850); + }, [fitView, getZoom]); const handleZoomIn = useCallback(() => { zoomIn({ duration: 300 }); - }, [zoomIn]); + // 延迟更新zoom值以获取最新的缩放比例 + setTimeout(() => setCurrentZoom(getZoom()), 350); + }, [zoomIn, getZoom]); const handleZoomOut = useCallback(() => { zoomOut({ duration: 300 }); - }, [zoomOut]); + // 延迟更新zoom值以获取最新的缩放比例 + setTimeout(() => setCurrentZoom(getZoom()), 350); + }, [zoomOut, getZoom]); // 处理节点拖拽放置 - 使用官方推荐的screenToFlowPosition方法 const handleDrop = useCallback((event: React.DragEvent) => { @@ -352,6 +366,12 @@ const WorkflowDesignInner: React.FC = () => { setConfigEdge(null); }, []); + // 监听视图变化(缩放、平移等) + const handleViewportChange = useCallback(() => { + const zoom = getZoom(); + setCurrentZoom(zoom); + }, [getZoom]); + return (
{ onFitView={handleFitView} canUndo={false} canRedo={false} - zoom={getZoom()} + zoom={currentZoom} /> {/* 主要内容区域 */} @@ -394,6 +414,7 @@ const WorkflowDesignInner: React.FC = () => { onNodeClick={handleNodeClick} onEdgeClick={handleEdgeClick} onDrop={handleDrop} + onViewportChange={handleViewportChange} className="workflow-canvas" />