1
This commit is contained in:
parent
c2a460d7d1
commit
9e17cdb685
@ -51,6 +51,7 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
const [definitionData, setDefinitionData] = useState<any>(null);
|
const [definitionData, setDefinitionData] = useState<any>(null);
|
||||||
const [nodeDefinitions, setNodeDefinitions] = useState<NodeDefinition[]>([]);
|
const [nodeDefinitions, setNodeDefinitions] = useState<NodeDefinition[]>([]);
|
||||||
const [isNodeDefinitionsLoaded, setIsNodeDefinitionsLoaded] = useState(false);
|
const [isNodeDefinitionsLoaded, setIsNodeDefinitionsLoaded] = useState(false);
|
||||||
|
const [forceUpdate, setForceUpdate] = useState(false);
|
||||||
|
|
||||||
// 初始化图形
|
// 初始化图形
|
||||||
const initGraph = () => {
|
const initGraph = () => {
|
||||||
@ -84,6 +85,22 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
// 注册插件
|
// 注册插件
|
||||||
const history = new History({
|
const history = new History({
|
||||||
enabled: true,
|
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());
|
graph.use(new Selection());
|
||||||
@ -101,17 +118,42 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
// 监听图形变化
|
// 监听图形变化
|
||||||
graph.on('cell:added', ({ cell }) => {
|
graph.on('cell:added', ({ cell }) => {
|
||||||
const canUndo = history.canUndo();
|
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 }) => {
|
graph.on('cell:removed', ({ cell }) => {
|
||||||
const canUndo = history.canUndo();
|
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 }) => {
|
graph.on('cell:changed', ({ cell, options }) => {
|
||||||
const canUndo = history.canUndo();
|
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);
|
registerEventHandlers(graph);
|
||||||
@ -127,9 +169,24 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
console.error('History plugin not initialized');
|
console.error('History plugin not initialized');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('Can undo:', history.canUndo());
|
|
||||||
|
const beforeState = {
|
||||||
|
canUndo: history.canUndo(),
|
||||||
|
canRedo: history.canRedo(),
|
||||||
|
stackSize: history.stackSize,
|
||||||
|
};
|
||||||
|
|
||||||
if (history.canUndo()) {
|
if (history.canUndo()) {
|
||||||
history.undo();
|
history.undo();
|
||||||
|
const afterState = {
|
||||||
|
canUndo: history.canUndo(),
|
||||||
|
canRedo: history.canRedo(),
|
||||||
|
stackSize: history.stackSize,
|
||||||
|
};
|
||||||
|
console.log('Undo operation:', {
|
||||||
|
before: beforeState,
|
||||||
|
after: afterState,
|
||||||
|
});
|
||||||
message.success('已撤销');
|
message.success('已撤销');
|
||||||
} else {
|
} else {
|
||||||
message.info('没有可撤销的操作');
|
message.info('没有可撤销的操作');
|
||||||
@ -144,9 +201,24 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
console.error('History plugin not initialized');
|
console.error('History plugin not initialized');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('Can redo:', history.canRedo());
|
|
||||||
|
const beforeState = {
|
||||||
|
canUndo: history.canUndo(),
|
||||||
|
canRedo: history.canRedo(),
|
||||||
|
stackSize: history.stackSize,
|
||||||
|
};
|
||||||
|
|
||||||
if (history.canRedo()) {
|
if (history.canRedo()) {
|
||||||
history.redo();
|
history.redo();
|
||||||
|
const afterState = {
|
||||||
|
canUndo: history.canUndo(),
|
||||||
|
canRedo: history.canRedo(),
|
||||||
|
stackSize: history.stackSize,
|
||||||
|
};
|
||||||
|
console.log('Redo operation:', {
|
||||||
|
before: beforeState,
|
||||||
|
after: afterState,
|
||||||
|
});
|
||||||
message.success('已重做');
|
message.success('已重做');
|
||||||
} else {
|
} else {
|
||||||
message.info('没有可重做的操作');
|
message.info('没有可重做的操作');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user