WriteEpc.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**
  2. * EPC 打印界面
  3. */
  4. <template>
  5. <div>
  6. <!-- 打印结果模态框 -->
  7. <Modal v-model:show="modal" title="发卡机发卡">
  8. <div class="form-horizontal">
  9. <div class="form-group epc-container">
  10. <label class="col-sm-2 epc-label">EPC</label>
  11. <div style="width: 84%">
  12. <input
  13. v-model="lastWriteEpc"
  14. type="text"
  15. class="form-control"
  16. placeholder="EPC"
  17. />
  18. </div>
  19. </div>
  20. </div>
  21. <button
  22. type="button"
  23. class="btn btn-default m-button"
  24. @click="writeSingleEpc(lastWriteEpc)"
  25. >
  26. 写入
  27. </button>
  28. <button
  29. type="button"
  30. class="btn btn-default m-button"
  31. @click="restoreEpc"
  32. >
  33. 重置
  34. </button>
  35. <button type="button" class="btn btn-default m-button" @click="readEpc">
  36. 读取
  37. </button>
  38. <div
  39. v-if="printResult != null && printResult.command == 'write'"
  40. :class="
  41. printResult.errorCode === 0
  42. ? 'alert alert-success'
  43. : 'alert alert-danger'
  44. "
  45. role="alert"
  46. >
  47. <p v-if="printResult.errorCode === 0">
  48. 操作成功 EPC:{{ lastWriteEpc }} 写入成功
  49. </p>
  50. <p v-else-if="printResult.errorCode === 1">
  51. 操作失败 {{ printResult.errorMessage }} 请先重置EPC。
  52. </p>
  53. <p v-else>
  54. 操作失败 {{ printResult.errorMessage }} 待写入EPC:{{
  55. lastWriteEpc
  56. }}
  57. </p>
  58. </div>
  59. <div
  60. v-if="printResult != null && printResult.command == 'restore'"
  61. :class="
  62. printResult.errorCode === 0
  63. ? 'alert alert-success'
  64. : 'alert alert-danger'
  65. "
  66. role="alert"
  67. >
  68. <p>
  69. {{ printResult.errorCode === 0 ? "操作成功" : "操作失败" }}
  70. {{ printResult.errorMessage }}
  71. </p>
  72. </div>
  73. <div
  74. v-if="printResult != null && printResult.command == 'read'"
  75. :class="
  76. printResult.errorCode === 0
  77. ? 'alert alert-success'
  78. : 'alert alert-danger'
  79. "
  80. role="alert"
  81. >
  82. <p style="word-wrap: break-word">
  83. {{ printResult.errorCode === 0 ? "操作成功" : "操作失败" }},{{
  84. printResult.epcs && printResult.epcs.length > 0
  85. ? `读取到 ${printResult.tagCount} 个标签:${printResult.epcs}`
  86. : printResult.errorMessage
  87. }}
  88. </p>
  89. </div>
  90. </Modal>
  91. <Loading v-if="loading" />
  92. </div>
  93. </template>
  94. <script>
  95. import WriteEpcUtil from './WriteEpcUtil.js';
  96. import Modal from '../../modal/src/Modal.vue';
  97. import Loading from '../../loading/src/Loading.vue';
  98. export default {
  99. name: 'WriteEpc',
  100. components: {
  101. Modal,
  102. Loading,
  103. },
  104. props: {
  105. visible: {
  106. type: Boolean,
  107. default: false,
  108. },
  109. },
  110. emits: ['update:visible'],
  111. data: function () {
  112. return {
  113. lastWriteEpc: '', // 最后写入的EPC
  114. // 打印结果
  115. printResult: {
  116. command: '', // 指令
  117. success: true, // 是否操作成功
  118. message: '', // 操作不成功的消息
  119. tagCount: 0, // 标签读取的数量
  120. epcs: '', // 读取的标签信息
  121. epc: '', // 打印的EPC
  122. },
  123. loading: false,
  124. };
  125. },
  126. computed: {
  127. modal: {
  128. get() {
  129. return this.visible;
  130. },
  131. set(value) {
  132. this.$emit('update:visible', value);
  133. },
  134. },
  135. },
  136. methods: {
  137. /**
  138. * EPC 发卡
  139. * @param epc 待操作的EPC的内容
  140. */
  141. writeSingleEpc: function (epc) {
  142. let _self = this;
  143. _self.modal = false;
  144. _self.lastWriteEpc = epc;
  145. let promise = WriteEpcUtil.writeSingleEpc(epc);
  146. _self.loading = true;
  147. promise.then(
  148. successData => {
  149. _self.loading = false;
  150. successData.command = 'write';
  151. _self.printResult = successData;
  152. _self.modal = true;
  153. },
  154. errorData => {
  155. _self.loading = false;
  156. errorData.command = 'write';
  157. _self.printResult = errorData;
  158. _self.modal = true;
  159. },
  160. );
  161. },
  162. /**
  163. * 恢复EPC
  164. */
  165. restoreEpc: function () {
  166. let _self = this;
  167. _self.modal = true;
  168. let promise = WriteEpcUtil.resetTag();
  169. _self.loading = true;
  170. promise.then(
  171. successData => {
  172. _self.loading = false;
  173. successData.command = 'restore';
  174. _self.printResult = successData;
  175. _self.modal = true;
  176. },
  177. errorData => {
  178. _self.loading = false;
  179. errorData.command = 'restore';
  180. _self.printResult = errorData;
  181. _self.modal = true;
  182. },
  183. );
  184. },
  185. /**
  186. * 读取EPC
  187. */
  188. readEpc: function () {
  189. let _self = this;
  190. _self.modal = true;
  191. let promise = WriteEpcUtil.readEpc();
  192. _self.loading = true;
  193. promise.then(
  194. successData => {
  195. _self.loading = false;
  196. successData.command = 'read';
  197. if (successData.errorCode === 0) {
  198. successData.tagCount = successData.data.length;
  199. successData.epcs = successData.data.join();
  200. }
  201. _self.printResult = successData;
  202. },
  203. errorData => {
  204. _self.loading = false;
  205. errorData.command = 'read';
  206. _self.printResult = errorData;
  207. },
  208. );
  209. },
  210. /**
  211. * 显示模态框
  212. */
  213. show: function () {
  214. this.modal = true;
  215. },
  216. },
  217. };
  218. </script>
  219. <style scoped>
  220. .m-button {
  221. margin-right: 1rem;
  222. margin-bottom: 1rem;
  223. }
  224. .epc-container {
  225. display: flex;
  226. align-items: center;
  227. }
  228. .epc-label {
  229. margin-bottom: 0;
  230. width: 80px;
  231. text-align: center;
  232. }
  233. </style>