diff --git a/frontend/src/pages/Workflow/Definition/Design/index.tsx b/frontend/src/pages/Workflow/Definition/Design/index.tsx index bf68173b..bbad059e 100644 --- a/frontend/src/pages/Workflow/Definition/Design/index.tsx +++ b/frontend/src/pages/Workflow/Definition/Design/index.tsx @@ -51,6 +51,7 @@ const WorkflowDesign: React.FC = () => { const [definitionData, setDefinitionData] = useState(null); const [nodeDefinitions, setNodeDefinitions] = useState([]); const [isNodeDefinitionsLoaded, setIsNodeDefinitionsLoaded] = useState(false); + const [forceUpdate, setForceUpdate] = useState(false); // 初始化图形 const initGraph = () => { @@ -84,6 +85,22 @@ const WorkflowDesign: React.FC = () => { // 注册插件 const history = new History({ enabled: true, + beforeAddCommand(event: any, args: any) { + console.log('History command added:', event, args); + return true; + }, + afterExecuteCommand: () => { + // 强制更新组件状态 + setForceUpdate(prev => !prev); + }, + afterUndo: () => { + // 强制更新组件状态 + setForceUpdate(prev => !prev); + }, + afterRedo: () => { + // 强制更新组件状态 + setForceUpdate(prev => !prev); + }, }); graph.use(new Selection()); @@ -101,17 +118,42 @@ const WorkflowDesign: React.FC = () => { // 监听图形变化 graph.on('cell:added', ({ cell }) => { const canUndo = history.canUndo(); - console.log('Cell added, history:', canUndo, cell); + const canRedo = history.canRedo(); + console.log('Cell added:', { + cell, + canUndo, + canRedo, + stackSize: history.stackSize, + }); + // 强制更新组件状态 + setForceUpdate(prev => !prev); }); graph.on('cell:removed', ({ cell }) => { const canUndo = history.canUndo(); - console.log('Cell removed, history:', canUndo, cell); + const canRedo = history.canRedo(); + console.log('Cell removed:', { + cell, + canUndo, + canRedo, + stackSize: history.stackSize, + }); + // 强制更新组件状态 + setForceUpdate(prev => !prev); }); graph.on('cell:changed', ({ cell, options }) => { const canUndo = history.canUndo(); - console.log('Cell changed, history:', canUndo, cell, options); + const canRedo = history.canRedo(); + console.log('Cell changed:', { + cell, + options, + canUndo, + canRedo, + stackSize: history.stackSize, + }); + // 强制更新组件状态 + setForceUpdate(prev => !prev); }); registerEventHandlers(graph); @@ -127,9 +169,24 @@ const WorkflowDesign: React.FC = () => { console.error('History plugin not initialized'); return; } - console.log('Can undo:', history.canUndo()); + + const beforeState = { + canUndo: history.canUndo(), + canRedo: history.canRedo(), + stackSize: history.stackSize, + }; + if (history.canUndo()) { history.undo(); + const afterState = { + canUndo: history.canUndo(), + canRedo: history.canRedo(), + stackSize: history.stackSize, + }; + console.log('Undo operation:', { + before: beforeState, + after: afterState, + }); message.success('已撤销'); } else { message.info('没有可撤销的操作'); @@ -144,9 +201,24 @@ const WorkflowDesign: React.FC = () => { console.error('History plugin not initialized'); return; } - console.log('Can redo:', history.canRedo()); + + const beforeState = { + canUndo: history.canUndo(), + canRedo: history.canRedo(), + stackSize: history.stackSize, + }; + if (history.canRedo()) { history.redo(); + const afterState = { + canUndo: history.canUndo(), + canRedo: history.canRedo(), + stackSize: history.stackSize, + }; + console.log('Redo operation:', { + before: beforeState, + after: afterState, + }); message.success('已重做'); } else { message.info('没有可重做的操作');