app-loading-service.ts 1.5 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
import { LoadingServiceBase } from './loading-service-base';

/**
 * 应用加载服务类
 *
 * @export
 * @class AppLoadingService
 * @extends {LoadingServiceBase}
 */
export class AppLoadingService extends LoadingServiceBase {

    /**
     * 单例变量声明
     *
     * @private
     * @static
     * @type {AppLoading}
     * @memberof AppLoadingService
     */
    private static appLoading: AppLoadingService;

    /**
     * 获取AppLoading单例对象
     *
     * @static
     * @returns {AppLoadingService}
     * @memberof AppLoadingService
     */
    public static getInstance(): AppLoadingService {
        if (!this.appLoading) {
            this.appLoading = new AppLoadingService();
        }
        return this.appLoading;
    }


    /**
     * 统计加载
     *
     * @type {number}
     * @memberof AppLoadingService
     */
    private loadingCount: number = 0;


    /**
     * 加载结束
     *
     * @public
     * @memberof AppLoadingService
     */
    public endLoading(): void {
        const body = document.querySelector('body');
        if (this.loadingCount > 0) {
            this.loadingCount--;
        }
        if (this.loadingCount === 0) {
            super.endLoading(body);
        }
    }

    /**
     * 应用加载
     *
     * @public
     * @memberof AppLoadingService
     */
    public beginLoading() {
        const body = document.querySelector('body');
        if (!this.isLoading) {
            super.beginLoading(body)
        }
        this.loadingCount++;
        this.isLoading = true;
    }

}