64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { Component, ElementRef, OnInit, Renderer2 } from '@angular/core';
|
|
import { NavigationEnd, NavigationError, RouteConfigLoadStart, Router } from '@angular/router';
|
|
import { TitleService, VERSION as VERSION_ALAIN } from '@delon/theme';
|
|
import { environment } from '@env/environment';
|
|
import { NzIconService } from 'ng-zorro-antd/icon';
|
|
import { NzModalService } from 'ng-zorro-antd/modal';
|
|
import { VERSION as VERSION_ZORRO } from 'ng-zorro-antd/version';
|
|
import { ThemeService } from './theme.service';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
template: ` <router-outlet></router-outlet> `
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
constructor(
|
|
el: ElementRef,
|
|
renderer: Renderer2,
|
|
private router: Router,
|
|
private titleSrv: TitleService,
|
|
private modalSrv: NzModalService,
|
|
private iconService: NzIconService,
|
|
private themeService: ThemeService
|
|
) {
|
|
renderer.setAttribute(el.nativeElement, 'ng-alain-version', VERSION_ALAIN.full);
|
|
renderer.setAttribute(el.nativeElement, 'ng-zorro-version', VERSION_ZORRO.full);
|
|
this.iconService.fetchFromIconfont({
|
|
scriptUrl: 'https://at.alicdn.com/t/font_3153207_udngwyp35db.js'
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
let configLoad = false;
|
|
this.router.events.subscribe(ev => {
|
|
if (ev instanceof RouteConfigLoadStart) {
|
|
configLoad = true;
|
|
}
|
|
if (configLoad && ev instanceof NavigationError) {
|
|
this.modalSrv.confirm({
|
|
nzTitle: `提醒`,
|
|
nzContent: environment.production ? `应用可能已发布新版本,请点击刷新才能生效。` : `无法加载路由:${ev.url}`,
|
|
nzCancelDisabled: false,
|
|
nzOkText: '刷新',
|
|
nzCancelText: '忽略',
|
|
nzOnOk: () => location.reload()
|
|
});
|
|
}
|
|
if (ev instanceof NavigationEnd) {
|
|
this.titleSrv.setTitle();
|
|
this.modalSrv.closeAll();
|
|
}
|
|
});
|
|
// 适配放大150%的屏幕
|
|
const screen: any = window.screen
|
|
var zoom = window.devicePixelRatio || screen.deviceXDPI / screen?.logicalXDPI;
|
|
// console.log(zoom)
|
|
if (document.body.clientWidth >= 1280) {
|
|
if (zoom != 1 && zoom != 2 && zoom != 3) {
|
|
this.themeService.toggleTheme().then();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|