template.blade.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. @extends('layouts.app')
  2. @section('title','面单打印')
  3. @section('content')
  4. <div class="container " id="list">
  5. <div class="card">
  6. <div class="card-header">
  7. <label>
  8. <input type="text" name="printStr" class="form-control">
  9. </label>
  10. </div>
  11. <div class="card-body">
  12. <button @click="getPrintRequest">获取</button>
  13. <button @click="pushGoPrintData">打印</button>
  14. <button @click="resetGoWebsocket">recon</button>
  15. <button @click="uploadPrintData">上传</button>
  16. </div>
  17. <div class="alert-success" v-if="goWebSocketStatus">
  18. 链接成功
  19. </div>
  20. <div v-else class="alert-primary">
  21. 链接失败
  22. </div>
  23. <div class="card-footer">
  24. <canvas id="canvas-div" class="d-none"></canvas>
  25. </div>
  26. <div>
  27. <img src="" alt="" id="img">
  28. </div>
  29. </div>
  30. </div>
  31. @endsection
  32. @section('lastScript')
  33. <script>
  34. let vue = new Vue({
  35. el: '#list',
  36. data: {
  37. data: [],
  38. goWebSocketPath: "ws://127.0.0.1:11101/msg",
  39. goWebSocket: null,
  40. goWebSocketStatus: false,
  41. printData: [],
  42. uploadData:[]
  43. },
  44. created() {
  45. },
  46. mounted() {
  47. this.getGoWebSocket();
  48. },
  49. methods: {
  50. getGoWebSocket() {
  51. if (this.goWebSocket) return this.goWebSocket;
  52. this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
  53. this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
  54. return this.goWebSocket;
  55. },
  56. closeGoWebSocket() {
  57. this.goWebSocket.close();
  58. },
  59. getPrintRequest() {
  60. let self = this;
  61. let url = '{{url('apiLocal/maintenance/print/getData')}}'
  62. window.axios.get(url).then(res => {
  63. res.data.data.forEach(function (item) {
  64. self.printData.push({
  65. type: "CAINIAO",
  66. data: JSON.stringify(self.getPreviewRequest(item, null))
  67. });
  68. });
  69. this.$forceUpdate();
  70. console.log(this.printData);
  71. }).catch(err => {
  72. console.log(err);
  73. });
  74. },
  75. pushGoPrintData() {
  76. let self = this;
  77. this.printData.forEach(function (item) {
  78. let json = JSON.stringify(item);
  79. self.getGoWebSocket().send(json);
  80. })
  81. },
  82. receiveGoWebSocketMessage(meg) {
  83. console.log("receiveGoWebSocketMessage");
  84. let params = JSON.parse(meg.data)
  85. if(params.success ==="false"){
  86. alert(params.message)
  87. }else if (params.success ==="true"){
  88. let imgBase64 = params.data;
  89. let base64String = "data:image/gif;base64," + imgBase64;
  90. document.getElementById("img").setAttribute("src",base64String)
  91. // js/base64图片 base64String
  92. this.uploadData.push({
  93. 'base64':base64String
  94. })
  95. console.log(this.uploadData);
  96. this.$forceUpdate()
  97. }
  98. },
  99. getPreviewRequest(item, taskId) {
  100. return {
  101. cmd: "print",
  102. requestID: "123458976",
  103. letsion: '1.0',
  104. firstDocumentNumber: 0,
  105. totalDocumentCount: 1,
  106. task: {
  107. taskID: '123458976123',
  108. preview: true,
  109. printer: '',
  110. notifyMode: 'allInOne',
  111. previewType: 'image',
  112. documents: [{
  113. documentID: "123123123",
  114. contents: [{
  115. encryptedData: item['encryptedData'],
  116. signature: item['encryptedData'],
  117. templateURL: item['templateURL'],
  118. ver: item['ver']
  119. }],
  120. }],
  121. }
  122. };
  123. },
  124. resetGoWebsocket() {
  125. this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
  126. this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
  127. },
  128. uploadPrintData(){
  129. let url = "{{url("apiLocal/maintenance/print/uploadPrintData")}}";
  130. let data = {printData:this.uploadData}
  131. window.axios.post(url,data).then(res=>{
  132. }).then(err=>{
  133. })
  134. }
  135. }
  136. });
  137. </script>
  138. @endsection