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.
43 lines
1.3 KiB
43 lines
1.3 KiB
import { Component } from '@angular/core'; |
|
import { HttpClient } from '@angular/common/http' |
|
import { Router,ActivatedRoute } from '@angular/router' |
|
import { IsLoginService } from './is-login.service' //引入服务 |
|
import {CacheTokenService} from './http-interceptors/cache-token.service' //引入服务 |
|
|
|
|
|
|
|
@Component({ |
|
selector: 'app-root', |
|
templateUrl: './app.component.html', |
|
styleUrls: ['./app.component.scss'] |
|
}) |
|
export class AppComponent { |
|
|
|
constructor(private http:HttpClient,private router:Router,public token:CacheTokenService,public isLogin:IsLoginService) { } |
|
|
|
ngOnInit(): void { |
|
|
|
let token = sessionStorage.getItem("token"); |
|
let refreshToken = sessionStorage.getItem("refreshToken"); |
|
if(token && refreshToken) { |
|
this.http.post('/api/ExamAccounts/RefreshToken', { |
|
token: token, |
|
refreshToken: refreshToken |
|
}).subscribe((data:any) => { |
|
sessionStorage.setItem("realName",data.realName); |
|
sessionStorage.setItem("roleType",data.roleType); |
|
sessionStorage.setItem("token",data.token); |
|
sessionStorage.setItem("refreshToken",data.refreshToken); |
|
sessionStorage.setItem("level",data.level); |
|
this.token.startUp() |
|
}) |
|
} else { |
|
sessionStorage.clear() |
|
this.token.delete() |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}
|
|
|