接入画布
This commit is contained in:
54
src/component/Canvas/CanvasEditor/commands/ToolCommands.js
Normal file
54
src/component/Canvas/CanvasEditor/commands/ToolCommands.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { Command } from "./Command";
|
||||
|
||||
/**
|
||||
* 工具切换命令
|
||||
* 用于切换编辑器的工具模式(如绘画、选择、橡皮擦等)
|
||||
*/
|
||||
export class ToolCommand extends Command {
|
||||
/**
|
||||
* 创建一个工具切换命令
|
||||
* @param {Object} options 配置选项
|
||||
* @param {Object} options.toolManager 工具管理器实例
|
||||
* @param {String} options.tool 要设置的工具名称
|
||||
* @param {String} options.previousTool 先前的工具名称(可选,如果不提供会在执行时记录)
|
||||
* @param {Boolean} options.saveState 是否保存画布状态(默认为false)
|
||||
*/
|
||||
constructor(options) {
|
||||
super({
|
||||
...options,
|
||||
name: `切换工具: ${options.tool}`,
|
||||
description: `将工具切换为 ${options.tool}`,
|
||||
});
|
||||
|
||||
this.toolManager = options.toolManager;
|
||||
this.tool = options.tool;
|
||||
this.previousTool = options.previousTool || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行工具切换
|
||||
* @returns {String} 设置的工具名称
|
||||
*/
|
||||
execute() {
|
||||
if (!this.toolManager) return null;
|
||||
|
||||
// 记录当前工具(用于撤销)
|
||||
if (!this.previousTool) {
|
||||
this.previousTool = this.toolManager.getCurrentTool();
|
||||
}
|
||||
|
||||
// 切换工具
|
||||
return this.toolManager.setTool(this.tool);
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销工具切换
|
||||
* @returns {String} 恢复的工具名称
|
||||
*/
|
||||
undo() {
|
||||
if (!this.toolManager || !this.previousTool) return null;
|
||||
|
||||
// 恢复到先前工具
|
||||
return this.toolManager.setTool(this.previousTool);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user