From cc61ef0b93b7e0128408694dc5a5d91163184658 Mon Sep 17 00:00:00 2001 From: asp_ly Date: Sat, 14 Dec 2024 13:56:32 +0800 Subject: [PATCH] 1 --- .../Workflow/Definition/Design/index.tsx | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Workflow/Definition/Design/index.tsx b/frontend/src/pages/Workflow/Definition/Design/index.tsx index 77391b4c..a1bf9495 100644 --- a/frontend/src/pages/Workflow/Definition/Design/index.tsx +++ b/frontend/src/pages/Workflow/Definition/Design/index.tsx @@ -19,6 +19,7 @@ import '@antv/x6-plugin-clipboard'; import '@antv/x6-plugin-history'; import { Selection } from '@antv/x6-plugin-selection'; import { MiniMap } from '@antv/x6-plugin-minimap'; +import { Clipboard } from '@antv/x6-plugin-clipboard'; import {getDefinitionDetail, saveDefinition} from '../service'; import {getNodeDefinitionList} from './service'; import NodePanel from './components/NodePanel'; @@ -139,6 +140,43 @@ const WorkflowDesign: React.FC = () => { }); }; + // 处理复制操作 + const handleCopy = () => { + if (!graph) return; + const cells = graph.getSelectedCells(); + if (cells.length === 0) { + message.info('请先选择要复制的节点'); + return; + } + graph.copy(cells); + message.success('已复制'); + }; + + // 处理剪切操作 + const handleCut = () => { + if (!graph) return; + const cells = graph.getSelectedCells(); + if (cells.length === 0) { + message.info('请先选择要剪切的节点'); + return; + } + graph.cut(cells); + message.success('已剪切'); + }; + + // 处理粘贴操作 + const handlePaste = () => { + if (!graph) return; + if (graph.isClipboardEmpty()) { + message.info('剪贴板为空'); + return; + } + const cells = graph.paste({ offset: 32 }); + graph.cleanSelection(); + graph.select(cells); + message.success('已粘贴'); + }; + // 首先加载节点定义列表 useEffect(() => { const loadNodeDefinitions = async () => { @@ -217,6 +255,11 @@ const WorkflowDesign: React.FC = () => { ); } + // 注册剪贴板插件 + graph.use(new Clipboard({ + enabled: true, + })); + registerEventHandlers(graph); setGraph(graph); @@ -434,19 +477,19 @@ const WorkflowDesign: React.FC = () => {