优化bug
This commit is contained in:
+47
-3
@@ -917,6 +917,11 @@ $("#set_bg").click(function () {//设置为背�?
|
||||
// onStateRestored 函数在 core.js 中定义并附加到 window 对象
|
||||
// ==========================================
|
||||
$("#previous").click(function () {
|
||||
// 正在应用历史(撤销/重做)时,直接忽略新的点击,防止并发操作
|
||||
if (window._isApplyingHistory) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (step.val == 0) return;
|
||||
|
||||
step.val--;
|
||||
@@ -928,29 +933,50 @@ $("#previous").click(function () {
|
||||
objs = objs1;
|
||||
|
||||
// 2. 恢复画布 (使用回调函数)
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson1[step.val], function () {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs1);
|
||||
}
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored(); // 图片加载完才执行这一行
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
} else {
|
||||
// 背面逻辑
|
||||
objs2 = JSON.parse(recordObjs2[step.val]);
|
||||
objs = objs2;
|
||||
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson2[step.val], function () {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs2);
|
||||
}
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored();
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
// ==========================================
|
||||
$("#next").click(function () {
|
||||
// 正在应用历史(撤销/重做)时,直接忽略新的点击,防止并发操作
|
||||
if (window._isApplyingHistory) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前历史记录的最大长度
|
||||
let maxLen = $("#front_side").hasClass("ui-button-active") ? recordObjs1.length : recordObjs2.length;
|
||||
|
||||
@@ -962,23 +988,39 @@ $("#next").click(function () {
|
||||
objs1 = JSON.parse(recordObjs1[step.val]);
|
||||
objs = objs1;
|
||||
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson1[step.val], function () {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs1);
|
||||
}
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored(); // 图片加载完才执行这一行
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
} else {
|
||||
objs2 = JSON.parse(recordObjs2[step.val]);
|
||||
objs = objs2;
|
||||
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson2[step.val], function () {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs2);
|
||||
}
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored();
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -1280,8 +1322,9 @@ $("#circle_stroke_transparent").click(function () {
|
||||
|
||||
// saveAs 函数保留,因为它被作为回调传递给 output 函数(第52行)
|
||||
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', 'evented', 'linethrough', 'textBackgroundColor', 'diameter', 'flipped'];
|
||||
let j = canvas1.toJSON(props);
|
||||
let b = canvas2.toJSON(props);
|
||||
|
||||
// 清理不需要的 src 字段(使用 window.cleanupSrcFields,在 output.js 中定义)
|
||||
if (typeof window.cleanupSrcFields === 'function') {
|
||||
@@ -1634,7 +1677,8 @@ $("#circle_text_back_color").bind('input propertychange', function () {
|
||||
})
|
||||
$("#circle_text_text").bind('input propertychange', function () {
|
||||
let val = $("#circle_text_text").val().trim()
|
||||
canvas.getActiveObject().set("text", ` ${val} `);
|
||||
// 有内容时不加首行缩进(前面的空格),只保留后面的空格
|
||||
canvas.getActiveObject().set("text", val ? `${val} ` : ` ${val} `);
|
||||
canvas.renderAll();
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
|
||||
Reference in New Issue
Block a user