diff --git a/src/utils/zplGenerator.js b/src/utils/zplGenerator.js index 96f45f6..d4f9bee 100644 --- a/src/utils/zplGenerator.js +++ b/src/utils/zplGenerator.js @@ -441,6 +441,7 @@ export class ZPLGenerator { generateQRCodeZPL(element, x, y) { const orientation = this.config.qrcodeOrientation const data = element.data || '' + const showContent = element.showContent !== undefined ? element.showContent : false // 将毫米转换为ZPL尺寸单位,使用精确的DPI转换公式 // 二维码的尺寸参数是模块大小,通常1-10 @@ -459,15 +460,43 @@ export class ZPLGenerator { size = Math.max(size, 2) // 短数据使用较小尺寸 } - // 尝试使用更明确的二维码格式 - // 对于长数字内容,使用数字模式可能更有效 + let zpl = '' + + // 生成二维码 if (/^\d+$/.test(data)) { // 纯数字内容,使用数字模式 - return `^FO${x},${y}^BQ${orientation},2,${size}^FDMN,${data}^FS` + zpl = `^FO${x},${y}^BQ${orientation},2,${size}^FDMN,${data}^FS` } else { // 混合内容,使用自动模式 - return `^FO${x},${y}^BQ${orientation},2,${size}^FDMA,${data}^FS` + zpl = `^FO${x},${y}^BQ${orientation},2,${size}^FDMA,${data}^FS` + } + + // 如果需要显示明文,在二维码下方添加文本 + if (showContent && data) { + // 计算文本位置:二维码下方,居中对齐 + const textY = y + sizeInDots + 10 // 二维码下方留10个点的间距 + const fontSize = 15 // 根据二维码大小调整字体大小 + + // 设置中文字体支持 + zpl += `\n^CI28^CWJ,E:ARIAL.TTF^CFJ,${fontSize}` + + // 计算文本宽度以实现居中对齐 + const estimatedTextWidth = this.estimateTextWidth(data, fontSize) + let textX = x + Math.round((sizeInDots - estimatedTextWidth) / 2) + textX = Math.max(x, textX) // 确保不超出左边界 + + // 如果文本太长,使用多行显示 + if (data.length > 20) { + const lineWidth = Math.max(sizeInDots, estimatedTextWidth) + const lineRows = Math.min(3, Math.ceil(data.length / 20)) // 最多3行 + zpl += `\n^FO${x},${textY}^FB${lineWidth},${lineRows},0,C^CFJ,${fontSize}^FD${data}^FS` + } else { + // 单行文本 + zpl += `\n^FO${textX},${textY}^FD${data}^FS` + } } + + return zpl } diff --git a/src/views/modules/labelSetting/components/PropertyForm.vue b/src/views/modules/labelSetting/components/PropertyForm.vue index 5346040..0cb8ad5 100644 --- a/src/views/modules/labelSetting/components/PropertyForm.vue +++ b/src/views/modules/labelSetting/components/PropertyForm.vue @@ -396,17 +396,26 @@ - - - +
+ + + + + + + + + + +
diff --git a/src/views/modules/warehouse/ifsInventoryInit.vue b/src/views/modules/warehouse/ifsInventoryInit.vue index 5f752f2..e5591df 100644 --- a/src/views/modules/warehouse/ifsInventoryInit.vue +++ b/src/views/modules/warehouse/ifsInventoryInit.vue @@ -336,9 +336,15 @@ export default { type: 'success', duration: 1500 }) + let printLabelType; + if (this.createHuForm.partNo && this.createHuForm.partNo.startsWith("80")) { + printLabelType = '库存成品标签'; + } else { + printLabelType = 'BIL标签'; + } // 创建成功后进行打印 - this.printHandlingUnits(data.unitIds) + this.printHandlingUnits(data.unitIds,printLabelType) this.createHuVisible = false this.getDataList() @@ -353,7 +359,7 @@ export default { }) }, // 打印HandlingUnit标签 - async printHandlingUnits (unitIds) { + async printHandlingUnits (unitIds,printLabelType) { if (!unitIds || unitIds.length === 0) { return } @@ -361,7 +367,7 @@ export default { try { // 逐个打印每个HandlingUnit for (const unitId of unitIds) { - await this.printViaServer(unitId) + await this.printViaServer(unitId,printLabelType) } this.$message({ message: `成功打印 ${unitIds.length} 个HandlingUnit标签`, @@ -373,7 +379,7 @@ export default { } }, // 通过服务器打印 - async printViaServer(unitId) { + async printViaServer(unitId,printLabelType) { try { const printRequest = { reportId: this.reportId, @@ -384,7 +390,8 @@ export default { userId: localStorage.getItem('userName'), username: localStorage.getItem('userName'), site: localStorage.getItem('site'), - unitId: unitId + unitId: unitId, + labelType: printLabelType } const { data } = await printLabel(printRequest) if (data.code === 200) { diff --git a/src/views/modules/warehouse/labelQuery.vue b/src/views/modules/warehouse/labelQuery.vue index e520e21..c462a93 100644 --- a/src/views/modules/warehouse/labelQuery.vue +++ b/src/views/modules/warehouse/labelQuery.vue @@ -69,13 +69,13 @@ @@ -182,19 +182,18 @@ export default { // 重打标签 async reprintLabel(row) { - // 检查是否为未入库状态 - if (row.inStockFlag !== 'X') { - this.$message.warning('只有未入库状态的记录才能重打标签') - return - } - try { // 设置页面打印状态 this.printLoading = true this.loadingText = `${row.unitId} 打印中...` // 设置行打印状态 this.$set(row, 'printing', true) - + let printLabelType; + if (row.partNo && row.partNo.startsWith("80")) { + printLabelType = '库存成品标签'; + } else { + printLabelType = 'BIL标签'; + } const printRequest = { reportId: this.reportId, zplCode: this.zplCode,