import { Component, OnInit, Inject } from '@angular/core'; import { Router } from '@angular/router'; import { SettingsService } from '@delon/theme'; import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; import { CacheService } from '@delon/cache'; @Component({ selector: 'header-user', template: `
{{settings.user.name}}
个人中心
设置
  • 退出登录
    ` }) export class HeaderUserComponent implements OnInit { constructor( public settings: SettingsService, private router: Router, private cacheService:CacheService, @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) {} ngOnInit(): void { this.cacheService.get('userdata').subscribe((data:any)=>{ this.settings.setUser({name:data.username}); }) // this.tokenService.change().subscribe((res: any) => { // this.settings.setUser(res); // }); // // mock // const token = this.tokenService.get() || { // token: 'nothing', // name: 'Admin', // avatar: './assets/img/zorro.svg', // email: 'cipchk@qq.com' // }; // this.tokenService.set(token); } logout() { this.tokenService.clear(); this.cacheService.clear(); this.router.navigateByUrl(this.tokenService.login_url); } }