index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <PageWrapper title="消息示例">
  3. <CollapseContainer class="w-full h-32 bg-white rounded-md" title="Message">
  4. <a-button @click="infoMsg('Info message')" class="mr-2"> Info </a-button>
  5. <a-button @click="successMsg('Success message')" class="mr-2" color="success">
  6. Success
  7. </a-button>
  8. <a-button @click="warningMsg('Warning message')" class="mr-2" color="warning">
  9. Warning
  10. </a-button>
  11. <a-button @click="errorMsg('Error message')" class="mr-2" color="error"> Error </a-button>
  12. <a-button @click="handleLoading" class="mr-2" type="primary"> Loading </a-button>
  13. </CollapseContainer>
  14. <CollapseContainer class="w-full h-32 mt-5 bg-white rounded-md" title="Comfirm">
  15. <a-button @click="handleConfirm('info')" class="mr-2"> Info </a-button>
  16. <a-button @click="handleConfirm('warning')" color="warning" class="mr-2"> Warning </a-button>
  17. <a-button @click="handleConfirm('success')" color="success" class="mr-2"> Success </a-button>
  18. <a-button @click="handleConfirm('error')" color="error" class="mr-2"> Error </a-button>
  19. </CollapseContainer>
  20. <CollapseContainer class="w-full h-32 mt-5 bg-white rounded-md" title="Modal">
  21. <a-button @click="handleInfoModal" class="mr-2"> Info </a-button>
  22. <a-button @click="handleSuccessModal" color="success" class="mr-2"> Success </a-button>
  23. <a-button @click="handleErrorModal" color="error" class="mr-2"> Error </a-button>
  24. <a-button @click="handleWarningModal" color="warning" class="mr-2"> Warning </a-button>
  25. </CollapseContainer>
  26. <CollapseContainer
  27. class="w-full h-32 mt-5 bg-white rounded-md"
  28. title="Notification 用法与上面一致"
  29. >
  30. <a-button @click="handleNotify" color="success" class="mr-2"> Success </a-button>
  31. </CollapseContainer>
  32. </PageWrapper>
  33. </template>
  34. <script lang="ts">
  35. import { defineComponent } from 'vue';
  36. import { CollapseContainer } from '/@/components/Container/index';
  37. import { useMessage } from '/@/hooks/web/useMessage';
  38. import { PageWrapper } from '/@/components/Page';
  39. export default defineComponent({
  40. components: { CollapseContainer, PageWrapper },
  41. setup() {
  42. const {
  43. createMessage,
  44. createConfirm,
  45. createSuccessModal,
  46. createInfoModal,
  47. createErrorModal,
  48. createWarningModal,
  49. notification,
  50. } = useMessage();
  51. const { info, success, warning, error } = createMessage;
  52. function handleLoading() {
  53. createMessage.loading('Loading...');
  54. }
  55. function handleConfirm(type: 'warning' | 'error' | 'success' | 'info') {
  56. createConfirm({
  57. iconType: type,
  58. title: 'Tip',
  59. content: 'content message...',
  60. });
  61. }
  62. function handleSuccessModal() {
  63. createSuccessModal({ title: 'Tip', content: 'content message...' });
  64. }
  65. function handleErrorModal() {
  66. createErrorModal({ title: 'Tip', content: 'content message...' });
  67. }
  68. function handleWarningModal() {
  69. createWarningModal({ title: 'Tip', content: 'content message...' });
  70. }
  71. function handleInfoModal() {
  72. createInfoModal({ title: 'Tip', content: 'content message...' });
  73. }
  74. function handleNotify() {
  75. notification.success({
  76. message: 'Tip',
  77. description: 'content message...',
  78. });
  79. }
  80. return {
  81. infoMsg: info,
  82. successMsg: success,
  83. warningMsg: warning,
  84. errorMsg: error,
  85. handleLoading,
  86. handleConfirm,
  87. handleSuccessModal,
  88. handleErrorModal,
  89. handleWarningModal,
  90. handleInfoModal,
  91. handleNotify,
  92. };
  93. },
  94. });
  95. </script>