添加图层剪切功能

This commit is contained in:
李志鹏
2025-11-12 16:12:02 +08:00
parent 2117f9d9d1
commit b24bcf68f2
14 changed files with 835 additions and 16 deletions

View File

@@ -493,7 +493,7 @@ export class ExportLayerToImageCommand extends Command {
this._collectLayersAndObjects();
}
async execute() {
async execute(isDownload = true) {
if (!this.layer) {
throw new Error(`图层 ${this.layerId} 不存在`);
}
@@ -532,18 +532,21 @@ export class ExportLayerToImageCommand extends Command {
fabricObjects: this.objectsToRasterize,
isReturenDataURL: true,
maskObject: clippingMaskFabricObject || null, // 不处理遮罩
scaleFactor: isDownload ? 2 : 1,
});
// 模拟浏览器下载
const link = document.createElement("a");
link.href = imageBase64;
link.download = `${this.layer.name}.png`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
if (isDownload) {
const link = document.createElement("a");
link.href = imageBase64;
link.download = `${this.layer.name}.png`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
console.log(`✅ 图层 ${this.layer.name} 导出完成`);
return true;
return imageBase64;
} catch (error) {
console.error("导出图层失败:", error);
throw error;