From 56054d3ba4fbad0d120e1213fdce1e0b44d3ec3e Mon Sep 17 00:00:00 2001 From: linfso Date: Sun, 19 May 2024 12:07:15 +0800 Subject: [PATCH] md --- .env.development | 4 +- src/utils/TanexPrinterSdk.js | 191 ++++++++++++++---- .../EmisBaseTools/GoodsMultiplePicker.vue | 58 +++--- .../emis/emisWaybill/emisWaybillRecord.vue | 19 +- .../emis/emisWaybill/waybillIsPrinted.vue | 64 +++--- 5 files changed, 210 insertions(+), 126 deletions(-) diff --git a/.env.development b/.env.development index 344e5378..e20f5b34 100644 --- a/.env.development +++ b/.env.development @@ -8,8 +8,8 @@ VUE_APP_VERSION = '20240516' # 开发环境 #VUE_APP_BASE_API = '/dev-api' VUE_APP_PDOMAIN = 'tanex56' -# VUE_APP_BASE_API = 'http://api.emis.tanex56.com/api/bizsvr' -VUE_APP_BASE_API = 'http://47.102.220.189:58089/api/bizsvr' +VUE_APP_BASE_API = 'http://api.emis.tanex56.com/api/bizsvr' +# VUE_APP_BASE_API = 'http://47.102.220.189:58089/api/bizsvr' # VUE_APP_BASE_API = 'http://47.96.189.20:58089/api/bizsvr' diff --git a/src/utils/TanexPrinterSdk.js b/src/utils/TanexPrinterSdk.js index bdb2a63a..1bc8483f 100644 --- a/src/utils/TanexPrinterSdk.js +++ b/src/utils/TanexPrinterSdk.js @@ -1,9 +1,10 @@ 'use strict' +import { download } from '@/utils/request' /* TanexPrinterSdk getPrinterList: 获取打印机列表 - getPrinterTplList: 获取打印模版列表 + getPrintTplList: 获取打印模版列表 batchPrint:发送打印 getPrinterVer:获取打印组件版本信息 @@ -14,13 +15,17 @@ */ 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://192.168.88.100:17080"; + // 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"; + AUTH_TOKEN=null; WS_INIT = 0; @@ -31,10 +36,13 @@ class TanexPrinterSdk { // 和服务端连接的socket对象 ws = null; // WS 回调函数 - onOpen =null; - onClose = null; - onError =null; - onMessage = null; + onOpenCallback =[]; + onCloseCallback=[]; + onErrorCallback =[]; + // onMessageCallback =[]; + + onGetPrinterCallback =[]; + onGetPrintTplCallback =[]; // 自定义 回调函数 callbacks ={} @@ -63,22 +71,62 @@ class TanexPrinterSdk { } return this.instance } - - initSdk(callbacks){ + // 外部方法---------------------------------------------------------------- + init(onOpen,onClose,onError,onGetPrinter,onGetPrintTpl,OnGetPrintTpl){ + // 初始化参数建立连接 this.token=getToken(); - this.callbacks=callbacks; - - this.onOpen=callbacks['onOpen']; - this.onClose=callbacks['onClose']; - this.onError=callbacks['onError']; - - this.callbacks['onGetPrinterList']=this.onGetPrinterList; - this.connect(); this.start(); } - sendToken(){ + setOnOpen(callback){ + this.onOpenCallback.push(callback); + } + + setOnClose(callback){ + this.onCloseCallback.push(callback); + } + + setOnError(callback){ + this.onErrorCallback.push(callback); + } + + setOnGetPrinter(callback){ + this.onGetPrinterCallback.push(callback); + } + + setOnGetPrintTpl(callback){ + this.onGetPrintTplCallback.push(callback); + } + + // 获取打印机列表 + getPrinterTplList(){ + return this.printerList; + } + + // 获取打印模版列表 + getPrintTplList(){ + return this.printTplList; + } + + // 获取默认打印机 + getDefaultPrinter(){ + return this.defaultPrinter; + } + + // 下载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(); + } + + + //--内部方法-------------------------------------------------------------- + sendSetTokenCMD(){ // {"CMD":"setToken","status":"1","Data":"token"} var printCmd={}; printCmd['CMD']="setToken"; @@ -88,7 +136,7 @@ class TanexPrinterSdk { this.send(JSON.stringify(printCmd),null); } - batchPrint(tplName,printerName,orderList){ + sendBatchPrintCMD(tplName,printerName,orderList){ // {"CMD":"batchPrint","status":"1","Data":["DT20210901001","DT20210901002"]} var printCmd={}; printCmd['CMD']="batchPrint"; @@ -105,24 +153,24 @@ class TanexPrinterSdk { } } - getPrinterList(callback){ + sendGetPrinterListCMD(){ // {"CMD":"getPrinterList","status":"1","Data":""} var printCmd={}; printCmd['CMD']="getPrinterList"; printCmd['Status']="1"; printCmd['Data']=""; console.log(JSON.stringify(printCmd)); - this.send(JSON.stringify(printCmd),callback); + this.send(JSON.stringify(printCmd),null); } - getPrinterTplList(callback){ - // {"CMD":"getPrinterTplList","status":"1","Data":""} + sendGetPrintTplListCMD(){ + // {"CMD":"getPrintTplList","status":"1","Data":""} var printCmd={}; - printCmd['CMD']="getPrinterTplList"; + printCmd['CMD']="getPrintTplList"; printCmd['Status']="1"; printCmd['Data']=""; console.log(JSON.stringify(printCmd)); - this.send(JSON.stringify(printCmd),callback); + this.send(JSON.stringify(printCmd),null); } @@ -140,8 +188,10 @@ class TanexPrinterSdk { this.ws.onerror = () => { console.log("ws onerror!"); - if(this.onError!=null){ - this.onError(); + if(this.onErrorCallback.length>0){ + this.onErrorCallback.forEach(callback=>{ + callback(); + }) } } this.ws.onopen = () => { @@ -150,23 +200,31 @@ class TanexPrinterSdk { this.connected = true this.connectRetryCount = 0 - if(this.onOpen != null){ - this.onOpen() + if(this.onOpenCallback.length>0){ + this.onOpenCallback.forEach(callback=>{ + callback(); + }) } - this.sendToken(); - this.getPrinterList(); - this.getPrinterTplList(); + this.sendSetTokenCMD(); + this.sendGetPrinterListCMD(); + this.sendGetPrintTplListCMD(); }; + this.ws.onpong = () => { + console.log("ws onpong!"); + } + this.ws.onclose = () => { console.log("ws onclose!"); this.connected = false; this.connectRetryCount++; - if(this.onClose != null){ - this.onClose() + if(this.onCloseCallback.length>0){ + this.onCloseCallback.forEach(callback=>{ + callback(); + }) } setTimeout(() => { @@ -175,18 +233,43 @@ 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'){ printerIsRead=true; - }else{ - if (this.callbacks[msg["CMD"]]) { - this.callbacks[msg["CMD"]](msg); } + else{ + + if(msg["CMD"]=='getPrinterList'){ + this.innerGetPrinterList(msg) + + if(this.onGetPrinterCallback.length>0){ + this.onGetPrinterCallback.forEach(callback=>{ + callback(); + }) + } + + } + if(msg["CMD"]=='getPrintTplList'){ + this.innerGetPrintTplList(msg) + if(this.onGetPrintTplCallback.length>0){ + this.onGetPrintTplCallback.forEach(callback=>{ + callback(); + }) + } + } + + + // 通知其他客户端 + // if (this.callbacks[msg["CMD"]]) { + // this.callbacks[msg["CMD"]](msg); + // } + + } } else { - console("数据格式非法:" + e.data); + console.log("数据格式非法:" + e.data); } }; @@ -202,21 +285,39 @@ class TanexPrinterSdk { return this.ws; } - onGetPrinterList(msg){ - console.log("onGetPrinterList") + innerGetPrinterList(msg){ + console.log("innerGetPrinterList") if(msg){ this.printerList=[]; + console.log(msg); + msg.Data.printerList.forEach(item=>{ let optionItem={ label:item, value:item } this.printerList.push(optionItem); - this.selPrinterName=msg.Data.defaultPrinter; + this.defaultPrinter=msg.Data.defaultPrinter; }) } } + innerGetPrintTplList(msg){ + console.log("innerGetPrintTplList") + if(msg){ + this.printTplList=[]; + msg.Data.tplList.forEach(item=>{ + let optionItem={ + label:item, + value:item + } + this.printTplList.push(optionItem); + this.selTplName=this.printTplList[0].value; + }) + } + } + + jsonToObj(json){ return JSON.parse(json) } @@ -260,9 +361,11 @@ class TanexPrinterSdk { // 开启心跳检测 start() { this.heartbeatInterval = setInterval(() => { - this.data = {type: "ping"}; - this.send(JSON.stringify(this.data)); - }, 5000); + if (this.getWSReadyState() === this.WS_OPEN ) { + // this.ws.ping(); + this.ws.send(0x9); + } + }, 10000); } } diff --git a/src/views/emis/EmisBaseTools/GoodsMultiplePicker.vue b/src/views/emis/EmisBaseTools/GoodsMultiplePicker.vue index 53e4a4c0..bbe45bfb 100644 --- a/src/views/emis/EmisBaseTools/GoodsMultiplePicker.vue +++ b/src/views/emis/EmisBaseTools/GoodsMultiplePicker.vue @@ -10,6 +10,7 @@ v-model="svalue" :placeholder="placeholder" style="width:100%" + @focus="onFocus" @change="onChange">
@@ -17,10 +18,10 @@ 货物大类
- 确定 + 确定
- + @@ -374,13 +381,7 @@ - - - - (kg) - - - +
diff --git a/src/views/emis/emisWaybill/waybillIsPrinted.vue b/src/views/emis/emisWaybill/waybillIsPrinted.vue index 9c34afa2..61b2f06e 100644 --- a/src/views/emis/emisWaybill/waybillIsPrinted.vue +++ b/src/views/emis/emisWaybill/waybillIsPrinted.vue @@ -130,13 +130,12 @@ - -
+ +
{{ printerStatusMessage }} {{ printerStatusMessage }}
+ { - let optionItem={ - label:item, - value:item - } - this.printerList.push(optionItem); - this.selPrinterName=msg.Data.defaultPrinter; - }) - } + onGetPrinter(msg){ + console.log("onGetPrinter") + this.printerList=this.tanexPrinter.getPrinterTplList(); + this.selPrinterName=this.tanexPrinter.getDefaultPrinter(); }, - onGetPrinterTplList(msg){ - console.log("onGetPrinterTplList") - if(msg){ - this.printTplList=[]; - msg.Data.tplList.forEach(item=>{ - let optionItem={ - label:item, - value:item - } - this.printTplList.push(optionItem); - this.selTplName=this.printTplList[0].value; - }) - } + onGetPrintTpl(msg){ + console.log("onGetPrintTpl") + this.printTplList=this.tanexPrinter.getPrintTplList(); + this.selTplName=this.printTplList[0].value; }, handleBatchPrint(){ @@ -753,7 +731,11 @@ export default { }, handleDownPDF(){ - + let orderList=[]; + this.currentSelection.forEach(item=>{ + orderList.push(item.billCode); + this.tanexPrinter.downPdfFile(item.billCode,this.selTplName,this.selPrinterName) + }); }, /** 查询运单列表列表 */