数据可视化大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8KB

  1. import { Component, ElementRef, OnInit, Renderer2, inject } from '@angular/core';
  2. import { NavigationEnd, NavigationError, RouteConfigLoadStart, Router, RouterOutlet } from '@angular/router';
  3. import { TitleService, VERSION as VERSION_ALAIN, stepPreloader } from '@delon/theme';
  4. import { environment } from '@env/environment';
  5. import { NzModalService } from 'ng-zorro-antd/modal';
  6. import { VERSION as VERSION_ZORRO } from 'ng-zorro-antd/version';
  7. @Component({
  8. selector: 'app-root',
  9. template: ` <router-outlet />`,
  10. standalone: true,
  11. imports: [RouterOutlet]
  12. })
  13. export class AppComponent implements OnInit {
  14. private readonly router = inject(Router);
  15. private readonly titleSrv = inject(TitleService);
  16. private readonly modalSrv = inject(NzModalService);
  17. private donePreloader = stepPreloader();
  18. constructor(el: ElementRef, renderer: Renderer2) {
  19. renderer.setAttribute(el.nativeElement, 'ng-alain-version', VERSION_ALAIN.full);
  20. renderer.setAttribute(el.nativeElement, 'ng-zorro-version', VERSION_ZORRO.full);
  21. }
  22. ngOnInit(): void {
  23. let configLoad = false;
  24. this.router.events.subscribe(ev => {
  25. if (ev instanceof RouteConfigLoadStart) {
  26. configLoad = true;
  27. }
  28. if (configLoad && ev instanceof NavigationError) {
  29. this.modalSrv.confirm({
  30. nzTitle: `提醒`,
  31. nzContent: environment.production ? `应用可能已发布新版本,请点击刷新才能生效。` : `无法加载路由:${ev.url}`,
  32. nzCancelDisabled: false,
  33. nzOkText: '刷新',
  34. nzCancelText: '忽略',
  35. nzOnOk: () => location.reload()
  36. });
  37. }
  38. if (ev instanceof NavigationEnd) {
  39. this.donePreloader();
  40. this.titleSrv.setTitle();
  41. this.modalSrv.closeAll();
  42. }
  43. });
  44. }
  45. }