Index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div id="app-demo-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. export default {
  20. data() {
  21. return {
  22. views: [
  23. {
  24. type: 'main',
  25. title: '通知标题',
  26. subtitle: '副标题', // macOS系统专有属性
  27. body: '这是通知内容-默认',
  28. silent: true,
  29. icon: '/asset/images/tray_logo.png',
  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. self.$ipc.on('example.sendNotification', (event, result) => {
  62. if (Object.prototype.toString.call(result) == '[object Object]') {
  63. self.$message.info(result.msg);
  64. }
  65. })
  66. },
  67. sendNotification (index) {
  68. this.$ipc.send('example.sendNotification', this.views[index]);
  69. },
  70. }
  71. };
  72. </script>
  73. <style lang="less" scoped>
  74. #app-demo-notification {
  75. padding: 0px 10px;
  76. text-align: left;
  77. width: 100%;
  78. .one-block-1 {
  79. font-size: 16px;
  80. padding-top: 10px;
  81. }
  82. .one-block-2 {
  83. padding-top: 10px;
  84. }
  85. }
  86. </style>