app-notice-service.ts 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
import { VNode } from "vue";
import { AppNotice } from "../../utils/app-notice/app-notice";
import { NoticeOptions } from "../../utils/app-notice/interface/notice-options";

/**
 * 应用通知服务类
 *
 * @export
 * @class AppNoticeService
 */
 export class AppNoticeService {

    /**
     * 唯一实例
     * 
     * @private
     * @static
     * @memberof AppNoticeService
     */
    private static readonly instance = new AppNoticeService();

    /**
     * 获取唯一实例
     *
     * @static
     * @return {*}  {AppNoticeService}
     * @memberof AppNoticeService
     */
    public static getInstance(): AppNoticeService {
        return AppNoticeService.instance;
    }

    /**
     * 成功信息提示
     *
     * @param {(string | VNode)} message
     * @param {NoticeOptions} [options={}]
     * @memberof AppNoticeService
     */
    public success(message: string | VNode, options: NoticeOptions = {}){
        options.type = 'success';
        options.message = message;
        AppNotice.getInstance().open(options);
    }

    /**
     * 警告信息提示
     *
     * @param {(string | VNode)} message
     * @param {NoticeOptions} [options={}]
     * @memberof AppNoticeService
     */
    public warning(message: string | VNode, options: NoticeOptions = {}){
        options.type = 'warning';
        options.message = message;
        AppNotice.getInstance().open(options);
    }

    /**
     * 普通信息提示
     *
     * @param {(string | VNode)} message
     * @param {NoticeOptions} [options={}]
     * @memberof AppNoticeService
     */
    public info(message: string | VNode, options: NoticeOptions = {}){
        options.type = 'info';
        options.message = message;
        AppNotice.getInstance().open(options);
    }

    /**
     * 错误信息提示
     *
     * @param {(string | VNode)} message
     * @param {NoticeOptions} [options={}]
     * @memberof AppNoticeService
     */
    public error(message: string | VNode, options: NoticeOptions = {}){
        options.type = 'error';
        options.message = message;
        AppNotice.getInstance().open(options);
    }

    /**
     * 打开信息提示
     *
     * @param {NoticeOptions} options
     * @memberof AppNoticeService
     */
    public open(options: NoticeOptions){
        if(!options){
            return
        }
        AppNotice.getInstance().open(options);
    }
}