From 6a353e3e08fcc21c6be0793a1e80ab21a816d998 Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Tue, 23 Dec 2025 16:38:41 +0800 Subject: [PATCH] =?UTF-8?q?2025-12-23=20pda=E5=85=B6=E4=BB=96=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E6=8F=90=E4=BA=A4=E6=97=B6=E8=B0=83=E7=94=A8=E6=89=93?= =?UTF-8?q?=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mixins/labelPrintTemplates.js | 230 +++++++++++++++ src/utils/LodopFuncs.js | 267 +++++++++++++++--- .../other-inout/otherInboundDetail.vue | 89 +++++- static/config/index.js | 2 +- 4 files changed, 549 insertions(+), 39 deletions(-) create mode 100644 src/mixins/labelPrintTemplates.js diff --git a/src/mixins/labelPrintTemplates.js b/src/mixins/labelPrintTemplates.js new file mode 100644 index 0000000..1b3113a --- /dev/null +++ b/src/mixins/labelPrintTemplates.js @@ -0,0 +1,230 @@ +/** + * 标签打印模板 Mixin + * 提供 A001、A002、A003 三种标签打印模板的通用方法 + */ +export default { + methods: { + // A001 标签打印(70mm x 30mm)- 左边二维码,右边文字信息 + printLabelA001(LODOP, printData, isNewPage){ + if(isNewPage){ + LODOP.NEWPAGE(); + } + + // ============================================================ + // 1. 纸张设置 + // ============================================================ + // SET_PRINT_PAGESIZE(方向, 宽度, 高度, 纸张名称) + // 方向: 0=纵向, 1=横向 + // 宽度/高度: 单位为 1/10 毫米,如 700 = 70mm + LODOP.SET_PRINT_PAGESIZE(0, 700, 300, ''); + + // ============================================================ + // 2. 绘制边框和分隔线 + // ============================================================ + // ADD_PRINT_RECT(上边距, 左边距, 宽度, 高度, 边框样式, 边框粗细) + // 边框样式: 0=实线 + // 边框粗细: 单位为像素 + + // 外边框(1mm边距,68mm宽 x 28mm高) + LODOP.ADD_PRINT_RECT('1mm', '1mm', '68mm', '28mm', 0, 1); + + // ADD_PRINT_LINE(起点Y, 起点X, 终点Y, 终点X, 线条样式, 线条粗细) + // 线条样式: 0=实线 + + // 垂直分隔线:左右分隔(从上到下) + // 参数说明:起点(1mm, 22mm) -> 终点(29mm, 22mm) + LODOP.ADD_PRINT_LINE('1mm', '22mm', '29mm', '22mm', 0, 1); + + // 水平分隔线1:编码下方 + // 参数说明:起点(8mm, 22mm) -> 终点(8mm, 69mm) + LODOP.ADD_PRINT_LINE('8mm', '22mm', '8mm', '69mm', 0, 1); + + // 水平分隔线2:型号下方 + // 参数说明:起点(13mm, 22mm) -> 终点(13mm, 69mm) + LODOP.ADD_PRINT_LINE('13mm', '22mm', '13mm', '69mm', 0, 1); + + // 水平分隔线3:数量下方 + // 参数说明:起点(18mm, 22mm) -> 终点(18mm, 69mm) + LODOP.ADD_PRINT_LINE('18mm', '22mm', '18mm', '69mm', 0, 1); + + // 水平分隔线4:批号下方 + // 参数说明:起点(23mm, 22mm) -> 终点(23mm, 69mm) + LODOP.ADD_PRINT_LINE('23mm', '22mm', '23mm', '69mm', 0, 1); + + // ============================================================ + // 3. 左侧二维码 + // ============================================================ + // ADD_PRINT_BARCODE(上边距, 左边距, 宽度, 高度, 条码类型, 条码内容) + // 二维码位置:距上7mm,距左3mm,尺寸20mm x 20mm + const qrIndex = LODOP.ADD_PRINT_BARCODE('7mm', '3mm', '20mm', '20mm', 'QRCode', printData.rollNo || ''); + LODOP.SET_PRINT_STYLEA(qrIndex, "QRCodeVersion", 4); + LODOP.SET_PRINT_STYLEA(qrIndex, "QRCodeErrorLevel", "M"); + + // ============================================================ + // 4. 右侧文字信息(5行) + // ============================================================ + // ADD_PRINT_TEXT(上边距, 左边距, 宽度, 高度, 文字内容) + + // 文字起始X位置(左边距)和宽度 + const startX = '23mm'; // 可调整:文字左边距,增大向右移,减小向左移 + const textWidth = '43mm'; // 可调整:文字区域宽度 + + // 编码(第1行) + // 上边距4mm:可调整,增大向下移,减小向上移 + const text1 = LODOP.ADD_PRINT_TEXT('4mm', startX, textWidth, '4mm', `编码:${printData.partNo || ''}`); + LODOP.SET_PRINT_STYLEA(text1, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text1, "FontSize", 8); // 可调整:字体大小 + + // 型号(第2行) + // 上边距9mm:可调整 + const text2 = LODOP.ADD_PRINT_TEXT('9mm', startX, textWidth, '4mm', `型号:${printData.spec || ''}`); + LODOP.SET_PRINT_STYLEA(text2, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text2, "FontSize", 8); + + // 数量(第3行) + // 上边距14mm:可调整 + const text3 = LODOP.ADD_PRINT_TEXT('14mm', startX, textWidth, '4mm', `数量:${printData.quantity || ''}`); + LODOP.SET_PRINT_STYLEA(text3, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text3, "FontSize", 8); + + // 批号(第4行) + // 上边距19mm:可调整 + const text4 = LODOP.ADD_PRINT_TEXT('19mm', startX, textWidth, '4mm', `批号:${printData.batchNo || ''}`); + LODOP.SET_PRINT_STYLEA(text4, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text4, "FontSize", 8); + + // 日期(第5行) + // 上边距24mm:可调整 + const text5 = LODOP.ADD_PRINT_TEXT('24mm', startX, textWidth, '4mm', `日期:${printData.documentDate || ''}`); + LODOP.SET_PRINT_STYLEA(text5, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text5, "FontSize", 8); + }, + + // A002 标签打印(70mm x 20mm)- 其他工序用 + printLabelA002(LODOP, printData, isNewPage){ + if(isNewPage){ + LODOP.NEWPAGE(); + } + + // ============================================================ + // 1. 纸张设置 + // ============================================================ + // 设置纸张大小 70mm x 20mm (0=纵向) + LODOP.SET_PRINT_PAGESIZE(0, 700, 200, ''); + + // ============================================================ + // 2. 绘制边框 + // ============================================================ + // 外边框(1mm边距,68mm宽 x 18mm高) + LODOP.ADD_PRINT_RECT('1mm', '1mm', '68mm', '18mm', 0, 1); + + // ============================================================ + // 3. 左侧二维码 + // ============================================================ + // 二维码位置:距上1.6mm,距左3.4mm,尺寸18.2mm x 18.2mm + const qrIndex = LODOP.ADD_PRINT_BARCODE('1.6mm', '3.4mm', '18.2mm', '18.2mm', 'QRCode', printData.rollNo || ''); + LODOP.SET_PRINT_STYLEA(qrIndex, "QRCodeVersion", 4); + LODOP.SET_PRINT_STYLEA(qrIndex, "QRCodeErrorLevel", "M"); + + // ============================================================ + // 4. 右侧文字信息(4行)- 向左移动,字体缩小 + // ============================================================ + const startX = '22mm'; // 文字左边距(从23mm改为22mm,向左移动1mm) + const textWidth = '46mm'; // 文字区域宽度(从43mm增加到46mm) + + // 第1行:编码 + const text1 = LODOP.ADD_PRINT_TEXT('3mm', startX, textWidth, '3mm', `编码:${printData.partNo || ''}`); + LODOP.SET_PRINT_STYLEA(text1, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text1, "FontSize", 7); + + // 第2行:卷号 + const text2 = LODOP.ADD_PRINT_TEXT('7mm', startX, textWidth, '3mm', `卷号:${printData.rollNo || ''}`); + LODOP.SET_PRINT_STYLEA(text2, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text2, "FontSize", 7); + + // 第3行:良品 + 不良品(左右分布) + // 良品(左侧) + const text3 = LODOP.ADD_PRINT_TEXT('11mm', startX, '22mm', '3mm', `良品:${printData.goodQuantity || ''}`); + LODOP.SET_PRINT_STYLEA(text3, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text3, "FontSize", 7); + + // 不良品(右侧) + const text4 = LODOP.ADD_PRINT_TEXT('11mm', '44mm', '24mm', '3mm', `不良品:${printData.badQuantity || ''}`); + LODOP.SET_PRINT_STYLEA(text4, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text4, "FontSize", 7); + + // 第4行:总数 + 良率(左右分布) + // 总数(左侧) + const text5 = LODOP.ADD_PRINT_TEXT('15mm', startX, '22mm', '3mm', `总数:${printData.quantity || ''}`); + LODOP.SET_PRINT_STYLEA(text5, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text5, "FontSize", 7); + + // 良率(右侧) + const yieldValue = printData['yield'] || printData.yield || ''; + const yieldText = yieldValue ? `良率:${yieldValue}%` : '良率:'; + const text6 = LODOP.ADD_PRINT_TEXT('15mm', '44mm', '24mm', '3mm', yieldText); + LODOP.SET_PRINT_STYLEA(text6, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text6, "FontSize", 7); + }, + + // A003 标签打印(70mm x 20mm)- 绑定用 + printLabelA003(LODOP, printData, isNewPage){ + if(isNewPage){ + LODOP.NEWPAGE(); + } + + // ============================================================ + // 1. 纸张设置 + // ============================================================ + // 设置纸张大小 70mm x 20mm (0=纵向) + LODOP.SET_PRINT_PAGESIZE(0, 700, 200, ''); + + // ============================================================ + // 2. 绘制边框 + // ============================================================ + // 外边框(1mm边距,68mm宽 x 18mm高) + LODOP.ADD_PRINT_RECT('1mm', '1mm', '68mm', '18mm', 0, 1); + + // ============================================================ + // 3. 左侧二维码 + // ============================================================ + // 二维码位置:距上1.6mm,距左3.4mm,尺寸18.2mm x 18.2mm + const qrIndex = LODOP.ADD_PRINT_BARCODE('1.6mm', '3.4mm', '18.2mm', '18.2mm', 'QRCode', printData.rollNo || ''); + LODOP.SET_PRINT_STYLEA(qrIndex, "QRCodeVersion", 4); + LODOP.SET_PRINT_STYLEA(qrIndex, "QRCodeErrorLevel", "M"); + + // ============================================================ + // 4. 右侧文字信息(4行) + // ============================================================ + const startX = '23mm'; // 文字左边距 + const textWidth = '43mm'; // 文字区域宽度 + + // 第1行:ERP No. + const text1 = LODOP.ADD_PRINT_TEXT('3mm', startX, textWidth, '3mm', `ERP No.: ${printData.partNo || ''}`); + LODOP.SET_PRINT_STYLEA(text1, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text1, "FontSize", 8); + + // 第2行:Batch No. + Reel No.(左右分布) + // Batch No.(左侧) + const text2 = LODOP.ADD_PRINT_TEXT('7mm', startX, '20mm', '3mm', `Batch No.: ${printData.batchNo || ''}`); + LODOP.SET_PRINT_STYLEA(text2, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text2, "FontSize", 8); + + // Reel No.(右侧) + const text3 = LODOP.ADD_PRINT_TEXT('7mm', '43mm', '23mm', '3mm', `Reel No.: ${printData.reelNo || ''}`); + LODOP.SET_PRINT_STYLEA(text3, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text3, "FontSize", 8); + + // 第3行:Good QTY + const text4 = LODOP.ADD_PRINT_TEXT('11mm', startX, textWidth, '3mm', `Good QTY: ${printData.goodQuantity || ''}`); + LODOP.SET_PRINT_STYLEA(text4, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text4, "FontSize", 8); + + // 第4行:Bad QTY + const text5 = LODOP.ADD_PRINT_TEXT('15mm', startX, textWidth, '3mm', `Bad QTY: ${printData.badQuantity || ''}`); + LODOP.SET_PRINT_STYLEA(text5, "FontName", "Microsoft YaHei"); + LODOP.SET_PRINT_STYLEA(text5, "FontSize", 8); + } + } +} + diff --git a/src/utils/LodopFuncs.js b/src/utils/LodopFuncs.js index 22e2c88..73732b0 100644 --- a/src/utils/LodopFuncs.js +++ b/src/utils/LodopFuncs.js @@ -1,50 +1,249 @@ -import { MessageBox } from 'element-ui' - -// ====页面动态加载C-Lodop云打印必须的文件CLodopfuncs.js==== -var head = document.head || document.getElementsByTagName('head')[0] || document.documentElement -var oscript = document.createElement('script') -// 让本机的浏览器打印(更优先一点): -oscript = document.createElement('script') -oscript.src = 'http://localhost:8000/CLodopfuncs.js?priority=2' -head.insertBefore(oscript, head.firstChild) -// 加载双端口(8000和18000)避免其中某个端口被占用: -oscript = document.createElement('script') -oscript.src = 'http://localhost:18000/CLodopfuncs.js?priority=1' -head.insertBefore(oscript, head.firstChild) - -// 下载loadLodop +//==本JS是加载Lodop插件或Web打印服务CLodop/Lodop7的综合示例== +import { MessageBox } from 'element-ui' + +//用双端口加载主JS文件Lodop.js(或CLodopfuncs.js兼容老版本)以防其中某端口被占: +var MainJS = "CLodopfuncs.js", + URL_WS1 = "ws://192.168.1.147:8000/" + MainJS, //ws用8000/18000 + URL_WS2 = "ws://192.168.1.147:18000/" + MainJS, + URL_HTTP1 = "http://localhost:8000/" + MainJS, //http用8000/18000 + URL_HTTP2 = "http://localhost:18000/" + MainJS, + URL_HTTP3 = "https://localhost.lodop.net:8443/" + MainJS; //https用8000/8443 + +var CreatedOKLodopObject, CLodopIsLocal, LoadJsState; + +//==判断是否需要CLodop(那些不支持插件的浏览器):== +function needCLodop() { + try { + var ua = navigator.userAgent; + if (ua.match(/Windows\sPhone/i) || + ua.match(/iPhone|iPod|iPad/i) || + ua.match(/Android/i) || + ua.match(/Edge\D?\d+/i)) + return true; + var verTrident = ua.match(/Trident\D?\d+/i); + var verIE = ua.match(/MSIE\D?\d+/i); + var verOPR = ua.match(/OPR\D?\d+/i); + var verFF = ua.match(/Firefox\D?\d+/i); + var x64 = ua.match(/x64/i); + if ((!verTrident) && (!verIE) && (x64)) return true; + else if (verFF) { + verFF = verFF[0].match(/\d+/); + if ((verFF[0] >= 41) || (x64)) return true; + } else if (verOPR) { + verOPR = verOPR[0].match(/\d+/); + if (verOPR[0] >= 32) return true; + } else if ((!verTrident) && (!verIE)) { + var verChrome = ua.match(/Chrome\D?\d+/i); + if (verChrome) { + verChrome = verChrome[0].match(/\d+/); + if (verChrome[0] >= 41) return true; + } + } + return false; + } catch (err) { + return true; + } +} + +//==检查加载成功与否,如没成功则用http(s)再试== +function checkOrTryHttp() { + if (window.getCLodop) { + LoadJsState = "complete"; + return true; + } + if (LoadJsState == "loadingB" || LoadJsState == "complete") return; + LoadJsState = "loadingB"; + var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement; + var JS1 = document.createElement("script"), + JS2 = document.createElement("script"), + JS3 = document.createElement("script"); + JS1.src = URL_HTTP1; + JS2.src = URL_HTTP2; + JS3.src = URL_HTTP3; + JS1.onload = JS2.onload = JS3.onload = JS2.onerror = JS3.onerror = function() { + LoadJsState = "complete"; + } + JS1.onerror = function(e) { + if (window.location.protocol !== 'https:') + head.insertBefore(JS2, head.firstChild); + else + head.insertBefore(JS3, head.firstChild); + } + head.insertBefore(JS1, head.firstChild); +} + +//==加载Lodop对象的主过程:== +(function loadCLodop() { + if (!needCLodop()) return; + CLodopIsLocal = !!((URL_WS1 + URL_WS2).match(/\/\/localho|\/\/127.0.0./i)); + LoadJsState = "loadingA"; + if (!window.WebSocket && window.MozWebSocket) window.WebSocket = window.MozWebSocket; + //ws方式速度快(小于200ms)且可避免CORS错误,但要求Lodop版本足够新: + try { + var WSK1 = new WebSocket(URL_WS1); + WSK1.onopen = function(e) { setTimeout(checkOrTryHttp, 200); } + WSK1.onmessage = function(e) { if (!window.getCLodop) eval(e.data); } + WSK1.onerror = function(e) { + var WSK2 = new WebSocket(URL_WS2); + WSK2.onopen = function(e) { setTimeout(checkOrTryHttp, 200); } + WSK2.onmessage = function(e) { if (!window.getCLodop) eval(e.data); } + WSK2.onerror = function(e) { checkOrTryHttp(); } + } + } catch (e) { + checkOrTryHttp(); + } +})(); + +// 下载CLodop安装程序 function loadLodop() { - window.open('../../static/Lodop/CLodop_Setup_for_Win32NT.exe') + window.open(window.SITE_CONFIG['baseUrl'] + '/printer/download') } -// ====获取LODOP对象的主过程:==== -function getLodop() { - var LODOP +//==获取LODOP对象主过程== +function getLodop(oOBJECT, oEMBED) { + var LODOP; try { - LODOP = getCLodop() - //LODOP.SET_LICENSES("","13F0BE83846277CB60918577C6281375", "", ""); //重庆的Clodop授权 - //LODOP.SET_LICENSES("","15F0BE661E9473DF7491843CB334EB3D","",""); //苏州的Clodop授权 - //LODOP.SET_LICENSES("","7B5624CC84EF99D6B17F27DF4AF4310C", "", ""); //越南的Clodop授权 - let lodopCode = JSON.parse(localStorage.getItem('configParams')).lodopCode - LODOP.SET_LICENSES("",lodopCode, "", ""); - LODOP.SET_SHOW_MODE("LANGUAGE",1); - if (!LODOP && document.readyState !== 'complete') { - MessageBox.alert('C-Lodop打印控件还没准备好,请稍后再试!') - return + var isWinIE = (/MSIE/i.test(navigator.userAgent)) || (/Trident/i.test(navigator.userAgent)); + var isWinIE64 = isWinIE && (/x64/i.test(navigator.userAgent)); + var isLinuxX86 = (/Linux/i.test(navigator.platform)) && (/x86/i.test(navigator.platform)); + var isLinuxARM = (/Linux/i.test(navigator.platform)) && (/aarch/i.test(navigator.platform)); + + if (needCLodop() || isLinuxX86 || isLinuxARM) { + try { + LODOP = window.getCLodop(); + } catch (err) {} + + if (!LODOP) { + logger.info("LodopFuncs.js getLodop no CLodop"); + MessageBox({ + title: 'Information', + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Download', + cancelButtonText: 'Cancel', + zIndex: 3000, + message: "您没有安装打印组件或者您安装的版本不是最新版本,请下载并安装或升级,同时请检查相关服务是否已启动,最后请关闭并重新打开浏览器。", + callback: res => { + if (res === 'confirm') { + loadLodop(); + } + } + }); + return + } + + + // 检查版本是否需要升级 + var needUpgrade = false; + if (isLinuxX86 && LODOP.CVERSION < "7.1.0.5") needUpgrade = true; + else if (isLinuxARM && LODOP.CVERSION < "7.1.0.5") needUpgrade = true; + else if (typeof CLODOP !== 'undefined' && CLODOP.CVERSION < "6.6.2.8") needUpgrade = true; + + if (needUpgrade) { + MessageBox({ + title: 'Information', + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Download', + cancelButtonText: 'Cancel', + zIndex: 3000, + message: "您没有安装打印组件或者您安装的版本不是最新版本,请下载并安装或升级,同时请检查相关服务是否已启动,最后请关闭并重新打开浏览器。", + callback: res => { + if (res === 'confirm') { + loadLodop(); + } + } + }); + } + + if (LoadJsState !== "complete") { + if (!LoadJsState) { + MessageBox.alert('Lodop main JS file is not loaded, please call loadCLodop first.', 'Information', { type: 'warning' }); + } + return; + } + + } else { + //==如果页面有Lodop插件就直接使用,否则新建:== + if (oOBJECT || oEMBED) { + if (isWinIE) + LODOP = oOBJECT; + else + LODOP = oEMBED; + } else if (!CreatedOKLodopObject) { + LODOP = document.createElement("object"); + LODOP.setAttribute("width", 0); + LODOP.setAttribute("height", 0); + LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;"); + if (isWinIE) + LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA"); + else + LODOP.setAttribute("type", "application/x-print-lodop"); + document.documentElement.appendChild(LODOP); + CreatedOKLodopObject = LODOP; + } else { + LODOP = CreatedOKLodopObject; + } + + //==Lodop插件未安装时提示下载:== + if ((!LODOP) || (!LODOP.VERSION)) { + MessageBox({ + title: 'Information', + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Download', + cancelButtonText: 'Cancel', + zIndex: 3000, + message: "您没有安装打印组件或者您安装的版本不是最新版本,请下载并安装或升级,同时请检查相关服务是否已启动,最后请关闭并重新打开浏览器。", + callback: res => { + if (res === 'confirm') { + loadLodop(); + } + } + }); + return LODOP; + } + + if (LODOP.VERSION < "6.2.2.6") { + MessageBox({ + title: 'Information', + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Download', + cancelButtonText: 'Cancel', + zIndex: 3000, + message: "您没有安装打印组件或者您安装的版本不是最新版本,请下载并安装或升级,同时请检查相关服务是否已启动,最后请关闭并重新打开浏览器。", + callback: res => { + if (res === 'confirm') { + loadLodop(); + } + } + }); + } } - return LODOP + + //===如下空白位置适合调用统一功能(如注册语句、语言选择等):======================= + + // 设置 LODOP 授权许可(请填入实际授权信息后取消注释) + LODOP.SET_LICENSES("", "DA9F670A226A03FD22639678C43A5C73", "", ""); + + //=============================================================================== + return LODOP; } catch (err) { MessageBox({ - title: '温馨提示', + title: 'Information', type: 'warning', showCancelButton: true, - message: '您还未安装打印控件,点击确定下载打印控件,安装成功后刷新页面即可进行打印', + confirmButtonText: 'Download', + cancelButtonText: 'Cancel', + zIndex: 3000, + message: "您没有安装打印组件或者您安装的版本不是最新版本,请下载并安装或升级,同时请检查相关服务是否已启动,最后请关闭并重新打开浏览器。", callback: res => { if (res === 'confirm') { - loadLodop() + loadLodop(); } } - }) + }); } } diff --git a/src/views/modules/other-inout/otherInboundDetail.vue b/src/views/modules/other-inout/otherInboundDetail.vue index 856ecb6..4673b6c 100644 --- a/src/views/modules/other-inout/otherInboundDetail.vue +++ b/src/views/modules/other-inout/otherInboundDetail.vue @@ -311,8 +311,11 @@ import { getOtherInboundDetails, getMaterialList, validateLabelWithOtherInbound, import { getInventoryStock } from "@/api/inbound.js"; import { getCurrentWarehouse } from '@/utils' import moment from 'moment'; +import getLodop from '@/utils/LodopFuncs.js'; +import labelPrintTemplates from '@/mixins/labelPrintTemplates.js'; export default { + mixins: [labelPrintTemplates], data() { return { materialCode: '', @@ -577,7 +580,7 @@ export default { }, // 提交入库(通过存储过程GetSaveLabelVerification) - submitInbound() { + async submitInbound() { if (!this.locationCode.trim()) { this.$message.warning('请输入库位号'); return; @@ -589,18 +592,96 @@ export default { locationCode: this.locationCode.trim(), documentType: '其他入库' // 单据类型 }; - confirmOtherInbound(params).then(({ data }) => { + try { + const { data } = await confirmOtherInbound(params); if (data && data.code === 0) { this.$message.success('入库成功'); this.showLocationDialog = false; + + // 自动打印标签 + const printList = data.printList || []; + if (printList.length > 0) { + await this.printLabelsWithTemplate(printList); + } + this.$router.back(); } else { this.$message.error(data.msg || '入库失败'); } - }).catch(error => { + } catch (error) { console.error('入库失败:', error); this.$message.error('入库失败'); - }); + } + }, + + /** + * 使用模板打印标签 + * @param {Array} printList - 打印数据列表(存储过程UspPartLabelTemplate返回) + */ + async printLabelsWithTemplate(printList) { + try { + // 1. 获取打印机 + const LODOP = getLodop(); + if (!LODOP) { + console.warn('无法连接到打印控件,跳过打印'); + return; + } + + // 获取默认打印机 + const printerCount = LODOP.GET_PRINTER_COUNT(); + if (printerCount === 0) { + console.warn('未检测到打印机,跳过打印'); + return; + } + + // 2. 执行打印 + this.executePrintWithTemplate(LODOP, printList); + + this.$message.success('标签打印任务已发送!'); + + } catch (error) { + console.error('模板打印失败:', error); + this.$message.warning('标签打印失败,请手动打印'); + } + }, + + /** + * 执行模板打印 + * @param {Object} LODOP - 打印控件对象 + * @param {Array} printDataList - 打印数据列表 + * @param {String} printerName - 打印机名称 + */ + executePrintWithTemplate(LODOP, printDataList) { + console.log('开始打印,标签数量:', printDataList.length, '标签数据:', printDataList); + + // 循环打印每个标签(每个标签单独打印一次) + for (let i = 0; i < printDataList.length; i++) { + const printData = printDataList[i]; + + // 获取标签模板编号(存储过程返回) + const labelNo = printData.labelNo; + + // 每个标签单独初始化一个打印任务 + LODOP.PRINT_INIT('其他入库标签打印_' + (i + 1)); + + // 设置打印模式 + LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE", true); + + // 根据 labelNo 调用不同的打印方法(来自 labelPrintTemplates mixin) + // 注意:不需要 NEWPAGE,因为每个标签是独立的打印任务 + if (labelNo === 'A001') { + this.printLabelA001(LODOP, printData, false); + } else if (labelNo === 'A002') { + this.printLabelA002(LODOP, printData, false); + } else if (labelNo === 'A003') { + this.printLabelA003(LODOP, printData, false); + } + + // 执行打印 + LODOP.PRINT(); + + console.log(`第${i + 1}张标签已发送打印, 标签条码: ${printData.rollNo}`); + } }, // 取消入库 diff --git a/static/config/index.js b/static/config/index.js index 48229cf..de3e455 100644 --- a/static/config/index.js +++ b/static/config/index.js @@ -5,7 +5,7 @@ window.SITE_CONFIG = {}; // api接口请求地址 - window.SITE_CONFIG['baseUrl'] = 'http://127.0.0.1:9090/xujie-fast'; + window.SITE_CONFIG['baseUrl'] = 'http://127.0.0.1:9090'; // cdn地址 = 域名 + 版本号 window.SITE_CONFIG['domain'] = './'; // 域名