template.blade.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. <input type="file" id="uploadInput">
  15. {{-- <template v-for="image in printImage">--}}
  16. {{-- <div class="print-div">--}}
  17. {{-- <template v-if="image.type === 'image'">--}}
  18. {{-- <img :src="image.uri" class="print-image">--}}
  19. {{-- </template>--}}
  20. {{-- <template v-else-if="image.type === 'pdf'">--}}
  21. {{-- <embed :src="image.uri" type="application/pdf" width="100%" height="100%" class="print-pdf">--}}
  22. {{-- </template>--}}
  23. {{-- </div>--}}
  24. {{-- </template>--}}
  25. </div>
  26. <div class="alert-success" v-if="goWebSocketStatus">
  27. 链接成功
  28. </div>
  29. <div v-else class="alert-primary">
  30. 链接失败
  31. </div>
  32. <div class="card-footer">
  33. <canvas id="canvas-div" class="d-none"></canvas>
  34. </div>
  35. </div>
  36. </div>
  37. @endsection
  38. @section('lastScript')
  39. <script>
  40. let vue = new Vue({
  41. el: '#list',
  42. data: {
  43. data: [],
  44. goWebSocketPath: 'ws://127.0.0.1:11101/',
  45. goWebSocket:null,
  46. goWebSocketStatus:false,
  47. printData:[]
  48. },
  49. created() {
  50. },
  51. mounted() {
  52. this.getGoWebSocket();
  53. },
  54. methods: {
  55. getGoWebSocket(){
  56. let self = this;
  57. if(this.goWebSocket)return this.goWebSocket;
  58. let socket= new window.WebSocket(this.goWebSocketPath);
  59. socket.onopen = function(){
  60. self.goWebSocketStatus = true;
  61. }
  62. console.log(123);
  63. return this.goWebSocket = socket;
  64. },
  65. getPrintRequest() {
  66. let self = this;
  67. let url = '{{url('apiLocal/maintenance/print/getData')}}'
  68. window.axios.post(url).then(res => {
  69. res.data.data.forEach(function (item) {
  70. self.printData.push({
  71. type:"CAINIAO",
  72. data:self.getPreviewRequest(item,null)
  73. });
  74. });
  75. this.$forceUpdate();
  76. console.log(this.printData);
  77. }).catch(err => {
  78. console.log(err);
  79. });
  80. },
  81. pushGoPrintData(){
  82. let socket = this.getGoWebSocket();
  83. this.printData.forEach(function(item){
  84. let json = JSON.stringify(item);
  85. socket.send(json);
  86. })
  87. },
  88. getPreviewRequest(item,taskId){
  89. return {
  90. cmd: "print",
  91. requestID: "123458976",
  92. letsion: '1.0',
  93. firstDocumentNumber: 0,
  94. totalDocumentCount: 1,
  95. task: {
  96. taskID: '123458976123',
  97. preview: true,
  98. printer: '',
  99. notifyMode: 'allInOne',
  100. previewType: 'image',
  101. documents: [{
  102. documentID: "123123123",
  103. contents: [{
  104. encryptedData: item['encryptedData'],
  105. signature: item['encryptedData'],
  106. templateURL: item['templateURL'],
  107. ver: item['ver']
  108. }],
  109. }],
  110. }
  111. };
  112. }
  113. }
  114. });
  115. </script>
  116. @endsection