NotifyExample.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div>
  3. <h1>Notify Example</h1>
  4. </div>
  5. <a-space>
  6. <a-button @click="show">show方法</a-button>
  7. <a-button @click="notice">notice方法</a-button>
  8. <a-button @click="noticeBig">noticeBig方法</a-button>
  9. <a-button @click="info">info方法</a-button>
  10. <a-button @click="infoBig">infoBig方法</a-button>
  11. <a-button @click="success">success方法</a-button>
  12. <a-button @click="error">error方法</a-button>
  13. <a-button @click="open">antd原生open方法</a-button>
  14. </a-space>
  15. </template>
  16. <script setup>
  17. import { h, ref } from 'vue';
  18. import { Button, notification, message } from 'ant-design-vue';
  19. import Notify from '../../packages/common/Notify.js';
  20. const test = ref('你好');
  21. const handleClose = () => {
  22. message.success(test.value);
  23. };
  24. const show = () => {
  25. Notify.show({
  26. title: '提示',
  27. message: '这是一个提示',
  28. buttons: [
  29. {
  30. label: '确定',
  31. cssClass: 'btn-primary',
  32. action: function (dialogItself) {
  33. console.log('确定', dialogItself);
  34. dialogItself.close();
  35. handleClose();
  36. },
  37. },
  38. {
  39. label: '取消',
  40. action: function (dialogItself) {
  41. console.log('取消', dialogItself);
  42. dialogItself.close();
  43. },
  44. },
  45. ],
  46. });
  47. };
  48. const notice = () => {
  49. Notify.notice('提示', '这是一个提示', 3000);
  50. };
  51. const noticeBig = () => {
  52. Notify.noticeBig('提示', '这是一个提示');
  53. };
  54. const info = () => {
  55. Notify.info('提示', '这是一个提示', 2000);
  56. };
  57. const infoBig = () => {
  58. Notify.infoBig('提示', '这是一个提示', 2000);
  59. };
  60. const success = () => {
  61. Notify.success('提示', '这是一个提示', 6000);
  62. };
  63. const error = () => {
  64. Notify.error('提示', '这是一个提示', 2000);
  65. };
  66. const open = () => {
  67. const key = `notify_${Date.now()}`; // 生成唯一标识
  68. notification.open({
  69. message: '提示',
  70. description: '这是一个提示',
  71. duration: 0,
  72. key,
  73. btn: () =>
  74. h(
  75. Button,
  76. {
  77. type: 'primary',
  78. size: 'small',
  79. onClick: () => {
  80. console.log('确认');
  81. notification.close(key);
  82. },
  83. },
  84. {
  85. default: () => '确认',
  86. },
  87. ),
  88. onClose: console.log('close'),
  89. });
  90. };
  91. </script>