考核考试系统
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.
 
 
 
 
 

38 lines
1.1 KiB

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class CacheTokenService {
constructor(private http:HttpClient) { }
public timer;
//刷新token令牌定时器
startUp = ():void=>{
window.clearInterval(this.timer) //清一遍定时器
this.timer = window.setInterval(()=>{
var token = sessionStorage.getItem("token");
var refreshToken = sessionStorage.getItem("refreshToken");
if (token && refreshToken) {
this.http.post('/api/Account/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);
})
} else { this.delete() }
},18*60*1000)
}
//删除定时器
delete = ():void=> {
window.clearInterval(this.timer)
}
}