优化bug
This commit is contained in:
+50
-25
@@ -41,6 +41,8 @@ fabric.Object.prototype.objectCaching = false;
|
||||
ctx1 = canvas1.getSelectionContext();
|
||||
ctx2 = canvas2.getSelectionContext();
|
||||
is_bgi_add = false;
|
||||
// 撤销/重做过程中使用的标志位,防止并发操作和误记录历史
|
||||
window._isApplyingHistory = false;
|
||||
// 同步到 window 对象
|
||||
window.ctx1 = ctx1;
|
||||
window.ctx2 = ctx2;
|
||||
@@ -1224,6 +1226,10 @@ window.selectObj = function selectObj(objIndices, isFromCanvas = false) {
|
||||
}
|
||||
|
||||
window.recordState = function recordState() {
|
||||
// 撤销/重做过程中不记录历史,避免产生“中间状态”,导致需要点多次才能回到预期
|
||||
if (window._isApplyingHistory) {
|
||||
return;
|
||||
}
|
||||
//pre_objs.push(JSON.stringify(objs));
|
||||
//pre_json.push(canvas.toJSON(["selectable","hoverable","hoverCursor","text","fontStyle","fontWeight","underline"]));
|
||||
//next_json = [];
|
||||
@@ -1492,8 +1498,11 @@ function isObjectLocked(obj) {
|
||||
window.isObjectLocked = isObjectLocked;
|
||||
|
||||
// 统一的 toJSON 属性列表,不包含锁定相关属性(锁定状态不应被保存)
|
||||
// 统一的 toJSON 属性列表,不包含锁定相关属性(锁定状态不应被保存)
|
||||
// 包含所有需要保存的属性,特别是自定义对象的属性(如 CurvedText 的 diameter, flipped)
|
||||
const TO_JSON_PROPERTIES = [
|
||||
"selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline", "evented"
|
||||
"selectable", "hoverable", "hoverCursor", "text", "fontStyle", "fontWeight", "underline",
|
||||
"evented", "linethrough", "textBackgroundColor", "diameter", "flipped"
|
||||
];
|
||||
// 暴露到全局作用域
|
||||
window.TO_JSON_PROPERTIES = TO_JSON_PROPERTIES;
|
||||
@@ -1608,13 +1617,14 @@ function initCanvasEvents() {
|
||||
handleObjectSelected(e);
|
||||
});
|
||||
|
||||
// 阻止被锁定的对象被框选选中(只过滤被锁定的对象,保留未锁定的对象)
|
||||
// 阻止被锁定的对象和辅助线被框选选中:
|
||||
// - 锁定对象:不能被框选(只能通过列表选中)
|
||||
// - 辅助线:永远不进入选区,避免选区被拉得很大
|
||||
currentCanvas.on('before:selection:created', (e) => {
|
||||
if (!e.targets || e.targets.length === 0) return;
|
||||
// 过滤掉被锁定的对象,保留辅助线和未锁定的对象
|
||||
e.targets = e.targets.filter(target => {
|
||||
if (target.isGuideLine) return true; // 保留辅助线
|
||||
return !isObjectLocked(target); // 移除被锁定的对象,保留未锁定的对象
|
||||
if (target.isGuideLine) return false; // 完全排除辅助线
|
||||
return !isObjectLocked(target); // 排除被锁定的普通对象
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1850,6 +1860,11 @@ function initRulers() {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// 防止重复调用:如果正在拖拽,直接返回
|
||||
if ($dragLine && $dragLine.length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建临时显示的线
|
||||
$dragLine = $('<div class="guide-line-drag"></div>');
|
||||
$('.canvas-wrapper').append($dragLine);
|
||||
@@ -1922,18 +1937,13 @@ function initRulers() {
|
||||
let canvasX = relX / zoom;
|
||||
let canvasY = relY / zoom;
|
||||
|
||||
// 获取画布的实际尺寸和可见区域尺寸
|
||||
let canvasWidth = canvas.width || 10000;
|
||||
let canvasHeight = canvas.height || 10000;
|
||||
// 获取可见区域的尺寸(考虑缩放)
|
||||
let visibleWidth = canvasWrapper.width() || canvasWidth;
|
||||
let visibleHeight = canvasWrapper.height() || canvasHeight;
|
||||
// 使用足够大的固定值,确保辅助线能够覆盖整个画布和可见区域
|
||||
// 使用 100000 确保无论画布多大、如何缩放,都能覆盖整个可见区域
|
||||
let lineExtent = 100000;
|
||||
// 获取画布的实际尺寸(用于决定辅助线的长度)
|
||||
let canvasWidth = canvas.width || 2000;
|
||||
let canvasHeight = canvas.height || 2000;
|
||||
// 使用与画布尺寸相关的长度,避免“整块区域都像辅助线”,同时保证能横穿整个画布
|
||||
let lineExtent = Math.max(canvasWidth, canvasHeight) * 2;
|
||||
|
||||
// 构造线对象,使用足够大的范围确保覆盖整个画布
|
||||
// 线的起点和终点要足够远,确保覆盖整个可见区域
|
||||
// 构造线对象
|
||||
let linePoints = [];
|
||||
if (type === 'horizontal') {
|
||||
// 水平线:从很远的左边到很远的右边
|
||||
@@ -1962,19 +1972,34 @@ function initRulers() {
|
||||
lockScalingX: true,
|
||||
lockScalingY: true,
|
||||
hoverCursor: type === 'horizontal' ? 'ns-resize' : 'ew-resize',
|
||||
perPixelTargetFind: false, // 使用边界框检测而不是像素检测
|
||||
targetFindTolerance: 10, // 增加点击容差,扩大可点击区域(像素)
|
||||
padding: 10, // 增加选择边界的内边距
|
||||
// design1 中改回边框命中模型,保证更容易点中拖拽
|
||||
perPixelTargetFind: false,
|
||||
targetFindTolerance: 10,
|
||||
padding: 10,
|
||||
isGuideLine: true,
|
||||
ignoreSave: true
|
||||
});
|
||||
|
||||
// 限制移动方向
|
||||
guideLine.on('moving', function (e) {
|
||||
// 限制移动方向(只约束方向,不把整条线拖到极远,避免“整片区域是辅助线”的感觉)
|
||||
guideLine.on('moving', function () {
|
||||
if (type === 'horizontal') {
|
||||
this.left = -lineExtent;
|
||||
// 水平线:根据当前中心点的 Y,重算 x1/x2,使其横穿画布
|
||||
const cy = this.getCenterPoint().y;
|
||||
this.set({
|
||||
x1: -lineExtent,
|
||||
y1: cy,
|
||||
x2: lineExtent,
|
||||
y2: cy
|
||||
});
|
||||
} else {
|
||||
this.top = -lineExtent;
|
||||
// 垂直线:根据当前中心点的 X,重算 y1/y2,使其竖穿画布
|
||||
const cx = this.getCenterPoint().x;
|
||||
this.set({
|
||||
x1: cx,
|
||||
y1: -lineExtent,
|
||||
x2: cx,
|
||||
y2: lineExtent
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2200,8 +2225,8 @@ window.copySelection = function copySelection() {
|
||||
let appData = (idx > 0 && objs[idx - 1]) ? objs[idx - 1] : { type: 0 };
|
||||
|
||||
return {
|
||||
// 1. 保存画面样式 (坐标、颜色、字号等)
|
||||
fabricJson: obj.toObject(['id', 'name', 'selectable', 'evented', 'data']),
|
||||
// 1. 保存画面样式 (坐标、颜色、字号等,包含图片的 src)
|
||||
fabricJson: obj.toObject(['id', 'name', 'selectable', 'evented', 'data', 'src']),
|
||||
// 2. 保存业务属性 (深拷贝,防止引用冲突)
|
||||
appData: JSON.parse(JSON.stringify(appData))
|
||||
};
|
||||
|
||||
+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();
|
||||
|
||||
+2534
-2403
File diff suppressed because it is too large
Load Diff
+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() {
|
||||
|
||||
+113
-150
@@ -28,69 +28,10 @@ $('body').keydown(function (event) {
|
||||
const isModifierKey = event.ctrlKey || event.metaKey; // 兼容三端
|
||||
|
||||
// 快捷键处理(在输入框或文本区域中时不触发,除了删除相关的)
|
||||
// 注意:大部分快捷键已在 core.js 中统一处理,此处只保留 ui.js 特有的快捷键
|
||||
// 已移除的重复快捷键:CTRL/CMD+N/O/S/Z/Y/C/V/SHIFT+DEL/DEL(已在 core.js 中处理)
|
||||
if (!_inputEdit && !_textEdit) {
|
||||
// CTRL/CMD+N - 新建
|
||||
if (isModifierKey && event.keyCode == 78) {
|
||||
event.preventDefault();
|
||||
$('#new').click();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+O - 打开
|
||||
if (isModifierKey && event.keyCode == 79) {
|
||||
event.preventDefault();
|
||||
$('#open').click();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+S - 保存
|
||||
if (isModifierKey && !event.shiftKey && event.keyCode == 83) {
|
||||
event.preventDefault();
|
||||
$('#save').click();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+SHIFT+S - 保存副本
|
||||
if (isModifierKey && event.shiftKey && event.keyCode == 83) {
|
||||
event.preventDefault();
|
||||
if (typeof window.output === 'function') {
|
||||
window.output(null, saveAs);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+Z - 还原
|
||||
if (isModifierKey && !event.shiftKey && event.keyCode == 90) {
|
||||
event.preventDefault();
|
||||
$('#previous').click();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+Y - 重做
|
||||
if (isModifierKey && !event.shiftKey && event.keyCode == 89) {
|
||||
event.preventDefault();
|
||||
$('#next').click();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+C - 复制
|
||||
if (isModifierKey && event.keyCode == 67 && event.target.nodeName == 'BODY') {
|
||||
event.preventDefault();
|
||||
window.copySelection();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+V - 粘贴
|
||||
if (isModifierKey && event.keyCode == 86 && event.target.nodeName == 'BODY') {
|
||||
event.preventDefault();
|
||||
window.pasteFromClipboard();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+SHIFT+DEL (Windows) 或 CMD+SHIFT+Backspace (Mac) - 清空
|
||||
if (isModifierKey && event.shiftKey && (event.keyCode == 46 || event.keyCode == 8)) {
|
||||
event.preventDefault();
|
||||
$('#clean').click();
|
||||
return;
|
||||
}
|
||||
// CTRL/CMD+DEL (Windows) 或 CMD+Backspace (Mac) - 删除
|
||||
if (isModifierKey && !event.shiftKey && (event.keyCode == 46 || event.keyCode == 8)) {
|
||||
event.preventDefault();
|
||||
$('#delete').click();
|
||||
return;
|
||||
}
|
||||
// ui.js 特有的快捷键可以在这里添加
|
||||
}
|
||||
// 兼容三端的 modifier key 检测(Windows/Linux: Ctrl, Mac: Cmd/Meta)
|
||||
if (event.keyCode == 17 || event.metaKey) { // Ctrl 键或 Meta 键(Mac Cmd)
|
||||
@@ -439,6 +380,10 @@ $('#front_side').click(function () {
|
||||
recordObjs = recordObjs1
|
||||
recordJson = recordJson1
|
||||
step = step1
|
||||
// 同步到 window 对象,确保 recordState 使用正确的数组
|
||||
window.recordObjs = recordObjs1
|
||||
window.recordJson = recordJson1
|
||||
window.step = step1
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
}
|
||||
@@ -476,6 +421,10 @@ $('#back_side').click(function () {
|
||||
recordObjs = recordObjs2
|
||||
recordJson = recordJson2
|
||||
step = step2
|
||||
// 同步到 window 对象,确保 recordState 使用正确的数组
|
||||
window.recordObjs = recordObjs2
|
||||
window.recordJson = recordJson2
|
||||
window.step = step2
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
}
|
||||
@@ -894,147 +843,155 @@ $('#set_bg').click(function () {
|
||||
}
|
||||
})
|
||||
$('#previous').click(function () {
|
||||
// 正在应用历史(撤销/重做)时,直接忽略新的点击,防止并发操作
|
||||
if (window._isApplyingHistory) {
|
||||
return;
|
||||
}
|
||||
//撤销一次操作
|
||||
if (step.val == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
step.val--
|
||||
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
// 使用 recordJson1 和 recordObjs1
|
||||
if (recordObjs1 && recordObjs1[step.val]) {
|
||||
objs1 = JSON.parse(recordObjs1[step.val]);
|
||||
objs = objs1;
|
||||
// 同步更新 window 变量
|
||||
window.objs1 = objs1;
|
||||
window.objs = objs;
|
||||
}
|
||||
|
||||
if (recordJson1 && recordJson1[step.val]) {
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson1[step.val], function() {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 加载后更新列表和图标显示
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs1);
|
||||
}
|
||||
canvas.renderAll();
|
||||
})
|
||||
}
|
||||
if (recordObjs1 && recordObjs1[step.val]) {
|
||||
objs1 = JSON.parse(recordObjs1[step.val])
|
||||
objs = objs1
|
||||
// 调用状态恢复函数
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored();
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
}
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
// 使用 recordJson2 和 recordObjs2
|
||||
if (recordObjs2 && recordObjs2[step.val]) {
|
||||
objs2 = JSON.parse(recordObjs2[step.val]);
|
||||
objs = objs2;
|
||||
// 同步更新 window 变量
|
||||
window.objs2 = objs2;
|
||||
window.objs = objs;
|
||||
}
|
||||
|
||||
if (recordJson2 && recordJson2[step.val]) {
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson2[step.val], function() {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 加载后更新列表和图标显示
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs2);
|
||||
}
|
||||
canvas.renderAll();
|
||||
})
|
||||
}
|
||||
if (recordObjs2 && recordObjs2[step.val]) {
|
||||
objs2 = JSON.parse(recordObjs2[step.val])
|
||||
objs = objs2
|
||||
// 调用状态恢复函数
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored();
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
background_image = canvas.getObjects()[0]
|
||||
canvas.renderAll()
|
||||
//recordState();
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
}
|
||||
|
||||
selectObj(-1)
|
||||
|
||||
$('#base_control').hide()
|
||||
$('#line_control').hide()
|
||||
$('#pic_control').hide()
|
||||
$("#set_bg").hide();
|
||||
$('#out_pic_control').hide()
|
||||
$('#text_control').hide()
|
||||
$("#circle_text_control").hide();
|
||||
$('#out_text_control').hide()
|
||||
$('#rect_control').hide()
|
||||
$('#circle_control').hide()
|
||||
$('#counter_control').hide()
|
||||
$('#qrcode_Controll').hide()
|
||||
$('#barcode_controll').hide()
|
||||
})
|
||||
$('#next').click(function () {
|
||||
// 正在应用历史(撤销/重做)时,直接忽略新的点击,防止并发操作
|
||||
if (window._isApplyingHistory) {
|
||||
return;
|
||||
}
|
||||
//撤销一次撤销操作
|
||||
// 根据当前是正面还是背面检查对应的 recordObjs 长度
|
||||
let maxLen;
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
if (step.val >= recordObjs1.length - 1) {
|
||||
maxLen = recordObjs1 ? recordObjs1.length : 0;
|
||||
if (step.val >= maxLen - 1) {
|
||||
return
|
||||
}
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
if (step.val >= recordObjs2.length - 1) {
|
||||
maxLen = recordObjs2 ? recordObjs2.length : 0;
|
||||
if (step.val >= maxLen - 1) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
++step.val
|
||||
|
||||
if ($('#front_side').hasClass('ui-button-active')) {
|
||||
// 使用 recordJson1 和 recordObjs1
|
||||
if (recordObjs1 && recordObjs1[step.val]) {
|
||||
objs1 = JSON.parse(recordObjs1[step.val]);
|
||||
objs = objs1;
|
||||
// 同步更新 window 变量
|
||||
window.objs1 = objs1;
|
||||
window.objs = objs;
|
||||
}
|
||||
|
||||
if (recordJson1 && recordJson1[step.val]) {
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson1[step.val], function() {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 加载后更新列表和图标显示
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs1);
|
||||
}
|
||||
canvas.renderAll();
|
||||
})
|
||||
}
|
||||
if (recordObjs1 && recordObjs1[step.val]) {
|
||||
objs1 = JSON.parse(recordObjs1[step.val])
|
||||
objs = objs1
|
||||
// 调用状态恢复函数
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored();
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
}
|
||||
} else if ($('#back_side').hasClass('ui-button-active')) {
|
||||
// 使用 recordJson2 和 recordObjs2
|
||||
if (recordObjs2 && recordObjs2[step.val]) {
|
||||
objs2 = JSON.parse(recordObjs2[step.val]);
|
||||
objs = objs2;
|
||||
// 同步更新 window 变量
|
||||
window.objs2 = objs2;
|
||||
window.objs = objs;
|
||||
}
|
||||
|
||||
if (recordJson2 && recordJson2[step.val]) {
|
||||
window._isApplyingHistory = true;
|
||||
canvas.loadFromJSON(recordJson2[step.val], function() {
|
||||
// 加载后解锁所有对象(背景除外)
|
||||
if (typeof window.unlockAllObjects === 'function') {
|
||||
window.unlockAllObjects(canvas);
|
||||
}
|
||||
// 加载后更新列表和图标显示
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
// 重新生成二维码和条码(因为它们需要根据 objs 数据动态生成)
|
||||
if (typeof window.regenerateQrCodesAndBarcodes === 'function') {
|
||||
window.regenerateQrCodesAndBarcodes(canvas, objs2);
|
||||
}
|
||||
canvas.renderAll();
|
||||
})
|
||||
// 调用状态恢复函数
|
||||
if (typeof window.onStateRestored === 'function') {
|
||||
window.onStateRestored();
|
||||
}
|
||||
window._isApplyingHistory = false;
|
||||
});
|
||||
}
|
||||
if (recordObjs2 && recordObjs2[step.val]) {
|
||||
objs2 = JSON.parse(recordObjs2[step.val])
|
||||
objs = objs2
|
||||
}
|
||||
}
|
||||
background_image = canvas.getObjects()[0]
|
||||
canvas.renderAll()
|
||||
selectObj(-1)
|
||||
|
||||
$('#base_control').hide()
|
||||
$('#line_control').hide()
|
||||
$('#pic_control').hide()
|
||||
$("#set_bg").hide();
|
||||
$('#out_pic_control').hide()
|
||||
$('#text_control').hide()
|
||||
$("#circle_text_control").hide();
|
||||
$('#out_text_control').hide()
|
||||
$('#rect_control').hide()
|
||||
$('#circle_control').hide()
|
||||
$('#counter_control').hide()
|
||||
$('#qrcode_Controll').hide()
|
||||
$('#barcode_controll').hide()
|
||||
if (typeof window.updateList === 'function') {
|
||||
window.updateList();
|
||||
}
|
||||
})
|
||||
$('#clean').click(function () {
|
||||
@@ -1316,8 +1273,9 @@ $('#circle_stroke_transparent').click(function () {
|
||||
// cleanupSrcFields 函数已在 output.js 中定义
|
||||
|
||||
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') {
|
||||
@@ -1464,7 +1422,7 @@ function addBackground() {
|
||||
//pre_objs1.push(JSON.stringify(objs1));
|
||||
|
||||
recordObjs1.push(JSON.stringify(objs1))
|
||||
const props = window.TO_JSON_PROPERTIES || ['selectable', 'hoverable', 'hoverCursor', 'text', 'fontStyle', 'fontWeight', 'underline', 'evented'];
|
||||
const props = window.TO_JSON_PROPERTIES || ['selectable', 'hoverable', 'hoverCursor', 'text', 'fontStyle', 'fontWeight', 'underline', 'evented', 'linethrough', 'textBackgroundColor', 'diameter', 'flipped'];
|
||||
recordJson1.push(canvas1.toJSON(props))
|
||||
})
|
||||
// 类型改变
|
||||
@@ -1483,7 +1441,7 @@ function addBackground() {
|
||||
//pre_objs2.push(JSON.stringify(objs2));
|
||||
|
||||
recordObjs2.push(JSON.stringify(objs2))
|
||||
const props = window.TO_JSON_PROPERTIES || ['selectable', 'hoverable', 'hoverCursor', 'text', 'fontStyle', 'fontWeight', 'underline', 'evented'];
|
||||
const props = window.TO_JSON_PROPERTIES || ['selectable', 'hoverable', 'hoverCursor', 'text', 'fontStyle', 'fontWeight', 'underline', 'evented', 'linethrough', 'textBackgroundColor', 'diameter', 'flipped'];
|
||||
recordJson2.push(canvas2.toJSON(props))
|
||||
|
||||
let file = GetFile().get('file')
|
||||
@@ -1635,6 +1593,7 @@ function selectOutPic(target, index) {
|
||||
}
|
||||
|
||||
function addText(pointer) {
|
||||
// 设置默认字号为30px(像素值),这样显示的字号约为 30 * 72 / 300 = 7.2pt
|
||||
let text = new fabric.IText('TEXT', {
|
||||
//源:文本
|
||||
left: pointer.x,
|
||||
@@ -1643,6 +1602,7 @@ function addText(pointer) {
|
||||
textBackgroundColor: '',
|
||||
fontStyle: 'normal',
|
||||
fontWeight: 'normal',
|
||||
fontSize: 30,
|
||||
underline: false,
|
||||
linethrough: false,
|
||||
fontFamily: 'Arial'
|
||||
@@ -2405,7 +2365,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();
|
||||
@@ -2448,7 +2409,8 @@ $("#out_text_size").bind('input propertychange', function () {
|
||||
})
|
||||
$('#out_text_text').bind('input propertychange', function () {
|
||||
let val = $("#out_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();
|
||||
@@ -2565,7 +2527,8 @@ $('#line_dist').bind('input propertychange', function () {
|
||||
})
|
||||
$('#text_text').bind('input propertychange', function () {
|
||||
let val = $("#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