优化调整bug与加密

This commit is contained in:
24kycj
2026-01-11 01:06:02 +08:00
parent f4aef8abaa
commit c26c4fa66e
19 changed files with 124 additions and 966 deletions
+79 -76
View File
@@ -566,7 +566,7 @@ $('#center_y_alignment').click(function () {
let itemMaxY = getCoordsMaxY(coords)
if (itemMinY < minTop) minTop = itemMinY
if (itemMaxY > maxBottom) maxBottom = itemMaxY
}
}
let groupCenterY = (minTop + maxBottom) / 2
// 将所有对象对齐到中心Y值
groupItems = []
@@ -713,7 +713,7 @@ $('#center_x_alignment').click(function () {
let itemMaxX = getCoordsMaxX(coords)
if (itemMinX < minLeft) minLeft = itemMinX
if (itemMaxX > maxRight) maxRight = itemMaxX
}
}
let groupCenterX = (minLeft + maxRight) / 2
// 将所有对象对齐到中心X值
groupItems = []
@@ -750,8 +750,8 @@ $('#up_obj').click(function () {
recordState()
if (typeof window.updateList === 'function') {
window.updateList();
}
window.updateList();
}
if (typeof window.selectObj === 'function') {
window.selectObj(idx);
}
@@ -770,8 +770,8 @@ $('#down_obj').click(function () {
objs[idx - 2] = temp
recordState()
if (typeof window.updateList === 'function') {
window.updateList();
}
window.updateList();
}
if (typeof window.selectObj === 'function') {
window.selectObj(idx - 2);
}
@@ -814,7 +814,7 @@ $('#set_bg').click(function () {
canvas.renderAll()
let objItem = objs.splice(idx - 1, 1)[0]
objs.unshift(objItem)
// 确保背景图(索引0)的锁定属性被正确设置
setTimeout(() => {
let bgObj = canvas.getObjects()[0];
@@ -833,7 +833,7 @@ $('#set_bg').click(function () {
canvas.renderAll();
}
}, 100);
recordState()
if (typeof window.updateList === 'function') {
window.updateList();
@@ -853,7 +853,7 @@ $('#previous').click(function () {
}
step.val--
if ($('#front_side').hasClass('ui-button-active')) {
// 使用 recordJson1 和 recordObjs1
if (recordObjs1 && recordObjs1[step.val]) {
@@ -863,10 +863,10 @@ $('#previous').click(function () {
window.objs1 = objs1;
window.objs = objs;
}
if (recordJson1 && recordJson1[step.val]) {
window._isApplyingHistory = true;
canvas.loadFromJSON(recordJson1[step.val], function() {
canvas.loadFromJSON(recordJson1[step.val], function () {
// 加载后解锁所有对象(背景除外)
if (typeof window.unlockAllObjects === 'function') {
window.unlockAllObjects(canvas);
@@ -891,10 +891,10 @@ $('#previous').click(function () {
window.objs2 = objs2;
window.objs = objs;
}
if (recordJson2 && recordJson2[step.val]) {
window._isApplyingHistory = true;
canvas.loadFromJSON(recordJson2[step.val], function() {
canvas.loadFromJSON(recordJson2[step.val], function () {
// 加载后解锁所有对象(背景除外)
if (typeof window.unlockAllObjects === 'function') {
window.unlockAllObjects(canvas);
@@ -923,7 +923,7 @@ $('#next').click(function () {
if ($('#front_side').hasClass('ui-button-active')) {
maxLen = recordObjs1 ? recordObjs1.length : 0;
if (step.val >= maxLen - 1) {
return
return
}
} else if ($('#back_side').hasClass('ui-button-active')) {
maxLen = recordObjs2 ? recordObjs2.length : 0;
@@ -935,7 +935,7 @@ $('#next').click(function () {
}
++step.val
if ($('#front_side').hasClass('ui-button-active')) {
// 使用 recordJson1 和 recordObjs1
if (recordObjs1 && recordObjs1[step.val]) {
@@ -945,10 +945,10 @@ $('#next').click(function () {
window.objs1 = objs1;
window.objs = objs;
}
if (recordJson1 && recordJson1[step.val]) {
window._isApplyingHistory = true;
canvas.loadFromJSON(recordJson1[step.val], function() {
canvas.loadFromJSON(recordJson1[step.val], function () {
// 加载后解锁所有对象(背景除外)
if (typeof window.unlockAllObjects === 'function') {
window.unlockAllObjects(canvas);
@@ -973,10 +973,10 @@ $('#next').click(function () {
window.objs2 = objs2;
window.objs = objs;
}
if (recordJson2 && recordJson2[step.val]) {
window._isApplyingHistory = true;
canvas.loadFromJSON(recordJson2[step.val], function() {
canvas.loadFromJSON(recordJson2[step.val], function () {
// 加载后解锁所有对象(背景除外)
if (typeof window.unlockAllObjects === 'function') {
window.unlockAllObjects(canvas);
@@ -1464,7 +1464,7 @@ function selectObject(target, index) {
function updateControls() {
// 检查是否有选中对象,如果没有则直接返回
if (!canvas || !canvas.getActiveObject()) return;
const activeObj = canvas.getActiveObject();
$('#text_r').val(activeObj.get('angle').toFixed(0))
$('#text_x').val((activeObj.get('left') - background_image.left).toFixed(0))
@@ -1517,20 +1517,20 @@ function addPic(pointer) {
function selectPic(target, index) {
// 检查是否有选中对象,如果没有则直接返回
if (!canvas || !canvas.getActiveObject()) return;
let activeObj = canvas.getActiveObject();
// 检查对象是否被锁定
if (isObjectLocked(activeObj)) {
canvas.discardActiveObject();
canvas.renderAll();
return;
}
//透明度
$('#pic_control').show()
$("#set_bg").show();
// 检查 pic_op 是否存在且有 setValue 方法
if (typeof pic_op !== 'undefined' && pic_op && typeof pic_op.setValue === 'function') {
pic_op.setValue(100 - activeObj.get('opacity') * 100);
@@ -1565,8 +1565,8 @@ function addOutPic(pointer) {
objs.push({ type: 2, name: resName('OUT_PIC_'), black: false })
canvas.renderAll()
if (typeof window.updateList === 'function') {
window.updateList();
}
window.updateList();
}
recordState()
})
})
@@ -1987,8 +1987,8 @@ function addQrCode(pointer) {
objs.push({ type: 8, name: resName('QR_CODE_'), color: '#000000', val: 'http://www.cardsoon.com', black: false })
canvas.renderAll()
if (typeof window.updateList === 'function') {
window.updateList();
}
window.updateList();
}
recordState()
})
}
@@ -2022,8 +2022,8 @@ function addBarCode(pointer) {
objs.push({ type: 9, name: resName('BAR_CODE_'), val: '123456789', color: '#000000', fontSize: 18, font: 'Arial', show: false, black: false }) //show是取消文字显示
canvas.renderAll()
if (typeof window.updateList === 'function') {
window.updateList();
}
window.updateList();
}
recordState()
})
}
@@ -2285,7 +2285,7 @@ $('#qrcode_color').bind('input propertychange', function () {
recordState()
})
})
$("#qrcode_val").bind('change', function () {
$("#qrcode_val").bind('input propertychange', function () {
let val = $(this).val() ? $(this).val() : 'https://www.cardsoon.com'
let item = canvas.getActiveObject();
let qr = jrQrcode.getQrBase64(val, { padding: 0, foreground: $("#qrcode_color").val() });
@@ -2551,14 +2551,17 @@ $('#barcode_val').bind('input propertychange', function () {
$("#barcode_show").click(function () {
let item = canvas.getActiveObject();
let idx = getIndex(canvas.getActiveObject());
let val = $("#barcode_size").val()
let val = $("#barcode_size").val();
let displayValue = true;
if ($(this).prop("checked")) {
objs[idx - 1].show = true;
val = 0
displayValue = false;
} else {
objs[idx - 1].show = false;
displayValue = true;
}
JsBarcode("#barcode", objs[idx - 1].val, { margin: 0, lineColor: objs[idx - 1].color, fontSize: val * dpi / 72, font: objs[idx - 1].font });
// val = 0; // Remove this hack
JsBarcode("#barcode", objs[idx - 1].val, { margin: 0, lineColor: objs[idx - 1].color, fontSize: val * dpi / 72, font: objs[idx - 1].font, displayValue: displayValue });
let barcode = document.getElementById('barcode');
let bar = barcode.toDataURL("image/png");
item.setSrc(bar, function (img) {
@@ -2755,47 +2758,47 @@ $("#output").click(function () {
if (typeof window._design2CanvasEventsInitialized === 'undefined') {
window._design2CanvasEventsInitialized = true;
// 所有 canvas 事件已在 core.js 的 initCanvasEvents() 中统一处理,这里不再重复监听
// 如果需要 canvas1 特定的 mouse:move 处理,可以在这里添加
canvas1.on('mouse:move', (e) => {
if (!e.pointer || typeof background_image === 'undefined' || !background_image) return;
let width = canvas.getWidth()
let height = canvas.getHeight()
$('#posText').text(
'X: ' + (e.pointer.x - (width / 2 - (width / 2 - background_image.left) * zoom)).toFixed(0) + ' Y: ' + (e.pointer.y - (height / 2 - (height / 2 - background_image.top) * zoom)).toFixed(0)
)
})
// 注意:以下事件已在 core.js 的 initCanvasEvents() 中统一处理,移除重复监听以避免冲突:
// - mouse:down (通过 handleObjectSelected 处理)
// - object:scaling, object:rotating, object:rotated
// - text:editing:entered, text:editing:exited
// - object:modified (已在 core.js 中处理)
// - mouse:up (已在 core.js 中处理)
// 如果需要 canvas1 特定的处理逻辑,请修改 core.js 中的相应函数
// 所有 canvas 事件已在 core.js 的 initCanvasEvents() 中统一处理,这里不再重复监听
// 如果需要 canvas1 特定的 mouse:move 处理,可以在这里添加
canvas1.on('mouse:move', (e) => {
if (!e.pointer || typeof background_image === 'undefined' || !background_image) return;
let width = canvas.getWidth()
let height = canvas.getHeight()
$('#posText').text(
'X: ' + (e.pointer.x - (width / 2 - (width / 2 - background_image.left) * zoom)).toFixed(0) + ' Y: ' + (e.pointer.y - (height / 2 - (height / 2 - background_image.top) * zoom)).toFixed(0)
)
})
// 注意:以下事件已在 core.js 的 initCanvasEvents() 中统一处理,移除重复监听以避免冲突:
// - mouse:down (通过 handleObjectSelected 处理)
// - object:scaling, object:rotating, object:rotated
// - text:editing:entered, text:editing:exited
// - object:modified (已在 core.js 中处理)
// - mouse:up (已在 core.js 中处理)
// 如果需要 canvas1 特定的处理逻辑,请修改 core.js 中的相应函数
// 保留 canvas1 特定的 after:render 处理
canvas1.on('after:render', function () {
if (is_bgi_add) {
var image = document.getElementById('source_front')
ctx1.drawImage(image, (canvas.width - $('#source_front').width()) / 2, (canvas.height - $('#source_front').height()) / 2, $('#source_front').width(), $('#source_front').height())
}
})
// 保留 canvas1 特定的 text:changed 处理
canvas1.on('text:changed', (e) => {
$('#text_text').val(e.target.get('text'))
})
// 保留 canvas2 特定的 after:render 处理
canvas2.on('after:render', function () {
if (is_bgi_add) {
var image = document.getElementById('source_back')
ctx2.drawImage(image, (canvas.width - $('#source_back').width()) / 2, (canvas1.height - $('#source_back').height()) / 2, $('#source_back').width(), $('#source_back').height())
}
})
// 注意:以下事件已在 core.js 的 initCanvasEvents() 中统一处理,移除重复监听以避免冲突:
// - mouse:down (通过 handleObjectSelected 处理)
// - mouse:up (已在 core.js 中处理)
// - object:scaling, object:rotating, object:rotated, object:added
// - text:editing:entered, text:editing:exited
// - object:modified (已在 core.js 中处理)
// 如果需要 canvas2 特定的处理逻辑,请修改 core.js 中的相应函数
// 保留 canvas1 特定的 after:render 处理
canvas1.on('after:render', function () {
if (is_bgi_add) {
var image = document.getElementById('source_front')
ctx1.drawImage(image, (canvas.width - $('#source_front').width()) / 2, (canvas.height - $('#source_front').height()) / 2, $('#source_front').width(), $('#source_front').height())
}
})
// 保留 canvas1 特定的 text:changed 处理
canvas1.on('text:changed', (e) => {
$('#text_text').val(e.target.get('text'))
})
// 保留 canvas2 特定的 after:render 处理
canvas2.on('after:render', function () {
if (is_bgi_add) {
var image = document.getElementById('source_back')
ctx2.drawImage(image, (canvas.width - $('#source_back').width()) / 2, (canvas1.height - $('#source_back').height()) / 2, $('#source_back').width(), $('#source_back').height())
}
})
// 注意:以下事件已在 core.js 的 initCanvasEvents() 中统一处理,移除重复监听以避免冲突:
// - mouse:down (通过 handleObjectSelected 处理)
// - mouse:up (已在 core.js 中处理)
// - object:scaling, object:rotating, object:rotated, object:added
// - text:editing:entered, text:editing:exited
// - object:modified (已在 core.js 中处理)
// 如果需要 canvas2 特定的处理逻辑,请修改 core.js 中的相应函数
}