添加图层剪切功能
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user