|
|
@@ -19,6 +19,9 @@
|
|
|
<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="getPrinters">获取打印机</button>
|
|
|
+
|
|
|
+ <button class="btn btn-dark" @click="getImage">获取图片</button>
|
|
|
+ <button class="btn btn-dark" @click="printImage">打印图片</button>
|
|
|
</div>
|
|
|
|
|
|
<div class="container">
|
|
|
@@ -37,6 +40,7 @@
|
|
|
<div class="alert alert-primary" v-if="goWebSocketStatus === 3" @click="initGoWebSocket">
|
|
|
链接错误
|
|
|
</div>
|
|
|
+
|
|
|
</div>
|
|
|
<div class="card">
|
|
|
<ul class="list-group">
|
|
|
@@ -51,6 +55,8 @@
|
|
|
</li>
|
|
|
</template>
|
|
|
</ul>
|
|
|
+
|
|
|
+ <img src="" alt="" id="cImage">
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
@@ -69,7 +75,8 @@
|
|
|
el: '#list',
|
|
|
data: {
|
|
|
printItems: [],
|
|
|
- goWebSocketPath: "ws://127.0.0.1:11101/print",
|
|
|
+ // goWebSocketPath: "ws://127.0.0.1:11101/print",
|
|
|
+ goWebSocketPath: "ws://127.0.0.1:11011/printer",
|
|
|
goWebSocket: null,
|
|
|
goWebSocketStatus: 0,
|
|
|
|
|
|
@@ -79,20 +86,19 @@
|
|
|
pddWebSocket: null,
|
|
|
pddWebSocketPath: "ws://127.0.0.1:5000",
|
|
|
pddWebSocketStatus: null,
|
|
|
-
|
|
|
clientPrinters: {
|
|
|
defaultPrinter: "",
|
|
|
printers: [],
|
|
|
},
|
|
|
- },
|
|
|
+ base64String:null, },
|
|
|
created() {
|
|
|
|
|
|
},
|
|
|
mounted() {
|
|
|
// 初始化 go 链接
|
|
|
- // this.initGoWebSocket();
|
|
|
- this.initPddWebSocket();
|
|
|
- this.initCnWebSocket();
|
|
|
+ this.initGoWebSocket();
|
|
|
+ // this.initPddWebSocket();
|
|
|
+ // this.initCnWebSocket();
|
|
|
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -147,23 +153,33 @@
|
|
|
},
|
|
|
// TODO GoWs 返回信息
|
|
|
receiveGoWebSocketMessage(meg) {
|
|
|
- this.goWebSocketStatus = 1;
|
|
|
- let res = JSON.parse(meg.data)
|
|
|
- if (res.operation === 'print') {
|
|
|
- if (res.status === true) {
|
|
|
- }
|
|
|
- } else if (res.operation === 'preview') {
|
|
|
- if (res.status === "success") {
|
|
|
- this.printItems.forEach(function (item) {
|
|
|
- if (item['task_id'] === res['task_id']) {
|
|
|
- item['base64'] = res.data.shift();
|
|
|
- }
|
|
|
- })
|
|
|
- this.$forceUpdate();
|
|
|
- }
|
|
|
- } else if (res.operation === 'line') {
|
|
|
- if (res.status === '') this.goWebSocketStatus = 1;
|
|
|
+ let data = meg.data;
|
|
|
+ data = JSON.parse(data)
|
|
|
+ console.log(data)
|
|
|
+ if (data.Status === true){
|
|
|
+ let image = document.getElementById("cImage");
|
|
|
+ console.log(image)
|
|
|
+ console.log(data.Base64)
|
|
|
+ this.base64String = data.Base64;
|
|
|
+ image.setAttribute("src","data:image/jpeg;base64,"+data.Base64)
|
|
|
}
|
|
|
+ // this.goWebSocketStatus = 1;
|
|
|
+ // let res = JSON.parse(meg.data)
|
|
|
+ // if (res.operation === 'print') {
|
|
|
+ // if (res.status === true) {
|
|
|
+ // }
|
|
|
+ // } else if (res.operation === 'preview') {
|
|
|
+ // if (res.status === "success") {
|
|
|
+ // this.printItems.forEach(function (item) {
|
|
|
+ // if (item['task_id'] === res['task_id']) {
|
|
|
+ // item['base64'] = res.data.shift();
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // this.$forceUpdate();
|
|
|
+ // }
|
|
|
+ // } else if (res.operation === 'line') {
|
|
|
+ // if (res.status === '') this.goWebSocketStatus = 1;
|
|
|
+ // }
|
|
|
},
|
|
|
// TODO 发送到后台进行加工
|
|
|
{{--uploadPrintData() {--}}
|
|
|
@@ -212,6 +228,7 @@
|
|
|
};
|
|
|
this.goWebSocket.onclose = function () {
|
|
|
self.goWebSocketStatus = 2
|
|
|
+ alert("onclose")
|
|
|
};
|
|
|
|
|
|
this.goWebSocket.onerror = function () {
|
|
|
@@ -410,6 +427,20 @@
|
|
|
self.previewLogisticFace(item)
|
|
|
})
|
|
|
},
|
|
|
+ getImage(){
|
|
|
+ let data = {
|
|
|
+ processType:"getBase64Image",
|
|
|
+ url:"https://ss3.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/exp/w=480/sign=2c1fdf63d909b3deebbfe560fcbe6cd3/fd039245d688d43ffdc5e9f9751ed21b0ef43b48.jpg"
|
|
|
+ }
|
|
|
+ this.goWebSocket.send(JSON.stringify(data))
|
|
|
+ },
|
|
|
+ printImage(){
|
|
|
+ let data = {
|
|
|
+ processType:"printImage",
|
|
|
+ base64:this.base64String
|
|
|
+ };
|
|
|
+ this.goWebSocket.send(JSON.stringify(data));
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|