From dd66769ae5dc56f6e6ffe71e1161b68ca8d59f5c Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Mon, 1 Sep 2025 10:52:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=AA=E5=90=91=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/coordinateTransform.js | 44 +++++++++++++----- src/utils/zplGenerator.js | 12 ++--- .../modules/labelSetting/LabelDesigner.vue | 45 ++++++++++++++++++- .../labelSetting/com_add_update_label.vue | 10 ++--- .../components/DataSourceDialog.vue | 8 +--- .../labelSetting/components/DesignCanvas.vue | 35 ++++----------- .../labelSetting/components/DesignElement.vue | 8 ++-- .../labelSetting/components/PaperSelector.vue | 1 + .../labelSetting/components/ZPLPreview.vue | 1 - .../modules/labelSetting/label_setting.vue | 45 ++++++++++++++----- 10 files changed, 134 insertions(+), 75 deletions(-) diff --git a/src/utils/coordinateTransform.js b/src/utils/coordinateTransform.js index 0ecd56c..4186ed9 100644 --- a/src/utils/coordinateTransform.js +++ b/src/utils/coordinateTransform.js @@ -18,7 +18,7 @@ export class CoordinateTransformer { */ getConfig() { let canvasSize - + this.paperId = localStorage.getItem('paperId') // 优先使用纸张ID if (this.paperId) { try { @@ -26,13 +26,21 @@ export class CoordinateTransformer { const { default: dynamicPaperConfig } = require('./paperConfigDynamic.js') const paper = dynamicPaperConfig.getPaperById(this.paperId) if (paper) { - const pixelSize = dynamicPaperConfig.calculatePixelSize(paper, 203, this.orientation) + const pixelSize = dynamicPaperConfig.calculatePixelSize(paper, 300, this.orientation) canvasSize = { width: pixelSize.width, height: pixelSize.height, name: paper.name, description: paper.description || '' } + console.log(`坐标转换器 - 纸张配置:`, { + paperId: this.paperId, + paperName: paper.name, + orientation: this.orientation, + originalSize: `${paper.widthMm}×${paper.heightMm}mm`, + pixelSize: `${pixelSize.width}×${pixelSize.height}px`, + dpi: 203 + }) } } catch (error) { console.warn('获取动态纸张配置失败,使用降级方案:', error) @@ -50,8 +58,14 @@ export class CoordinateTransformer { name: '自定义', description: `自定义尺寸 (${this.orientation === 'landscape' ? '横向' : '纵向'})` } + console.log(`坐标转换器 - 自定义尺寸:`, canvasSize) } else { canvasSize = getCanvasSize(this.paperType, this.orientation) + console.log(`坐标转换器 - 降级方案:`, { + paperType: this.paperType, + orientation: this.orientation, + canvasSize + }) } } @@ -67,7 +81,7 @@ export class CoordinateTransformer { canvasSize, scaleX: 1, scaleY: 1, - offsetX: Math.max(750, canvasSize.width * 0.8), + offsetX: 0, offsetY: 0 } } @@ -101,16 +115,19 @@ export class CoordinateTransformer { */ toZPL(canvasX, canvasY) { if (this.orientation === 'portrait') { - return { + // 纵向打印:直接映射 + const result = { x: Math.round(canvasX * this.config.scaleX), y: Math.round(canvasY * this.config.scaleY) - } + }; + return result; } else { - // 横向打印需要坐标旋转变换 - return { - x: Math.round(canvasX * this.config.scaleX), - y: Math.round(canvasY * this.config.scaleY) - } + const { width, height } = this.config.canvasSize; + const result = { + x: Math.round(canvasY * this.config.scaleX), + y: Math.round((width - canvasX-100) * this.config.scaleY) + }; + return result; } } @@ -122,15 +139,18 @@ export class CoordinateTransformer { */ toCanvas(zplX, zplY) { if (this.orientation === 'portrait') { + // 纵向打印:直接映射 return { x: Math.round(zplX / this.config.scaleX), y: Math.round(zplY / this.config.scaleY) } } else { // 横向打印的逆变换 + // 与修正后的 toZPL 方法对应的逆转换 + const { width, height } = this.config.canvasSize return { - x: Math.round(this.config.offsetX - (zplY / this.config.scaleY)), - y: Math.round(zplX / this.config.scaleX) + x: Math.round(zplY / this.config.scaleX), + y: Math.round((height - zplX) / this.config.scaleY) } } } diff --git a/src/utils/zplGenerator.js b/src/utils/zplGenerator.js index 64e771d..0045f51 100644 --- a/src/utils/zplGenerator.js +++ b/src/utils/zplGenerator.js @@ -412,9 +412,9 @@ export class ZPLGenerator { */ generateHorizontalLineZPL(element, x, y) { if (this.orientation === 'landscape') { - // 横向打印时需要特殊处理 - const adjustedY = Math.round(1200 - element.x) - element.width - return `^FO${x},${adjustedY}^FWR^GB${element.height},${element.width},3,B^FS` + // 横向打印时,由于使用了^FWB,横线在旋转后变成竖线 + // 使用标准的GB指令,坐标转换已经在coordinateTransform中处理 + return `^FO${x},${y}^GB${element.height},${element.width},3,B^FS` } else { return `^FO${x},${y}^GB${element.width},${element.height},3,B^FS` } @@ -425,9 +425,11 @@ export class ZPLGenerator { */ generateVerticalLineZPL(element, x, y) { if (this.orientation === 'landscape') { - return `^FO${x},${y}^FWR^GB${element.height},${element.width},3,B^FS` + // 横向打印时,由于使用了^FWB,竖线在旋转后变成横线 + // 使用标准的GB指令,坐标转换已经在coordinateTransform中处理 + return `^FO${x},${y}^GB${element.height},${element.width},3,B^FS` } else { - return `^FO${x},${y}^GB1,${element.height},${element.width},B^FS` + return `^FO${x},${y}^GB${element.width},${element.height},3,B^FS` } } diff --git a/src/views/modules/labelSetting/LabelDesigner.vue b/src/views/modules/labelSetting/LabelDesigner.vue index 636e30b..1c8b2a7 100644 --- a/src/views/modules/labelSetting/LabelDesigner.vue +++ b/src/views/modules/labelSetting/LabelDesigner.vue @@ -6,8 +6,13 @@
@@ -408,9 +413,17 @@ export default { console.log('使用默认DPI: 300') } - if (labelSetting.paperOrientation) { + // 处理打印方向,优先使用 prop 传入的值,然后是路由参数 + if (this.orientation && this.orientation !== 'portrait') { + // 如果组件prop已经指定了方向(如从label_draw2.vue传入的landscape),使用它 + console.log('使用组件prop指定的打印方向:', this.orientation) + } else if (labelSetting.paperOrientation) { this.orientation = labelSetting.paperOrientation - console.log('从路由参数设置打印方向:', labelSetting.paperOrientation) + console.log('从路由参数设置打印方向(paperOrientation):', labelSetting.paperOrientation) + } else if (labelSetting.printDirection) { + // 将中文打印方向转换为英文 + this.orientation = (labelSetting.printDirection === '横向打印' || labelSetting.printDirection === '横向设计') ? 'landscape' : 'portrait' + console.log('从路由参数设置打印方向(printDirection):', labelSetting.printDirection, '-> orientation:', this.orientation) } else { // 没有历史打印方向时,确保使用默认值 portrait this.orientation = 'portrait' @@ -729,6 +742,34 @@ export default { // 预览逻辑由PropertyPanel处理 }, + handleClearCanvas() { + if (this.elements.length === 0) { + this.$message.info('画布已经是空的') + return + } + + this.$confirm('确定要清空画布吗?此操作不可恢复。', '清空画布', { + confirmButtonText: '确定清空', + cancelButtonText: '取消', + type: 'warning', + dangerouslyUseHTMLString: true, + message: '
确定要清空画布吗?
此操作将删除所有设计元素,且不可恢复。
' + }).then(() => { + this.elements = [] + this.selectedIndex = -1 + this.$message.success('画布已清空') + }).catch(() => { + // 用户取消操作 + }) + }, + + handleClearSelection() { + if (this.selectedIndex >= 0) { + this.selectedIndex = -1 + this.$message.info('已取消选择') + } + }, + async handleDataSource(inData) { const response = await getViewFieldsByLabelType({ labelType: this.labelSettings.labelType, diff --git a/src/views/modules/labelSetting/com_add_update_label.vue b/src/views/modules/labelSetting/com_add_update_label.vue index 9c5b9ba..a9ca0a0 100644 --- a/src/views/modules/labelSetting/com_add_update_label.vue +++ b/src/views/modules/labelSetting/com_add_update_label.vue @@ -30,14 +30,14 @@ - + {{ buttons.searchButton }} @@ -194,24 +194,24 @@ export default { status: true, fixed: '' }, - /* { + { userId: this.$store.state.user.name, functionId: '100008001', - serialNumber: '100008001LabelLabelName', + serialNumber: '100008001LabelPrintDirection', tableId: '100008001Label', tableName: '标签自定义列表', columnProp: 'printDirection', headerAlign: 'center', align: 'center', columnLabel: '打印方向', - columnWidth: 140, + columnWidth: 100, columnHidden: false, columnImage: false, columnSortable: true, sortLv: 0, status: true, fixed: '' - },*/ + }, { userId: this.$store.state.user.name, functionId: '100008001', @@ -347,6 +347,7 @@ export default { labelName: '', labelType: '外箱标签', labelClass: '打印软件', + printDirection : '纵向设计', remark: '', addFlag: 'Y' }; @@ -404,12 +405,32 @@ export default { labelDrawModal(row){ let currentData = row; - if (currentData.printDirection === '横向打印') { - this.$router.push({ name: 'labelSetting-label_draw2', - params: {labelSetting: currentData}}) + + // 调试信息:显示当前标签的打印方向 + console.log('标签绘制跳转:', { + labelNo: currentData.labelNo, + printDirection: currentData.printDirection, + paperOrientation: currentData.paperOrientation + }); + + // 判断是否为横向打印 + const isLandscape = currentData.printDirection === '横向打印' || + currentData.printDirection === '横向设计' || + currentData.paperOrientation === 'landscape'; + + if (isLandscape) { + localStorage.setItem('paperId',currentData.paperId); + console.log('跳转到横向标签绘制页面'); + this.$router.push({ + name: 'labelSetting-label_draw2', + params: {labelSetting: currentData} + }); } else { - this.$router.push({ name: 'labelSetting-label_draw', - params: {labelSetting: currentData}}) + console.log('跳转到纵向标签绘制页面'); + this.$router.push({ + name: 'labelSetting-label_draw', + params: {labelSetting: currentData} + }); } }, @@ -500,7 +521,7 @@ export default { }; const result = await copyLabelSetting(copyData); - + if (result.data.code === 200) { this.refreshPageTables(); this.$message.success(`标签复制成功!新标签编号: ${result.data.data.newLabelNo}`);