123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /*
- * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import { HttpClient } from '@angular/common/http';
- import { Inject, Injectable } from '@angular/core';
- import { Router } from '@angular/router';
- import { ACLService } from '@delon/acl';
- import { ALAIN_I18N_TOKEN, MenuService, SettingsService, TitleService } from '@delon/theme';
- import { NzSafeAny } from 'ng-zorro-antd/core/types';
- import { NzIconService } from 'ng-zorro-antd/icon';
- import { Observable, zip } from 'rxjs';
- import { catchError, map } from 'rxjs/operators';
- import { ICONS } from '../../../style-icons';
- import { ICONS_AUTO } from '../../../style-icons-auto';
- import { I18NService } from '../i18n/i18n.service';
- /**
- * Used for application startup
- * Generally used to get the basic data of the application, like: Menu Data, User Data, etc.
- */
- @Injectable()
- export class StartupService {
- constructor(
- iconSrv: NzIconService,
- private menuService: MenuService,
- @Inject(ALAIN_I18N_TOKEN) private i18n: I18NService,
- private settingService: SettingsService,
- private aclService: ACLService,
- private titleService: TitleService,
- private httpClient: HttpClient,
- private router: Router
- ) {
- iconSrv.addIcon(...ICONS_AUTO, ...ICONS);
- }
- load(): Observable<void> {
- const defaultLang = this.i18n.defaultLang;
- return zip(this.i18n.loadLangData(defaultLang), this.httpClient.get('./assets/app-data.json')).pipe(
- // 接收其他拦截器后产生的异常消息
- catchError(res => {
- console.warn(`StartupService.load: Network request failed`, res);
- setTimeout(() => this.router.navigateByUrl(`/exception/500`));
- return [];
- }),
- map(([langData, appData]: [Record<string, string>, NzSafeAny]) => {
- // setting language data
- this.i18n.use(defaultLang, langData);
- // 应用信息:包括站点名、描述、年份
- this.settingService.setApp(appData.app);
- // 用户信息:包括姓名、头像、邮箱地址
- //this.settingService.setUser(appData.user);
- // ACL:设置权限为全量
- this.aclService.setFull(false);
- // 初始化菜单
- this.menuService.add(appData.menu);
- // 设置页面标题的后缀
- this.titleService.default = '';
- this.titleService.suffix = appData.app.name;
- })
- );
- }
- }
|