|
|
@@ -14,17 +14,7 @@
|
|
|
<button @click="getPrintRequest">获取</button>
|
|
|
<button @click="pushGoPrintData">打印</button>
|
|
|
<button @click="resetGoWebsocket">recon</button>
|
|
|
- <input type="file" id="uploadInput">
|
|
|
-{{-- <template v-for="image in printImage">--}}
|
|
|
-{{-- <div class="print-div">--}}
|
|
|
-{{-- <template v-if="image.type === 'image'">--}}
|
|
|
-{{-- <img :src="image.uri" class="print-image">--}}
|
|
|
-{{-- </template>--}}
|
|
|
-{{-- <template v-else-if="image.type === 'pdf'">--}}
|
|
|
-{{-- <embed :src="image.uri" type="application/pdf" width="100%" height="100%" class="print-pdf">--}}
|
|
|
-{{-- </template>--}}
|
|
|
-{{-- </div>--}}
|
|
|
-{{-- </template>--}}
|
|
|
+ <button @click="uploadPrintData">上传</button>
|
|
|
</div>
|
|
|
<div class="alert-success" v-if="goWebSocketStatus">
|
|
|
链接成功
|
|
|
@@ -35,6 +25,9 @@
|
|
|
<div class="card-footer">
|
|
|
<canvas id="canvas-div" class="d-none"></canvas>
|
|
|
</div>
|
|
|
+ <div>
|
|
|
+ <img src="" alt="" id="img">
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@endsection
|
|
|
@@ -47,9 +40,10 @@
|
|
|
data: {
|
|
|
data: [],
|
|
|
goWebSocketPath: "ws://127.0.0.1:11101/msg",
|
|
|
- goWebSocket:null,
|
|
|
- goWebSocketStatus:false,
|
|
|
- printData:[]
|
|
|
+ goWebSocket: null,
|
|
|
+ goWebSocketStatus: false,
|
|
|
+ printData: [],
|
|
|
+ uploadData:[]
|
|
|
},
|
|
|
created() {
|
|
|
|
|
|
@@ -58,22 +52,23 @@
|
|
|
this.getGoWebSocket();
|
|
|
},
|
|
|
methods: {
|
|
|
- getGoWebSocket(){
|
|
|
- if(this.goWebSocket)return this.goWebSocket;
|
|
|
+ getGoWebSocket() {
|
|
|
+ if (this.goWebSocket) return this.goWebSocket;
|
|
|
this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
|
|
|
+ this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
|
|
|
return this.goWebSocket;
|
|
|
},
|
|
|
- closeGoWebSocket(){
|
|
|
+ closeGoWebSocket() {
|
|
|
this.goWebSocket.close();
|
|
|
},
|
|
|
getPrintRequest() {
|
|
|
let self = this;
|
|
|
let url = '{{url('apiLocal/maintenance/print/getData')}}'
|
|
|
- window.axios.post(url).then(res => {
|
|
|
+ window.axios.get(url).then(res => {
|
|
|
res.data.data.forEach(function (item) {
|
|
|
self.printData.push({
|
|
|
- type:"CAINIAO",
|
|
|
- data:JSON.stringify(self.getPreviewRequest(item,null))
|
|
|
+ type: "CAINIAO",
|
|
|
+ data: JSON.stringify(self.getPreviewRequest(item, null))
|
|
|
});
|
|
|
});
|
|
|
this.$forceUpdate();
|
|
|
@@ -82,14 +77,31 @@
|
|
|
console.log(err);
|
|
|
});
|
|
|
},
|
|
|
- pushGoPrintData(){
|
|
|
+ pushGoPrintData() {
|
|
|
let self = this;
|
|
|
- this.printData.forEach(function(item){
|
|
|
- let json = JSON.stringify(item);
|
|
|
+ this.printData.forEach(function (item) {
|
|
|
+ let json = JSON.stringify(item);
|
|
|
self.getGoWebSocket().send(json);
|
|
|
})
|
|
|
},
|
|
|
- getPreviewRequest(item,taskId){
|
|
|
+ receiveGoWebSocketMessage(meg) {
|
|
|
+ console.log("receiveGoWebSocketMessage");
|
|
|
+ let params = JSON.parse(meg.data)
|
|
|
+ if(params.success ==="false"){
|
|
|
+ alert(params.message)
|
|
|
+ }else if (params.success ==="true"){
|
|
|
+ let imgBase64 = params.data;
|
|
|
+ let base64String = "data:image/gif;base64," + imgBase64;
|
|
|
+ document.getElementById("img").setAttribute("src",base64String)
|
|
|
+ // js/base64图片 base64String
|
|
|
+ this.uploadData.push({
|
|
|
+ 'base64':base64String
|
|
|
+ })
|
|
|
+ console.log(this.uploadData);
|
|
|
+ this.$forceUpdate()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getPreviewRequest(item, taskId) {
|
|
|
return {
|
|
|
cmd: "print",
|
|
|
requestID: "123458976",
|
|
|
@@ -114,8 +126,16 @@
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
- resetGoWebsocket(){
|
|
|
+ resetGoWebsocket() {
|
|
|
this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
|
|
|
+ this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
|
|
|
+ },
|
|
|
+ uploadPrintData(){
|
|
|
+ let url = "{{url("apiLocal/maintenance/print/uploadPrintData")}}";
|
|
|
+ let data = {printData:this.uploadData}
|
|
|
+ window.axios.post(url,data).then(res=>{
|
|
|
+ }).then(err=>{
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
});
|