import { Injectable, Inject } from '@angular/core'; import { Router } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; import { ALAIN_I18N_TOKEN, MenuService, SettingsService, TitleService } from '@delon/theme'; import { ACLService } from '@delon/acl'; import { Observable, zip, of, catchError, map } from 'rxjs'; import type { NzSafeAny } from 'ng-zorro-antd/core/types'; import { NzIconService } from 'ng-zorro-antd/icon'; import { ICONS } from '../../../style-icons'; import { ICONS_AUTO } from '../../../style-icons-auto'; /** * 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, private settingService: SettingsService, private aclService: ACLService, private titleService: TitleService, @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private httpClient: HttpClient, private router: Router ) { iconSrv.addIcon(...ICONS_AUTO, ...ICONS); } private viaHttp(): Observable { return this.httpClient.get('assets/tmp/app-data.json').pipe( catchError((res: NzSafeAny) => { console.warn(`StartupService.load: Network request failed`, res); setTimeout(() => this.router.navigateByUrl(`/exception/500`)); return of({}); }), map((res: NzSafeAny) => { // Application information: including site name, description, year this.settingService.setApp(res.app); // User information: including name, avatar, email address this.settingService.setUser(res.user); // ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started this.aclService.setFull(true); // Menu data, https://ng-alain.com/theme/menu this.menuService.add(res.menu); // Can be set page suffix title, https://ng-alain.com/theme/title this.titleService.suffix = res.app.name; }) ); } private viaMock(): Observable { // const tokenData = this.tokenService.get(); // if (!tokenData.token) { // this.router.navigateByUrl(this.tokenService.login_url!); // return; // } // mock const app: any = { name: `ng-alain`, description: `Ng-zorro admin panel front-end framework` }; const user: any = { name: 'Admin', avatar: './assets/tmp/img/avatar.jpg', email: 'cipchk@qq.com', token: '123456789' }; // Application information: including site name, description, year this.settingService.setApp(app); // User information: including name, avatar, email address this.settingService.setUser(user); // ACL: Set the permissions to full, https://ng-alain.com/acl/getting-started this.aclService.setFull(true); // Menu data, https://ng-alain.com/theme/menu this.menuService.add([ { text: 'Main', group: true, children: [ { text: 'Dashboard', link: '/dashboard', icon: { type: 'icon', value: 'appstore' } } , { text: 'Micro1', icon: { type: 'icon', value: 'appstore' }, children: [ { text: '主导航', group: true, hideInBreadcrumb: true, children: [ { text: '仪表盘', icon: 'anticon-dashboard', children: [ { text: '默认页', link: '/micro1/dashboard/v1', }, { text: '分析页', link: '/micro1/dashboard/analysis', }, { text: '监控页', link: '/micro1/dashboard/monitor', }, { text: '工作台', link: '/micro1/dashboard/workplace', } ] }, { text: '小部件', link: '/micro1/widgets', icon: 'anticon-appstore', } ] }, { text: 'Alain', group: true, hideInBreadcrumb: true, children: [ { text: '样式', icon: 'anticon-info', children: [ { text: '字体排印', link: '/micro1/style/typography', }, { text: '瀑布流', link: '/micro1/style/gridmasonry', }, { text: '色彩', link: '/micro1/style/colors', } ] }, { text: 'Delon 类库', icon: 'anticon-bulb', children: [ { text: '动态表单', link: '/micro1/delon/form', }, { text: '简易表格', link: '/micro1/delon/st', }, { text: '工具集', link: '/micro1/delon/util', }, { text: '打印', link: '/micro1/delon/print', }, { text: '二维码', link: '/micro1/delon/qr', }, { text: '基于角色访问控制', link: '/micro1/delon/acl', }, { text: '路由守卫', link: '/micro1/delon/guard', }, { text: '字典缓存', link: '/micro1/delon/cache', }, { text: '下载文件', link: '/micro1/delon/downfile', }, { text: 'Excel操作', link: '/micro1/delon/xlsx', }, { text: '本地解压缩', link: '/micro1/delon/zip', } ] } ] }, { text: 'Antd Pro', group: true, hideInBreadcrumb: true, children: [ { text: '表单页', link: '/micro1/pro/form', icon: 'anticon-edit', children: [ { text: '基础表单', link: '/micro1/pro/form/basic-form', }, { text: '分步表单', link: '/micro1/pro/form/step-form', }, { text: '高级表单', link: '/micro1/pro/form/advanced-form', } ] }, { text: '列表页', icon: 'anticon-appstore', children: [ { text: '查询表格', link: '/micro1/pro/list/table-list', }, { text: '标准列表', link: '/micro1/pro/list/basic-list', }, { text: '卡片列表', link: '/micro1/pro/list/card-list', }, { text: '搜索列表', children: [ { text: '搜索列表(文章)', link: '/micro1/pro/list/articles', }, { text: '搜索列表(项目)', link: '/micro1/pro/list/projects', }, { text: '搜索列表(应用)', link: '/micro1/pro/list/applications', } ] } ] }, { text: '详情页', icon: 'anticon-profile', children: [ { text: '基础详情页', link: '/micro1/pro/profile/basic', }, { text: '高级详情页', link: '/micro1/pro/profile/advanced', } ] }, { text: '结果页', icon: 'anticon-check-circle', children: [ { text: '成功页', link: '/micro1/pro/result/success', }, { text: '失败页', link: '/micro1/pro/result/fail', } ] }, { text: '异常页', link: '/micro1/', icon: 'anticon-exception', children: [ { text: '403', link: '/micro1/exception/403', }, { text: '404', link: '/micro1/exception/404', }, { text: '500', link: '/micro1/exception/500', } ] }, { text: '个人页', icon: 'anticon-user', children: [ { text: '个人中心', link: '/micro1/pro/account/center', }, { text: '个人设置', link: '/micro1/pro/account/settings', } ] } ] }, { text: '更多', group: true, hideInBreadcrumb: true, children: [ { text: '报表', icon: 'anticon-cloud', children: [ { text: '全屏关系图', link: '/micro1/data-v/relation', } ] }, { text: '扩展', link: '/micro1/extras', icon: 'anticon-link', children: [ { text: '帮助中心', link: '/micro1/extras/helpcenter', }, { text: '设置', link: '/micro1/extras/settings', }, { text: '门店', link: '/micro1/extras/poi', } ] } ] } ] }, ] } ]); // Can be set page suffix title, https://ng-alain.com/theme/title this.titleService.suffix = app.name; return of(void 0); } load(): Observable { // http // return this.viaHttp(); // mock: Don’t use it in a production environment. ViaMock is just to simulate some data to make the scaffolding work normally // mock:请勿在生产环境中这么使用,viaMock 单纯只是为了模拟一些数据使脚手架一开始能正常运行 return this.viaMock(); } }