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.
40 lines
936 B
40 lines
936 B
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"); |
|
this.http.post('/api/Account/RefreshToken', { |
|
token: token, |
|
refreshToken: refreshToken |
|
}).subscribe((data:any) => { |
|
sessionStorage.setItem("level",data.level); |
|
sessionStorage.setItem("token",data.token); |
|
sessionStorage.setItem("refreshToken",data.refreshToken); |
|
}) |
|
},18*60*1000) |
|
|
|
} |
|
|
|
|
|
|
|
//删除定时器 |
|
delete = ():void=> { |
|
window.clearInterval(this.timer) |
|
} |
|
|
|
|
|
|
|
}
|
|
|