template.blade.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <div class="form-group">
  8. <label class="form-inline" for="printStr"></label>
  9. <input type="text" name="printStr" class="form-control" ref="printStr" id="printStr" placeholder="输入波次号,订单号,">
  10. </div>
  11. </div>
  12. <div class="card-body">
  13. <button class="btn btn-primary" @click="getPrintItems">获取</button>
  14. <button class="btn btn-outline-info" @click="wsGetImage">GoWebSocket 预览</button>
  15. <button class="btn btn-outline-primary" @click="uploadPrintData">WAS加工</button>
  16. <button class="btn btn-success" @click="wsPrintImage">GoWebSocket 打印</button>
  17. {{--<button class="btn btn-outline-warning" @click="initGoWebSocket">GoWebSocket 重置</button>--}}
  18. </div>
  19. <div class="container">
  20. <p>打印步骤</p>
  21. <p>1:输入单号-获取</p>
  22. <p>2:预览</p>
  23. <p>3:加工</p>
  24. <p>4:打印</p>
  25. </div>
  26. <div class="alert alert-success" v-if="goWebSocketStatus === 1">
  27. 链接成功
  28. </div>
  29. <div class="alert alert-primary" v-if="goWebSocketStatus === 2" @click="initGoWebSocket">
  30. 链接失败
  31. </div>
  32. <div class="alert alert-primary" v-if="goWebSocketStatus === 3" @click="initGoWebSocket">
  33. 链接错误
  34. </div>
  35. </div>
  36. <div class="card">
  37. <ul class="list-group">
  38. <template v-for="item in printItems">
  39. <li class="list-group-item">
  40. <p> 编号:@{{ item.task_id }}</p>
  41. <p> 快递单号 :@{{ item.logistic_number }}</p>
  42. <div v-if="item.base64" class="position-relative">
  43. <img :src="'data:image/jpeg;base64,'+item.base64" alt="" style="width: 50%;height: 50%"
  44. class="position-relative">
  45. </div>
  46. </li>
  47. </template>
  48. </ul>
  49. </div>
  50. </div>
  51. </div>
  52. @endsection
  53. @section('lastScript')
  54. <script>
  55. let vue = new Vue({
  56. el: '#list',
  57. data: {
  58. printItems: [],
  59. goWebSocketPath: "ws://127.0.0.1:11101/print",
  60. goWebSocket: null,
  61. goWebSocketStatus: 0,
  62. },
  63. created() {
  64. },
  65. mounted() {
  66. // 初始化 go 链接
  67. this.initGoWebSocket();
  68. },
  69. methods: {
  70. // TODO 获取打印参数
  71. getPrintItems() {
  72. let url = '{{url('apiLocal/maintenance/print/getData')}}'
  73. let data = {
  74. printStr: this.$refs.printStr.value,
  75. };
  76. if (data.printStr.trim().length === 0) {
  77. window.tempTip.show('输入后在获取')
  78. }
  79. window.axios.post(url, data).then(res => {
  80. this.printItems = res.data.data
  81. this.$forceUpdate();
  82. }).catch(err => {
  83. console.log(err);
  84. });
  85. },
  86. // TODO GoWs 返回信息
  87. receiveGoWebSocketMessage(meg) {
  88. this.goWebSocketStatus = 1;
  89. let res = JSON.parse(meg.data)
  90. if (res.operation === 'print') {
  91. if (res.status === true) {
  92. }
  93. } else if (res.operation === 'preview') {
  94. if (res.status === "success") {
  95. this.printItems.forEach(function (item) {
  96. if (item['task_id'] === res['task_id']) {
  97. item['base64'] = res.data.shift();
  98. }
  99. })
  100. this.$forceUpdate();
  101. }
  102. } else if (res.operation === 'line') {
  103. if (res.status === '') this.goWebSocketStatus = 1;
  104. }
  105. },
  106. // TODO 发送到后台进行加工
  107. uploadPrintData() {
  108. let url = "{{url("apiLocal/maintenance/print/uploadPrintData")}}";
  109. let data = {printData: this.printItems}
  110. let self = this;
  111. window.axios.post(url, data).then(res => {
  112. console.log(res)
  113. if (res.data.success) {
  114. res.data.data.forEach(function (item) {
  115. self.printItems.forEach(function (data, index, array) {
  116. if (data['logistic_number'] === item['logistic_number']) {
  117. array[index] = item
  118. }
  119. })
  120. })
  121. this.$forceUpdate();
  122. }
  123. }).then(err => {
  124. })
  125. },
  126. // TODO GoWebSocket 初始化
  127. initGoWebSocket() {
  128. if (this.goWebSocket && this.goWebSocket.readyState === 1) return this.goWebSocket;
  129. this.goWebSocketStatus = 2;
  130. let self = this;
  131. this.goWebSocket = new window.WebSocket(this.goWebSocketPath);
  132. this.goWebSocket.onmessage = this.receiveGoWebSocketMessage;
  133. this.goWebSocket.onopen = function () {
  134. self.goWebSocketStatus = 1
  135. };
  136. this.goWebSocket.onclose = function () {
  137. self.goWebSocketStatus = 2
  138. };
  139. this.goWebSocket.onerror = function () {
  140. self.goWebSocketStatus = 3
  141. }
  142. },
  143. // TODO GoWebSocket 链接成功
  144. GoWebSocketOpen() {
  145. this.goWebSocketStatus = 0;
  146. },
  147. // TODO GoWebSocket 链接关闭
  148. GoWebSocketClose() {
  149. this.goWebSocketStatus = 1;
  150. },
  151. // TODO GoWebSocket 关闭
  152. closeGoWebSocket() {
  153. this.goWebSocketStatus = 2;
  154. this.goWebSocket.close();
  155. },
  156. // TODO 推动到GoWs 获取打印图片
  157. wsGetImage() {
  158. let self = this;
  159. if (!this.goWebSocket || this.goWebSocket.readyState !== 1) {
  160. window.tempTip.show("重置链接或继续")
  161. }
  162. this.initGoWebSocket();
  163. this.printItems.forEach(function (item) {
  164. if (item['is_process'] === true) return;
  165. item['operation'] = 'preview';
  166. self.goWebSocket.send(JSON.stringify(item))
  167. });
  168. },
  169. // TODO 推动到GoWs 进行打印
  170. wsPrintImage() {
  171. this.initGoWebSocket();
  172. let self = this;
  173. this.printItems.forEach(function (item) {
  174. item['operation'] = 'print';
  175. self.goWebSocket.send(JSON.stringify(item));
  176. });
  177. },
  178. }
  179. });
  180. </script>
  181. @endsection