This commit is contained in:
linfso 2024-05-19 12:07:15 +08:00
parent d04aa860c1
commit 56054d3ba4
5 changed files with 210 additions and 126 deletions

View File

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

View File

@ -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);
}
}

View File

@ -10,6 +10,7 @@
v-model="svalue"
:placeholder="placeholder"
style="width:100%"
@focus="onFocus"
@change="onChange">
<!-- allow-create -->
<div style="padding: 0px 8px 0 20px;width:100%;line-height:34px;display:inline-flex; border-bottom: 1px solid #e7e7e7;">
@ -17,10 +18,10 @@
<span style="font-size: 13px;font-weight: 600;">货物大类</span>
</div>
<div style="width:50%;text-align:right">
<el-button type="primary" size="mini" style="padding:2px 10px" @click="hideMe">确定</el-button>
<el-button type="primary" size="mini" style="padding:2px 10px" @click="confirmOk">确定</el-button>
</div>
</div>
<el-option v-for="item in optionItems" :key="item.id" :label="item.goodsName" :value="item.id">
<el-option v-for="item in optionItems" :key="item.goodsName" :label="item.goodsName" :value="item.goodsName">
</el-option>
</el-select>
<!-- <el-checkbox-group v-model="svalue">
@ -64,56 +65,53 @@
},
created() {
if(this.value) {
this.svalue = this.value.split(',');
}
this.queryData();
// if(this.value) {
// this.svalue = this.value.split(',');
// }
// this.queryData();
},
methods: {
hideMe(){
this.$refs.selectRef.blur();
},
onChange(val) {
let selData = [];
let selCodeStr = "";
confirmOk(){
let selIdStr="";
let selNameStr="";
let selData = [];
this.svalue.forEach(item=>{
let itemData=this.itemMap[item];
if(itemData!=null){
selData.push(itemData)
selCodeStr=selCodeStr+itemData.id+",";
selIdStr=selIdStr+itemData.goodsName+",";
selNameStr=selNameStr+itemData.goodsName+",";
}else{
// if( this.$refs.selectRef.createdLabel!=null ){
const itemData = {
goodsCode:'-1',
goodsName:item,
}
selData.push(itemData)
selCodeStr=selCodeStr+itemData.goodsName+",";
selNameStr=selNameStr+itemData.goodsName+",";
// }
}
});
selCodeStr = selCodeStr.substring(0,selCodeStr.length-1);
this.$emit('input', selCodeStr)
selIdStr = selIdStr.substring(0,selIdStr.length-1);
this.$emit('input', selIdStr)
this.$emit('onChange', selData,selNameStr)
this.$refs.selectRef.createdLabel = null
this.$refs.selectRef.blur();
},
onFocus(){
this.queryData();
},
onChange(val) {
},
queryData(queryVal) {
this.queryParams.pageNum=1;
this.queryParams.goodsName=queryVal;
listSimpleEmisGoods(this.queryParams).then(response => {
this.optionItems= response.rows
this.optionItems=response.rows
console.log(this.optionItems);
this.optionItems.forEach(item => {
if(!(id in this.itemMap)){
this.itemMap[item.id]=item;
if(!(item.goodsName in this.itemMap)){
this.itemMap[item.goodsName]=item;
}
});
});
},
}
};
</script>

View File

@ -282,7 +282,7 @@
</el-collapse-item>
<el-collapse-item title="" name="3">
<template slot="title">
<div class="form-group-title"><span class="title">{{ $t('重量收费信息') }}</span>
<div class="form-group-title"><span class="title">{{ $t('货物收费信息') }}</span>
</div>
</template>
<el-row :gutter="0" style="display: flex;flex-wrap: wrap;">
@ -304,7 +304,14 @@
<el-form-item label="总件数" prop="parcelQty" label-width="70px">
<el-input v-model="form.parcelQty" style="text-align: right;" placeholder="" />
</el-form-item>
</el-col>
</el-col>
<el-col :span="12">
<el-form-item label="实际重量" prop="billWeight" label-width="70px">
<el-input v-model="form.billWeight" @blur="reCalcSettlementWeight" style="text-align: right;min-width: 80px" placeholder="请输入实际重量" >
<span slot="suffix">(kg)</span>
</el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="" prop="goodsType" label-width="0px">
<!-- <GoodsSimplePicker v-model="form.goodsType" @onChange="onGoodsChange" placeholder="选择货物信息"></GoodsSimplePicker> -->
@ -374,13 +381,7 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="实际重量" prop="billWeight" label-width="70px">
<el-input v-model="form.billWeight" @blur="reCalcSettlementWeight" style="text-align: right;min-width: 80px" placeholder="请输入实际重量" >
<span slot="suffix">(kg)</span>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="总体积" prop="totalVolume" label-width="70px" >
<div style="">

View File

@ -130,13 +130,12 @@
</el-form-item>
</SearchForm>
<div style="padding:5px 0px;text-align: right;position: absolute;
top: 150px;
right: 10px;">
<!-- 打印机状态 -->
<div style="padding:5px 0px;text-align: right;position: fixed;top: 150px;right: 10px; z-index: 9999;">
<el-tag type="danger" v-if="printerStatus==0">{{ printerStatusMessage }}</el-tag>
<el-tag type="success" v-if="printerStatus==1">{{ printerStatusMessage }}</el-tag>
</div>
<XdTable v-loading="loading"
border stripe
size="small"
@ -674,17 +673,14 @@ export default {
initTanexPrinterSdk(){
this.tanexPrinter = this.$tanexPrinter;
console.log( this.tanexPrinter);
// openCallback, closeCallback,errorCallback,messageCallback
//tanexPrinterIns
let callbacks={
onOpen: this.onPrinterOpen,
onClose: this.onPrinterClose,
onError: this.onPrinterError,
getPrinterList:this.onGetPrinterList,
getPrinterTplList:this.onGetPrinterTplList
}
this.tanexPrinter.initSdk(callbacks);
this.tanexPrinter.init();
this.tanexPrinter.setOnOpen(this.onPrinterOpen);
this.tanexPrinter.setOnClose(this.onPrinterClose);
this.tanexPrinter.setOnError(this.onPrinterError);
this.tanexPrinter.setOnGetPrinter(this.onGetPrinter);
this.tanexPrinter.setOnGetPrintTpl(this.onGetPrintTpl);
},
onPrinterOpen(evt){
console.log("onPrinterOpen")
@ -703,33 +699,15 @@ export default {
this.printerStatusMessage="打印组件已断开!";
},
onGetPrinterList(msg){
console.log("onGetPrinterList")
if(msg){
this.printerList=[];
msg.Data.printerList.forEach(item=>{
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)
});
},
/** 查询运单列表列表 */