优化bug
This commit is contained in:
+108
-52
@@ -1246,7 +1246,111 @@ window.openFile = function open(file) {
|
||||
}
|
||||
})
|
||||
|
||||
// 先清空历史记录和重置 step
|
||||
objs2 = j.bo || []
|
||||
objs1 = j.fo || []
|
||||
step1.val = 0
|
||||
step2.val = 0
|
||||
recordJson1 = []
|
||||
recordJson2 = []
|
||||
recordObjs1 = []
|
||||
recordObjs2 = []
|
||||
|
||||
// 同步更新 window 变量
|
||||
window.objs1 = objs1
|
||||
window.objs2 = objs2
|
||||
window.step1 = step1
|
||||
window.step2 = step2
|
||||
window.recordJson1 = recordJson1
|
||||
window.recordJson2 = recordJson2
|
||||
window.recordObjs1 = recordObjs1
|
||||
window.recordObjs2 = recordObjs2
|
||||
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
objs = objs1
|
||||
recordObjs = recordObjs1
|
||||
recordJson = recordJson1
|
||||
step = step1
|
||||
window.objs = objs1
|
||||
window.recordObjs = recordObjs1
|
||||
window.recordJson = recordJson1
|
||||
window.step = step1
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
objs = objs2
|
||||
recordObjs = recordObjs2
|
||||
recordJson = recordJson2
|
||||
background_image = background_image2
|
||||
step = step2
|
||||
window.objs = objs2
|
||||
window.recordObjs = recordObjs2
|
||||
window.recordJson = recordJson2
|
||||
window.step = step2
|
||||
}
|
||||
|
||||
// 加载 JSON,并在回调中重新生成二维码和条形码
|
||||
// 使用 Promise 确保两个画布都加载完成后再保存初始状态
|
||||
let canvas1Loaded = false
|
||||
let canvas2Loaded = false
|
||||
|
||||
function saveInitialState() {
|
||||
// 两个画布都加载完成后才保存初始状态
|
||||
if (!canvas1Loaded || !canvas2Loaded) return
|
||||
|
||||
// 确保使用正确的 objs1 和 objs2(从文件加载的 fo 和 bo)
|
||||
// 注意:必须使用 fo 和 bo,因为它们是直接从文件 JSON 中读取的
|
||||
// 同时确保 objs1 和 objs2 也被正确设置
|
||||
objs1 = fo || []
|
||||
objs2 = bo || []
|
||||
window.objs1 = objs1
|
||||
window.objs2 = objs2
|
||||
|
||||
// 更新背景图引用
|
||||
background_image1 = canvas1.getObjects()[0]
|
||||
background_image2 = canvas2.getObjects()[0]
|
||||
window.background_image1 = background_image1
|
||||
window.background_image2 = background_image2
|
||||
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
background_image = background_image1
|
||||
window.background_image = background_image1
|
||||
objs = objs1
|
||||
window.objs = objs1
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
background_image = background_image2 || background_image1
|
||||
window.background_image = background_image
|
||||
objs = objs2
|
||||
window.objs = objs2
|
||||
}
|
||||
|
||||
// 保存初始状态(使用从文件加载的 objs 数组)
|
||||
recordObjs1.push(JSON.stringify(objs1))
|
||||
const props = window.TO_JSON_PROPERTIES || ['selectable', 'hoverable', 'hoverCursor', 'text', 'fontStyle', 'fontWeight', 'underline', 'evented', 'linethrough', 'textBackgroundColor', 'diameter', 'flipped'];
|
||||
let j1 = canvas1.toJSON(props)
|
||||
j1.objects[0].hoverCursor = 'default'
|
||||
recordJson1.push(j1)
|
||||
|
||||
recordObjs2.push(JSON.stringify(objs2))
|
||||
let j2 = canvas2.toJSON(props)
|
||||
j2.objects[0].hoverCursor = 'default'
|
||||
recordJson2.push(j2)
|
||||
|
||||
// 同步更新 window 变量和局部变量
|
||||
window.recordObjs1 = recordObjs1
|
||||
window.recordJson1 = recordJson1
|
||||
window.recordObjs2 = recordObjs2
|
||||
window.recordJson2 = recordJson2
|
||||
// 确保局部变量也同步
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
recordObjs = recordObjs1
|
||||
recordJson = recordJson1
|
||||
step = step1
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
recordObjs = recordObjs2
|
||||
recordJson = recordJson2
|
||||
step = step2
|
||||
}
|
||||
}
|
||||
|
||||
canvas1.loadFromJSON(j.f, function () {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
@@ -1260,6 +1364,8 @@ window.openFile = function open(file) {
|
||||
window.updateList();
|
||||
}
|
||||
canvas1.renderAll()
|
||||
canvas1Loaded = true
|
||||
saveInitialState()
|
||||
})
|
||||
canvas2.loadFromJSON(j.b, function () {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
@@ -1274,59 +1380,9 @@ window.openFile = function open(file) {
|
||||
window.updateList();
|
||||
}
|
||||
canvas2.renderAll()
|
||||
canvas2Loaded = true
|
||||
saveInitialState()
|
||||
})
|
||||
background_image1 = canvas1.getObjects()[0]
|
||||
background_image2 = canvas2.getObjects()[0]
|
||||
|
||||
objs2 = j.bo
|
||||
objs1 = j.fo
|
||||
step1.val = 0
|
||||
step2.val = 0
|
||||
recordJson1 = []
|
||||
recordJson2 = []
|
||||
recordObjs1 = []
|
||||
recordObjs2 = []
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
objs = objs1
|
||||
recordObjs = recordObjs1
|
||||
recordJson = recordJson1
|
||||
step = step1
|
||||
background_image = background_image1
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
objs = objs2
|
||||
recordObjs = recordObjs2
|
||||
recordJson = recordJson2
|
||||
background_image = background_image2
|
||||
step = step2
|
||||
}
|
||||
canvas1.renderAll()
|
||||
canvas2.renderAll()
|
||||
// 调用 updateList,现在它已附加到 window 对象
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList(); /*
|
||||
修复打开新文件后无法撤销的bug
|
||||
2022-07-16
|
||||
*/
|
||||
} else {
|
||||
// 延迟检查,确保 core.js 已加载
|
||||
setTimeout(() => {
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
setTimeout(() => {
|
||||
recordObjs1.push(JSON.stringify(objs1))
|
||||
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(props)
|
||||
j2.objects[0].hoverCursor = 'default'
|
||||
recordJson2.push(j2)
|
||||
}, 0)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
|
||||
Reference in New Issue
Block a user