|
|
@@ -8,15 +8,17 @@
|
|
|
<div class="card-header">
|
|
|
<div class="form-group">
|
|
|
<label class="form-inline" for="printStr"></label>
|
|
|
- <input type="text" name="printStr" class="form-control" ref="printStr" id="printStr" placeholder="输入波次号,订单号,">
|
|
|
+ <input type="text" name="printStr" class="form-control" ref="printStr" id="printStr"
|
|
|
+ placeholder="输入波次号,订单号,">
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="card-body">
|
|
|
<button class="btn btn-primary" @click="getPrintItems">获取</button>
|
|
|
- <button class="btn btn-outline-info" @click="wsGetImage">GoWebSocket 预览</button>
|
|
|
+ <button class="btn btn-outline-info" @click="testPreview"> 预览</button>
|
|
|
<button class="btn btn-outline-primary" @click="uploadPrintData">WAS加工</button>
|
|
|
<button class="btn btn-success" @click="wsPrintImage">GoWebSocket 打印</button>
|
|
|
- {{--<button class="btn btn-outline-warning" @click="initGoWebSocket">GoWebSocket 重置</button>--}}
|
|
|
+ <button class="btn btn-outline-warning" @click="initGoWebSocket">GoWebSocket 重置</button>
|
|
|
+ <button class="btn btn-outline-warning" @click="getPrinters">获取打印机</button>
|
|
|
</div>
|
|
|
|
|
|
<div class="container">
|
|
|
@@ -43,7 +45,7 @@
|
|
|
<p> 编号:@{{ item.task_id }}</p>
|
|
|
<p> 快递单号 :@{{ item.logistic_number }}</p>
|
|
|
<div v-if="item.base64" class="position-relative">
|
|
|
- <img :src="'data:image/jpeg;base64,'+item.base64" alt="" style="width: 50%;height: 50%"
|
|
|
+ <img :src="item.base64" alt="" style="width: 50%;height: 50%"
|
|
|
class="position-relative">
|
|
|
</div>
|
|
|
</li>
|
|
|
@@ -58,6 +60,11 @@
|
|
|
|
|
|
@section('lastScript')
|
|
|
<script>
|
|
|
+ let WebSocketStatus = {
|
|
|
+ Close: 0,
|
|
|
+ Open: 1,
|
|
|
+ Error: 2,
|
|
|
+ }
|
|
|
let vue = new Vue({
|
|
|
el: '#list',
|
|
|
data: {
|
|
|
@@ -65,15 +72,63 @@
|
|
|
goWebSocketPath: "ws://127.0.0.1:11101/print",
|
|
|
goWebSocket: null,
|
|
|
goWebSocketStatus: 0,
|
|
|
+
|
|
|
+ cnWebSocket: null,
|
|
|
+ cnWebSocketPath: "ws://127.0.0.1:13528",
|
|
|
+ cnWebSocketStatus: null,
|
|
|
+ pddWebSocket: null,
|
|
|
+ pddWebSocketPath: "ws://127.0.0.1:5000",
|
|
|
+ pddWebSocketStatus: null,
|
|
|
+
|
|
|
+ clientPrinters: {
|
|
|
+ defaultPrinter: "",
|
|
|
+ printers: [],
|
|
|
+ },
|
|
|
},
|
|
|
created() {
|
|
|
|
|
|
},
|
|
|
mounted() {
|
|
|
// 初始化 go 链接
|
|
|
- this.initGoWebSocket();
|
|
|
+ // this.initGoWebSocket();
|
|
|
+ this.initPddWebSocket();
|
|
|
+ this.initCnWebSocket();
|
|
|
+
|
|
|
},
|
|
|
methods: {
|
|
|
+ initPddWebSocket() {
|
|
|
+ if (this.pddWebSocket && this.pddWebSocket.readyState === 2) return
|
|
|
+ this.pddWebSocket = new window.WebSocket(this.pddWebSocketPath)
|
|
|
+ let self = this;
|
|
|
+ this.pddWebSocket.onclose = function () {
|
|
|
+ self.pddWebSocketStatus = WebSocketStatus.Close
|
|
|
+ }
|
|
|
+ this.pddWebSocket.onopen = function () {
|
|
|
+ self.getPrinters()
|
|
|
+ self.pddWebSocketStatus = WebSocketStatus.Open
|
|
|
+ }
|
|
|
+ this.pddWebSocket.onerror = function (message) {
|
|
|
+ self.pddWebSocketStatus = WebSocketStatus.Error
|
|
|
+ }
|
|
|
+ this.pddWebSocket.onmessage = this.handlerPddWebsocket
|
|
|
+ },
|
|
|
+ initCnWebSocket() {
|
|
|
+ if (this.cnWebSocket && this.cnWebSocket.readyState === 2) return
|
|
|
+ this.cnWebSocket = new window.WebSocket(this.cnWebSocketPath)
|
|
|
+ let self = this;
|
|
|
+
|
|
|
+ this.cnWebSocket.onclose = function () {
|
|
|
+ self.cnWebSocketStatus = WebSocketStatus.Close
|
|
|
+ }
|
|
|
+ this.cnWebSocket.onopen = function () {
|
|
|
+ self.getPrinters()
|
|
|
+ self.cnWebSocketStatus = WebSocketStatus.Open
|
|
|
+ }
|
|
|
+ this.cnWebSocket.onerror = function () {
|
|
|
+ self.cnWebSocketStatus = WebSocketStatus.Error
|
|
|
+ }
|
|
|
+ this.cnWebSocket.onmessage = this.handlerCnWebsocket
|
|
|
+ },
|
|
|
// TODO 获取打印参数
|
|
|
getPrintItems() {
|
|
|
let url = '{{url('apiLocal/maintenance/print/getData')}}'
|
|
|
@@ -111,25 +166,39 @@
|
|
|
}
|
|
|
},
|
|
|
// TODO 发送到后台进行加工
|
|
|
- uploadPrintData() {
|
|
|
+ {{--uploadPrintData() {--}}
|
|
|
+ {{-- let url = "{{url("apiLocal/maintenance/print/uploadPrintData")}}";--}}
|
|
|
+ {{-- let data = {printData: this.printItems}--}}
|
|
|
+ {{-- let self = this;--}}
|
|
|
+ {{-- window.axios.post(url, data).then(res => {--}}
|
|
|
+ {{-- console.log(res)--}}
|
|
|
+ {{-- if (res.data.success) {--}}
|
|
|
+ {{-- res.data.data.forEach(function (item) {--}}
|
|
|
+ {{-- self.printItems.forEach(function (data, index, array) {--}}
|
|
|
+ {{-- if (data['logistic_number'] === item['logistic_number']) {--}}
|
|
|
+ {{-- array[index] = item--}}
|
|
|
+ {{-- }--}}
|
|
|
+ {{-- })--}}
|
|
|
+ {{-- })--}}
|
|
|
+ {{-- this.$forceUpdate();--}}
|
|
|
+ {{-- }--}}
|
|
|
+ {{-- }).then(err => {--}}
|
|
|
+
|
|
|
+ {{-- })--}}
|
|
|
+ {{--},--}}
|
|
|
+ uploadPrintData(item) {
|
|
|
let url = "{{url("apiLocal/maintenance/print/uploadPrintData")}}";
|
|
|
- let data = {printData: this.printItems}
|
|
|
- let self = this;
|
|
|
+ let data = {printData: [item]};
|
|
|
window.axios.post(url, data).then(res => {
|
|
|
- console.log(res)
|
|
|
if (res.data.success) {
|
|
|
- res.data.data.forEach(function (item) {
|
|
|
- self.printItems.forEach(function (data, index, array) {
|
|
|
- if (data['logistic_number'] === item['logistic_number']) {
|
|
|
- array[index] = item
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- this.$forceUpdate();
|
|
|
+ res.data.data
|
|
|
}
|
|
|
- }).then(err => {
|
|
|
+ }).catch(err => {
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+ sendPrinterDate(item) {
|
|
|
|
|
|
- })
|
|
|
},
|
|
|
// TODO GoWebSocket 初始化
|
|
|
initGoWebSocket() {
|
|
|
@@ -184,6 +253,163 @@
|
|
|
self.goWebSocket.send(JSON.stringify(item));
|
|
|
});
|
|
|
},
|
|
|
+ // TODO 获取预览面单
|
|
|
+ previewLogisticFace(data) {
|
|
|
+ if (data.type === "CAINIAO") {
|
|
|
+ let json = this.getCnPreviewTaskJson(data)
|
|
|
+ if (this.cnWebSocket && this.cnWebSocket.readyState === 1) {
|
|
|
+ this.cnWebSocket.send(json)
|
|
|
+ }
|
|
|
+ } else if (data.type === "PDD") {
|
|
|
+ let json = this.getPddPreviewTaskJson(data)
|
|
|
+ if (this.pddWebSocket && this.pddWebSocket.readyState === 1) {
|
|
|
+ this.pddWebSocket.send(json)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handlerCnWebsocket(message) {
|
|
|
+ let data = JSON.parse(message.data)
|
|
|
+ if (data.msg !== '成功') {
|
|
|
+ alert(data.msg);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (data.cmd === 'getPrinters') {
|
|
|
+ this.setClientPrinters(data)
|
|
|
+ } else if (data.cmd === 'print') {
|
|
|
+ let url = data['previewImage'][0];
|
|
|
+ this.getBase64(url, data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handlerPddWebsocket(message) {
|
|
|
+ let data = JSON.parse(message.data);
|
|
|
+ if (data.cmd === 'getPrinters') {
|
|
|
+ this.setClientPrinters(data)
|
|
|
+ } else if (data.cmd === "PrintResultNotify") {
|
|
|
+ console.log(data)
|
|
|
+ this.getBase64(data['previewURL'], data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getBase64(imgUrlPath, data) {
|
|
|
+ let canvas = document.createElement('canvas');
|
|
|
+ let cxt = canvas.getContext('2d');
|
|
|
+ let img = new Image();
|
|
|
+ img.setAttribute('crossOrigin', 'anonymous');
|
|
|
+ if (data.cmd === "PrintResultNotify") {
|
|
|
+ img.setAttribute('Access-Control-Allow-Oriain', 'http://127.0.0.1:16666');
|
|
|
+ this.getBase64ByUrl(imgUrlPath,data)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ img.setAttribute('Access-Control-Allow-Credentials', 'true');
|
|
|
+ img.src = imgUrlPath;
|
|
|
+ let base64 = null;
|
|
|
+ let self = this;
|
|
|
+ img.onload = () => {
|
|
|
+ canvas.width = img.width;
|
|
|
+ canvas.height = img.height;
|
|
|
+ cxt.drawImage(img, 0, 0);
|
|
|
+ base64 = canvas.toDataURL("image/jpeg", 1);
|
|
|
+ self.printItems.forEach(function (item) {
|
|
|
+ if (item['task_id'] === data['taskID']) {
|
|
|
+ item['base64'] = base64;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ getBase64ByUrl(url,data){
|
|
|
+ let xhr = new XMLHttpRequest();
|
|
|
+ xhr.withCredentials = true;
|
|
|
+ xhr.responseType = 'blob';
|
|
|
+ xhr.open('GET',url);
|
|
|
+ xhr.send()
|
|
|
+ xhr.onreadystatechange = function(){
|
|
|
+ if ( xhr.readyState === 4 && xhr.status === 200 ) {
|
|
|
+ alert( xhr.responseText );
|
|
|
+ let blob = new Blob([xhr.response], {type: 'image/png'});
|
|
|
+ console.log(blob);
|
|
|
+ } else {
|
|
|
+ alert( xhr.statusText );
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ getPddPreviewTaskJson(item) {
|
|
|
+ let printer = this.clientPrinters.printers[0]['name'];
|
|
|
+ return JSON.stringify({
|
|
|
+ cmd: "print",
|
|
|
+ requestID: item['task_id'],
|
|
|
+ version: "1.0",
|
|
|
+ task: {
|
|
|
+ taskID: item['task_id'],
|
|
|
+ previewType: "jpg",
|
|
|
+ notifyType: null,
|
|
|
+ preview: true,
|
|
|
+ printer: null,
|
|
|
+ firstDocumentNumber: 0,
|
|
|
+ totalDocumentCount: 1,
|
|
|
+ documents: [{
|
|
|
+ documentID: '11111',
|
|
|
+ contents: [{
|
|
|
+ encryptedData: item['data']['encryptedData'],
|
|
|
+ signature: item['data']['signature'],
|
|
|
+ templateUrl: item['data']['templateUrl'],
|
|
|
+ ver: item['data']['ver'],
|
|
|
+ }]
|
|
|
+ }],
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getCnPreviewTaskJson(item) {
|
|
|
+ let printer = this.clientPrinters.printers[0]['name'];
|
|
|
+ console.log(item);
|
|
|
+ return JSON.stringify({
|
|
|
+ cmd: 'print',
|
|
|
+ request_id: item['task_id'],
|
|
|
+ version: '1.0',
|
|
|
+ task: {
|
|
|
+ preview: true,
|
|
|
+ previewType: 'image',
|
|
|
+ printer: printer,
|
|
|
+ taskID: item['task_id'],
|
|
|
+ firstDocumentNumber: 0,
|
|
|
+ totalDocumentCount: 1,
|
|
|
+ documents: [{
|
|
|
+ documentID: "11111",
|
|
|
+ contents: [{
|
|
|
+ encryptedData: item['data']['encryptedData'],
|
|
|
+ signature: item['data']['signature'],
|
|
|
+ templateURL: item['data']['templateURL'],
|
|
|
+ ver: item['data']['ver'],
|
|
|
+ }],
|
|
|
+ }],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getPrinters() {
|
|
|
+ let json = JSON.stringify({
|
|
|
+ cmd: "getPrinters",
|
|
|
+ requestID: "getPrinters" + (new Date().getDate()),
|
|
|
+ version: "1.0",
|
|
|
+ });
|
|
|
+ if (this.cnWebSocket && this.cnWebSocket.readyState === 1) {
|
|
|
+ this.cnWebSocket.send(json);
|
|
|
+ } else if (this.pddWebSocket && this.pddWebSocket.readyState === 1) {
|
|
|
+ this.pddWebSocket.send(json);
|
|
|
+ } else {
|
|
|
+ alert('未链接打印机终端')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ setClientPrinters(data) {
|
|
|
+ this.clientPrinters.defaultPrinter = data['defaultPrinter'];
|
|
|
+ this.clientPrinters.printers = data['printers'];
|
|
|
+ },
|
|
|
+ testPreview() {
|
|
|
+ let self = this;
|
|
|
+ this.printItems.forEach(function (item) {
|
|
|
+ self.previewLogisticFace(item)
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|
|
|
});
|
|
|
|