notify.ui.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { NotifyOptions as VantNotifyOptions, NotifyType as VantNotifyType } from 'vant';
  2. import { closeNotify, showNotify } from 'vant';
  3. import 'vant/es/notify/style';
  4. type NotifyType = 'info' | 'success' | 'error' | 'warning'
  5. type NotifyOptions = Omit<VantNotifyOptions, 'type' | 'message'>;
  6. export class Notify {
  7. static Type: Record<NotifyType, string> = {
  8. info: 'primary',
  9. success: 'success',
  10. error: 'danger',
  11. warning: 'warning',
  12. };
  13. static show(type: NotifyType, message: string, options?: NotifyOptions) {
  14. const notifyRef = showNotify({ type: this.Type[type] as VantNotifyType, message, ...options });
  15. return { notifyRef, close: Notify.close };
  16. }
  17. static close() { closeNotify(); }
  18. static info(message: string, options?: NotifyOptions) {
  19. return this.show('info', message, options);
  20. }
  21. static success(message: string, options?: NotifyOptions) {
  22. return this.show('success', message, options);
  23. }
  24. static warning(message: string, options?: NotifyOptions) {
  25. return this.show('warning', message, options);
  26. }
  27. static error(message: string, options?: NotifyOptions) {
  28. return this.show('error', message, options);
  29. }
  30. }