Index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div id="app-hw-bluetooth">
  3. <div class="one-block-1">
  4. <span>
  5. 1. 打印机设备
  6. </span>
  7. </div>
  8. <div class="one-block-2">
  9. <a-button @click="getPrinter()"> 获取打印机列表 </a-button>
  10. </div>
  11. <div class="one-block-2">
  12. <a-list size="small" bordered :data-source="printerList">
  13. <a-list-item slot="renderItem" slot-scope="item">
  14. {{ item.displayName }} {{ defaultDevice(item) }}
  15. </a-list-item>
  16. <div slot="header">
  17. 设备列表
  18. </div>
  19. </a-list>
  20. </div>
  21. <div class="one-block-1">
  22. <span>
  23. 2. 打印内容
  24. </span>
  25. </div>
  26. <div class="one-block-2">
  27. <a-button @click="doPrint(0)"> 打印一个页面 </a-button>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { ipcApiRoute } from '@/api/main'
  33. export default {
  34. data() {
  35. return {
  36. defaultDeviceName: '',
  37. printerList: [],
  38. views: [
  39. {
  40. type: 'html',
  41. content: '/public/html/view_example.html'
  42. },
  43. ],
  44. };
  45. },
  46. mounted () {
  47. this.init();
  48. },
  49. methods: {
  50. init () {
  51. // 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次
  52. this.$ipc.removeAllListeners(ipcApiRoute.printStatus);
  53. this.$ipc.on(ipcApiRoute.printStatus, (event, result) => {
  54. console.log('result', result);
  55. this.$message.info('打印中...');
  56. })
  57. },
  58. getPrinter () {
  59. this.$ipc.invoke(ipcApiRoute.getPrinterList, {}).then(res => {
  60. this.printerList = res;
  61. })
  62. },
  63. doPrint (index) {
  64. console.log('defaultDeviceName:', this.defaultDeviceName)
  65. const params = {
  66. view: this.views[index],
  67. deviceName: this.defaultDeviceName
  68. };
  69. this.$ipc.send(ipcApiRoute.print, params)
  70. },
  71. defaultDevice (item) {
  72. let desc = "";
  73. if (item.isDefault) {
  74. desc = "- 默认";
  75. this.defaultDeviceName = item.name;
  76. }
  77. return desc;
  78. }
  79. }
  80. };
  81. </script>
  82. <style lang="less" scoped>
  83. #app-hw-bluetooth {
  84. padding: 0px 10px;
  85. text-align: left;
  86. width: 100%;
  87. .one-block-1 {
  88. font-size: 16px;
  89. padding-top: 10px;
  90. }
  91. .one-block-2 {
  92. padding-top: 10px;
  93. }
  94. }
  95. </style>