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 @@