From 9538e1a6b2d1237d002453a9e7ba54383dbbec77 Mon Sep 17 00:00:00 2001 From: linfso Date: Mon, 20 May 2024 00:31:11 +0800 Subject: [PATCH] md --- package.json | 6 +- src/utils/TanexPrinterSdk.js | 84 ++++++++----- .../emis/emisWaybill/waybillIsPrinted.vue | 114 ++++++++++++++---- 3 files changed, 148 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index 8abfd5a6..a33a380e 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,9 @@ "monaco-editor": "^0.34.1", "mxgraph-js": "^1.0.1", "nprogress": "0.2.0", + "pdf-lib": "^1.17.1", + "pdfjs-dist": "^2.5.207", + "print-js": "^1.6.0", "qrcodejs2": "^0.0.2", "quill": "1.3.7", "require.js": "^1.0.0", @@ -86,6 +89,7 @@ "vue": "2.7.0", "vue-amap": "^0.5.10", "vue-barcode": "^1.3.0", + "vue-buffer": "^0.0.1", "vue-clipboard2": "^0.3.3", "vue-count-to": "1.0.13", "vue-cropper": "0.5.5", @@ -93,7 +97,7 @@ "vue-i18n": "^8.28.2", "vue-meta": "2.4.0", "vue-okr-tree": "^1.0.17", - "vue-pdf": "^4.3.0", + "vue-pdf": "^4.2.0", "vue-print-nb": "^1.7.5", "vue-property-decorator": "^9.1.2", "vue-router": "3.4.9", diff --git a/src/utils/TanexPrinterSdk.js b/src/utils/TanexPrinterSdk.js index 1bc8483f..cddf64c9 100644 --- a/src/utils/TanexPrinterSdk.js +++ b/src/utils/TanexPrinterSdk.js @@ -15,16 +15,17 @@ import { download } from '@/utils/request' */ import { getToken } from '@/utils/auth' -import { forEach } from 'lodash'; class TanexPrinterSdk { VERSION="1.0.0" MAX_SENT_RETRY_COUNT = 9; - // WS_URL = "ws://127.0.0.1:17080"; + WS_URL = "ws://127.0.0.1:17080/ws"; // WS_URL = "ws://192.168.88.100:17080"; - WS_URL = "ws://192.168.88.100:17080/ws"; - HTTP_GET_PDF = "http://192.168.88.100:17080/api/downPdfFile"; + // WS_URL = "ws://192.168.88.100:17080/ws"; + // HTTP_GET_PDF = "http://192.168.88.100:17080/api/downPdfFile"; + HTTP_GET_PDF = "http://127.0.0.1:17080/api/downPdfFile"; + AUTH_TOKEN=null; @@ -114,14 +115,26 @@ class TanexPrinterSdk { return this.defaultPrinter; } + // 获取pdf链接 + getPdfUrl(ydSn,tplName,printerName){ + return this.HTTP_GET_PDF + '?ydSn=' + ydSn+"&tplName="+tplName+"&printerName="+printerName; + } + // 下载PDF文件 downPdfFile(ydSn,tplName,printerName){ let link = document.createElement('a'); link.style.display = 'none'; link.href = this.HTTP_GET_PDF + '?ydSn=' + ydSn+"&tplName="+tplName+"&printerName="+printerName; - window.open(link.href, '_blank'); - // document.body.appendChild(link); - // link.click(); + // window.open(link.href, '_blank'); + document.body.appendChild(link); + link.click(); + } + + // 批量打印 + batchPrint(tplName,printerName,orderList){ + if(tplName&&printerName&&orderList&&orderList.length>0){ + this.sendBatchPrintCMD(tplName,printerName,orderList); + } } @@ -132,7 +145,7 @@ class TanexPrinterSdk { printCmd['CMD']="setToken"; printCmd['Status']="1"; printCmd['Data']=getToken(); - console.log(JSON.stringify(printCmd)); + // console.log(JSON.stringify(printCmd)); this.send(JSON.stringify(printCmd),null); } @@ -148,7 +161,7 @@ class TanexPrinterSdk { "orderList":orderList.toString() } printCmd['Data']=printData - console.log(JSON.stringify(printCmd)); + // console.log(JSON.stringify(printCmd)); this.send(JSON.stringify(printCmd),null); } } @@ -159,7 +172,7 @@ class TanexPrinterSdk { printCmd['CMD']="getPrinterList"; printCmd['Status']="1"; printCmd['Data']=""; - console.log(JSON.stringify(printCmd)); + // console.log(JSON.stringify(printCmd)); this.send(JSON.stringify(printCmd),null); } @@ -169,7 +182,7 @@ class TanexPrinterSdk { printCmd['CMD']="getPrintTplList"; printCmd['Status']="1"; printCmd['Data']=""; - console.log(JSON.stringify(printCmd)); + // console.log(JSON.stringify(printCmd)); this.send(JSON.stringify(printCmd),null); } @@ -178,7 +191,7 @@ class TanexPrinterSdk { connect() { // 连接服务器 if (!window.WebSocket) { - console.log('您的浏览器不支持WebSocket'); + // console.log('您的浏览器不支持WebSocket'); return null; } @@ -187,22 +200,26 @@ class TanexPrinterSdk { this.ws = new WebSocket(this.WS_URL); this.ws.onerror = () => { - console.log("ws onerror!"); + // console.log("ws onerror!"); if(this.onErrorCallback.length>0){ this.onErrorCallback.forEach(callback=>{ - callback(); + if(callback!=null){ + callback(); + } }) } } this.ws.onopen = () => { - console.log("ws onopen!"); + // console.log("ws onopen!"); this.connected = true this.connectRetryCount = 0 if(this.onOpenCallback.length>0){ this.onOpenCallback.forEach(callback=>{ - callback(); + if(callback!=null){ + callback(); + } }) } @@ -212,18 +229,20 @@ class TanexPrinterSdk { }; this.ws.onpong = () => { - console.log("ws onpong!"); + // console.log("ws onpong!"); } this.ws.onclose = () => { - console.log("ws onclose!"); + // console.log("ws onclose!"); this.connected = false; this.connectRetryCount++; if(this.onCloseCallback.length>0){ this.onCloseCallback.forEach(callback=>{ - callback(); + if(callback!=null){ + callback(); + } }) } @@ -233,7 +252,7 @@ class TanexPrinterSdk { }; this.ws.onmessage = e => { - console.log('ws onmessage:' + e.data) + // console.log('ws onmessage:' + e.data) if (e.data.charAt(0) === "{") { var msg = this.jsonToObj(e.data); if(msg["CMD"]=='printerIsRead'){ @@ -246,7 +265,9 @@ class TanexPrinterSdk { if(this.onGetPrinterCallback.length>0){ this.onGetPrinterCallback.forEach(callback=>{ - callback(); + if(callback!=null){ + callback(); + } }) } @@ -255,7 +276,9 @@ class TanexPrinterSdk { this.innerGetPrintTplList(msg) if(this.onGetPrintTplCallback.length>0){ this.onGetPrintTplCallback.forEach(callback=>{ - callback(); + if(callback!=null){ + callback(); + } }) } } @@ -269,15 +292,14 @@ class TanexPrinterSdk { } } else { - console.log("数据格式非法:" + e.data); + // console.log("数据格式非法:" + e.data); } }; } catch (ex) { - debugger - if (console && console.log) { - console.log(ex); - } + // if (console && // console.log) { + // // console.log(ex); + // } } } @@ -286,10 +308,10 @@ class TanexPrinterSdk { } innerGetPrinterList(msg){ - console.log("innerGetPrinterList") + // console.log("innerGetPrinterList") if(msg){ this.printerList=[]; - console.log(msg); + // console.log(msg); msg.Data.printerList.forEach(item=>{ let optionItem={ @@ -303,7 +325,7 @@ class TanexPrinterSdk { } innerGetPrintTplList(msg){ - console.log("innerGetPrintTplList") + // console.log("innerGetPrintTplList") if(msg){ this.printTplList=[]; msg.Data.tplList.forEach(item=>{ @@ -345,7 +367,7 @@ class TanexPrinterSdk { this.ws.send(data) return 1; } else { - console.log("Ws is abnormal,send faild!!") + // console.log("Ws is abnormal,send faild!!") return -1 } } diff --git a/src/views/emis/emisWaybill/waybillIsPrinted.vue b/src/views/emis/emisWaybill/waybillIsPrinted.vue index 61b2f06e..cd4674b3 100644 --- a/src/views/emis/emisWaybill/waybillIsPrinted.vue +++ b/src/views/emis/emisWaybill/waybillIsPrinted.vue @@ -134,6 +134,7 @@
{{ printerStatusMessage }} {{ printerStatusMessage }} +
批量打印 + >打印 - - + + + @@ -427,11 +432,9 @@ --> - + + + @@ -442,11 +445,13 @@ import emisWaybillForm from '@/views/emis/emisWaybill/emisWaybillForm'; import elDateAdvPicker from '@/components/DatePickerAdv/elDateAdvPicker'; import CountryPicker0 from '@/views/emis/EmisBaseTools/CountryPicker.vue'; import CountryPicker1 from '@/views/emis/EmisBaseTools/CountryPicker.vue'; -// import pdf from 'vue-pdf' + +import PdfViewer from '@/components/PdfViewer/index.vue'; +import PdfUtils from '@/utils/pdfUtils' export default { name: "WaybillIsPrinted", - components: { elDateAdvPicker,emisWaybillForm,CountryPicker0,CountryPicker1 }, + components: { PdfViewer,elDateAdvPicker,emisWaybillForm,CountryPicker0,CountryPicker1 }, dicts: ['emis_waybill_status','emis_declare_mode','emis_customs_clear','emis_payment_type','emis_print_type' ], data() { @@ -472,7 +477,12 @@ export default { openForm: false, titleForm: "", + openPdfView:false, + pdfUrl:null, + + tanexPrinter:null, + printerDownUrl:null, printerStatus:0, printerStatusMessage:'打印组件未连接', printerList:[], @@ -665,6 +675,7 @@ export default { created() { this.getList(); this.initTanexPrinterSdk(); + }, beforeDestroy(){ this.tanexPrinter.close(); @@ -674,6 +685,10 @@ export default { this.tanexPrinter = this.$tanexPrinter; console.log( this.tanexPrinter); + this.getConfigKey("sys.printer.downurl").then(response => { + this.printerDownUrl = response.msg; + }); + this.tanexPrinter.init(); this.tanexPrinter.setOnOpen(this.onPrinterOpen); @@ -712,7 +727,7 @@ export default { handleBatchPrint(){ // 重要,设置为true才会把右上角X和取消区分开来 - this.$confirm("确定批量打印?", "提示", { + this.$confirm("确定打印?", "提示", { cancelButtonText: "不打印", confirmButtonText: "确定打印", type: "warning", @@ -727,15 +742,35 @@ export default { }).catch(() => {}); }, - handlePrintPreview(){ + async handlePrintPreview(){ + let pdfUrlList=[]; + this.currentSelection.forEach(item=>{ + let url=this.tanexPrinter.getPdfUrl(item.billCode,this.selTplName,this.selPrinterName); + pdfUrlList.push(url) + }); + let pdfUtils=new PdfUtils({}); + const loadingInstance = this.$loading({ + text: '正在生成预览...' + }) + pdfUtils.mergePdf2(pdfUrlList, (new Date()).getTime()+".pdf" ) + .then(url=>{ + loadingInstance.close(); + // this.pdfUrl='/static/pdfjs/dist/web/printPreview.html?file=' +encodeURIComponent(url); + this.pdfUrl=url; + this.openPdfView = true; + }) + .catch(error => { + }); }, handleDownPDF(){ - let orderList=[]; + let pdfUrlList=[]; this.currentSelection.forEach(item=>{ - orderList.push(item.billCode); - this.tanexPrinter.downPdfFile(item.billCode,this.selTplName,this.selPrinterName) + let url=this.tanexPrinter.getPdfUrl(item.billCode,this.selTplName,this.selPrinterName); + pdfUrlList.push(url) }); + let pdfUtils=new PdfUtils({}); + pdfUtils.mergePdf2(pdfUrlList, (new Date()).getTime()+".pdf" ,true); }, /** 查询运单列表列表 */ @@ -750,7 +785,7 @@ export default { }, onDateSelect(value){ - console.log("date picker---->", value) + // console.log("date picker---->", value) this.dateTimeRange=value; // scanDate }, @@ -896,4 +931,35 @@ export default { } } + .previe_dialog { + display: flex; + justify-content: center; + align-items: Center; + overflow: hidden; + .el-dialog .el-dialog__body { + margin: 8px!important; + padding: 0; + overflow: auto; + } + + .el-dialog { + margin: 0 auto !important; + height: 100%; + overflow: hidden; + .el-dialog__body { + margin: 0px 8px 8px 8px; + + position: absolute; + left: 0; + top: 54px; + bottom: 0; + right: 0; + padding: 0; + z-index: 1; + overflow: hidden; + overflow-y: auto; + } + } + } +