import { Component, OnInit, Inject } from '@angular/core'; import { NaSettingsService, NaTitleService, NaTranslateService, NaStartupService, NaMessageService, NaLocalStorageService } from '@ng-arthur-mobile/core'; import { Router, NavigationEnd } from '@angular/router'; import { filter } from 'rxjs/operators'; import { HttpClient } from '@angular/common/http'; import { NaHttpService } from '../../projects/http/src/lib/na-http.service'; import { DOCUMENT } from '@angular/common'; import { SwUpdate } from '@angular/service-worker'; @Component({ selector: 'na-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { constructor( private swUpdate: SwUpdate, // private settings: NaSettingsService, // private router: Router, // private title: NaTitleService, // private log: NaLogService, private client: HttpClient, private message: NaMessageService, // private i18n: NaTranslateService, private translate: NaTranslateService, private naHttpService: NaHttpService, private startupService: NaStartupService, private localStorage: NaLocalStorageService, private naMessageService: NaMessageService, @Inject(DOCUMENT) private _doc: any ) { // this.i18n.use('zh'); // this.log.success('---'); } ngOnInit() { const version = this.startupService.get('version'); const exist = this.localStorage.get('VERSION'); if (version && exist && exist !== version) { this._doc.location.reload(); // 重载当前页面 } this.localStorage.set('VERSION', version); if (this.swUpdate.isEnabled) { this.swUpdate.available.subscribe(() => { if (confirm('新版本可用。加载新版本?')) { window.location.reload(); } }); } this.naMessageService.loading(''); } }