调整优化

This commit is contained in:
24kycj
2025-12-15 02:55:54 +08:00
parent 50ff0d347a
commit 3c4080f3f1
8 changed files with 3048 additions and 3407 deletions
+25 -14
View File
@@ -25,17 +25,14 @@ async function saveImageAsPNG(buffer) {
});
if (canceled) {
console.log('用户取消了保存操作');
return;
}
// 将Buffer写入PNG文件到用户选择的路径
fs.writeFile(filePath, buffer, (err) => {
if (err) {
console.error('写入文件失败:', err);
} else {
layer.msg(language_str("saveSucc") + filePath);//'保存成功至'
console.log('PNG文件已保存至:', filePath);
}
});
}
@@ -1110,15 +1107,31 @@ window.openFile = function open(file) {
});
canvas1.loadFromJSON(j.f, function () {
// 加载后解锁所有对象(背景除外)
if (typeof window.unlockAllObjects === 'function') {
window.unlockAllObjects(canvas1);
}
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
window.regenerateQrCodesAndBarcodes(canvas1, fo);
}
// 加载后更新列表和图标显示
if (typeof window.updateList === 'function') {
window.updateList();
}
canvas1.renderAll();
});
canvas2.loadFromJSON(j.b, function () {
// 加载后解锁所有对象(背景除外)
if (typeof window.unlockAllObjects === 'function') {
window.unlockAllObjects(canvas2);
}
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
window.regenerateQrCodesAndBarcodes(canvas2, bo);
}
// 加载后更新列表和图标显示
if (typeof window.updateList === 'function') {
window.updateList();
}
canvas2.renderAll();
});
@@ -1165,12 +1178,13 @@ window.openFile = function open(file) {
}
setTimeout(() => {
recordObjs1.push(JSON.stringify(objs1))
let j1 = canvas1.toJSON(["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline"]);
const props = window.TO_JSON_PROPERTIES || ["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline", "evented"];
let j1 = canvas1.toJSON(props);
j1.objects[0].hoverCursor = "default";
recordJson1.push(j1);
recordObjs2.push(JSON.stringify(objs2))
let j2 = canvas2.toJSON(["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline"]);
let j2 = canvas2.toJSON(props);
recordJson2.push(j2);
}, 0);
} catch (e) {
@@ -1229,8 +1243,9 @@ function saveAs(op1, callback) {
}
});
let j = canvas1.toJSON(["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline"]);
let b = canvas2.toJSON(["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline"]);
const props = window.TO_JSON_PROPERTIES || ["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline", "lockMovementX", "lockMovementY", "lockRotation", "lockScalingX", "lockScalingY", "lockSkewingX", "lockSkewingY", "evented"];
let j = canvas1.toJSON(props);
let b = canvas2.toJSON(props);
// 恢复辅助线
guideLines1.forEach(obj => canvas1.add(obj));
@@ -1271,7 +1286,6 @@ function saveAs(op1, callback) {
callback();
}
}).catch(err => {
console.log()
})
}
@@ -1292,8 +1306,9 @@ function save(op1, callback) {
}
});
let j = canvas1.toJSON(["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline"]);
let b = canvas2.toJSON(["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline"]);
const props = window.TO_JSON_PROPERTIES || ["selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline", "lockMovementX", "lockMovementY", "lockRotation", "lockScalingX", "lockScalingY", "lockSkewingX", "lockSkewingY", "evented"];
let j = canvas1.toJSON(props);
let b = canvas2.toJSON(props);
// 恢复辅助线
guideLines1.forEach(obj => canvas1.add(obj));
@@ -1346,7 +1361,6 @@ function save(op1, callback) {
callback();
}
}).catch(err => {
console.log()
})
}
@@ -1365,7 +1379,6 @@ window.saveHistory = function saveHistory() {
}
}
} catch (e) {
console.error("读取历史记录失败,将重置:", e);
// 出错时使用默认空数组,不中断流程
j = { history: [] };
}
@@ -1398,7 +1411,6 @@ window.saveHistory = function saveHistory() {
try {
fs.writeFileSync(fullPath, JSON.stringify(j), 'utf8');
} catch (e) {
console.error("写入历史记录失败:", e);
}
};
// 向后兼容
@@ -1448,7 +1460,6 @@ function clearAll() {
if (typeof window.updateList === 'function') {
window.updateList();
}
console.log();
}
// 将 clearAll 附加到 window 对象,确保全局可访问