Files
aida_front/src/component/Canvas/CanvasEditor/managers/BackgroundFillManager.js
李志鹏 7bc82af120 fix
2025-11-11 14:28:41 +08:00

45 lines
1.3 KiB
JavaScript

import { FillGroupLayerBackgroundCommand } from "../commands/FillGroupLayerBackgroundCommand";
import { FillLayerBackgroundCommand } from "../commands/FillLayerBackgroundCommand";
export class BackgroundFillManager {
constructor({ canvas, layers, commandManager, canvasManager, layerManager }) {
this.canvas = canvas;
this.layers = layers;
this.commandManager = commandManager;
this.canvasManager = canvasManager;
this.layerManager = layerManager;
}
/**
* 填充指定图层背景
* @param {string} layerId 图层ID
* @param {string} fillColor 填充颜色
* @param {boolean} undoable 是否可撤销
* @returns {Promise<void>}
*/
async fillLayerBackground(layerId, fillColor, undoable) {
if (!layerId || !fillColor) {
console.warn("图层ID或填充颜色不能为空");
return;
}
const command = new FillGroupLayerBackgroundCommand({
canvas: this.canvas,
layers: this.layers,
layerId,
fillColor,
canvasManager: this.canvasManager,
layerManager: this.layerManager,
// 是否实时更新
isRetimeUpdate: !undoable,
});
command.undoable = undoable;
if (this.commandManager) {
await this.commandManager.execute(command);
} else {
await command.execute();
}
}
}