红绿图导出问题

This commit is contained in:
李志鹏
2026-04-13 11:20:26 +08:00
parent f16aa6ea14
commit c6b1bdbdf1
4 changed files with 1074 additions and 1067 deletions

View File

@@ -55,6 +55,7 @@ commandManager.setChangeCallback((info) => {
emit("undo-redo-status-changed", { emit("undo-redo-status-changed", {
canUndo: canUndo.value, canUndo: canUndo.value,
canRedo: canRedo.value, canRedo: canRedo.value,
type: info.type,
commandManager, commandManager,
}); });
}); });

View File

@@ -907,7 +907,8 @@
} }
emit("changeCanvas", commandData) emit("changeCanvas", commandData)
canvasManager.changeCanvas() canvasManager.changeCanvas()
if ((command.canUndo || command.canRedo) && props.enabledRedGreenMode) { const type = command.type
if (props.enabledRedGreenMode && (type === "undo" || type === "redo")) {
setTimeout(async () => { setTimeout(async () => {
try { try {
const imageData = await canvasManager.exportImage({ const imageData = await canvasManager.exportImage({

View File

@@ -606,7 +606,9 @@ export class ExportManager {
imageSmoothingEnabled: true, imageSmoothingEnabled: true,
}); });
// tempFabricCanvas.setZoom(1); // tempFabricCanvas.setZoom(1);
console.log("==========", fixedLayerObject) const ox = fixedLayerObject.left - fixedLayerObject.width * fixedLayerObject.scaleX / 2
const oy = fixedLayerObject.top - fixedLayerObject.height * fixedLayerObject.scaleY / 2
console.log("==========", fixedLayerObject, ox, oy)
try { try {
// 克隆并添加所有对象到临时画布,需要调整位置相对于固定图层 // 克隆并添加所有对象到临时画布,需要调整位置相对于固定图层
for (let i = 0; i < objectsToExport.length; i++) { for (let i = 0; i < objectsToExport.length; i++) {
@@ -616,15 +618,16 @@ export class ExportManager {
restoreOpacityInRedGreen && true restoreOpacityInRedGreen && true
); );
if (cloned) { if (cloned) {
let scaleX = cloned.scaleX / fixedLayerObject.scaleX
let scaleY = cloned.scaleY / fixedLayerObject.scaleY
let top = (cloned.top - oy) * scaleY
let left = (cloned.left - ox) * scaleX
cloned.set({ cloned.set({
left: canvasWidth / 2, left: left,
top: canvasHeight / 2, top: top,
scaleX: cloned.scaleX / fixedLayerObject.scaleX, scaleX: scaleX,
scaleY: cloned.scaleY / fixedLayerObject.scaleY, scaleY: scaleY,
originX: "center",
originY: "center",
}); });
console.log("==========", {...cloned})
// 更新对象坐标 // 更新对象坐标
cloned.setCoords(); cloned.setCoords();
tempFabricCanvas.add(cloned); tempFabricCanvas.add(cloned);

View File

@@ -180,7 +180,7 @@ export class CommandManager {
this._recordPerformance("execute", command.constructor.name, duration); this._recordPerformance("execute", command.constructor.name, duration);
// 通知状态变化 // 通知状态变化
this._notifyStateChange(); this._notifyStateChange("execute");
console.log(`✅ 命令执行成功: ${command.constructor.name}`); console.log(`✅ 命令执行成功: ${command.constructor.name}`);
return result; return result;
@@ -219,7 +219,7 @@ export class CommandManager {
this._recordPerformance("undo", command.constructor.name, duration); this._recordPerformance("undo", command.constructor.name, duration);
// 通知状态变化 // 通知状态变化
this._notifyStateChange(); this._notifyStateChange("undo");
console.log(`✅ 命令撤销成功: ${command.constructor.name}`); console.log(`✅ 命令撤销成功: ${command.constructor.name}`);
return result; return result;
@@ -258,7 +258,7 @@ export class CommandManager {
this._recordPerformance("redo", command.constructor.name, duration); this._recordPerformance("redo", command.constructor.name, duration);
// 通知状态变化 // 通知状态变化
this._notifyStateChange(); this._notifyStateChange("redo");
console.log(`✅ 命令重做成功: ${command.constructor.name}`); console.log(`✅ 命令重做成功: ${command.constructor.name}`);
return result; return result;
@@ -298,7 +298,7 @@ export class CommandManager {
this.undoStack = []; this.undoStack = [];
this.redoStack = []; this.redoStack = [];
this._notifyStateChange(); this._notifyStateChange("clear");
// console.log("📝 命令历史已清空"); // console.log("📝 命令历史已清空");
} }
@@ -417,10 +417,12 @@ export class CommandManager {
* 通知状态变化 * 通知状态变化
* @private * @private
*/ */
_notifyStateChange() { _notifyStateChange(type) {
if (this.onStateChange) { if (this.onStateChange) {
try { try {
this.onStateChange(this.getState()); const obj = this.getState();
obj.type = type;
this.onStateChange(obj);
} catch (error) { } catch (error) {
console.error("状态变化回调执行失败:", error); console.error("状态变化回调执行失败:", error);
} }