Index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div id="app-base-notification">
  3. <div class="one-block-1">
  4. <span>
  5. 1. 弹出桌面通知
  6. </span>
  7. </div>
  8. <div class="one-block-2">
  9. <a-space>
  10. <a-button @click="sendNotification(0)">默认</a-button>
  11. <a-button @click="sendNotification(1)">发出提示音</a-button>
  12. <a-button @click="sendNotification(2)">点击通知触发事件</a-button>
  13. <a-button @click="sendNotification(3)">关闭通知触发事件</a-button>
  14. </a-space>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import { ipcApiRoute } from '@/api/main'
  20. export default {
  21. data() {
  22. return {
  23. views: [
  24. {
  25. type: 'main',
  26. title: '通知标题',
  27. subtitle: '副标题', // macOS系统专有属性
  28. body: '这是通知内容-默认',
  29. silent: true,
  30. },
  31. {
  32. type: 'main',
  33. title: '提示音',
  34. subtitle: '副标题-提示音',
  35. body: '这是通知内容-提示音',
  36. silent: false,
  37. },
  38. {
  39. type: 'main',
  40. title: '点击通知事件',
  41. subtitle: '副标题-点击通知事件',
  42. body: '这是通知内容-点击通知事件',
  43. clickEvent: true
  44. },
  45. {
  46. type: 'main',
  47. title: '关闭通知事件',
  48. subtitle: '副标题-关闭通知事件',
  49. body: '这是通知内容-点击通知事件',
  50. closeEvent: true
  51. },
  52. ],
  53. };
  54. },
  55. mounted () {
  56. this.init();
  57. },
  58. methods: {
  59. init () {
  60. const self = this;
  61. // 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次
  62. this.$ipc.removeAllListeners(ipcApiRoute.sendNotification);
  63. this.$ipc.on(ipcApiRoute.sendNotification, (event, result) => {
  64. if (Object.prototype.toString.call(result) == '[object Object]') {
  65. self.$message.info(result.msg);
  66. }
  67. })
  68. },
  69. sendNotification (index) {
  70. this.$ipc.send(ipcApiRoute.sendNotification, this.views[index]);
  71. },
  72. }
  73. };
  74. </script>
  75. <style lang="less" scoped>
  76. #app-base-notification {
  77. padding: 0px 10px;
  78. text-align: left;
  79. width: 100%;
  80. .one-block-1 {
  81. font-size: 16px;
  82. padding-top: 10px;
  83. }
  84. .one-block-2 {
  85. padding-top: 10px;
  86. }
  87. }
  88. </style>