1234567891011121314151617181920212223242526272829303132333435363738 |
- import type { NotifyOptions as VantNotifyOptions, NotifyType as VantNotifyType } from 'vant';
- import { closeNotify, showNotify } from 'vant';
- import 'vant/es/notify/style';
- type NotifyType = 'info' | 'success' | 'error' | 'warning'
- type NotifyOptions = Omit<VantNotifyOptions, 'type' | 'message'>;
- export class Notify {
- static Type: Record<NotifyType, string> = {
- info: 'primary',
- success: 'success',
- error: 'danger',
- warning: 'warning',
- };
- static show(type: NotifyType, message: string, options?: NotifyOptions) {
- const notifyRef = showNotify({ type: this.Type[type] as VantNotifyType, message, ...options });
- return { notifyRef, close: Notify.close };
- }
- static close() { closeNotify(); }
- static info(message: string, options?: NotifyOptions) {
- return this.show('info', message, options);
- }
- static success(message: string, options?: NotifyOptions) {
- return this.show('success', message, options);
- }
- static warning(message: string, options?: NotifyOptions) {
- return this.show('warning', message, options);
- }
- static error(message: string, options?: NotifyOptions) {
- return this.show('error', message, options);
- }
- }
|