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.
45 lines
1.3 KiB
45 lines
1.3 KiB
4 years ago
|
import { Component } from '@angular/core';
|
||
|
import { HttpClient } from '@angular/common/http'
|
||
|
import { Data } from './interface'
|
||
|
import { Router,ActivatedRoute } from '@angular/router'
|
||
|
import {CacheTokenService} from './http-interceptors/cache-token.service'//引入服务
|
||
|
import { CookieService } from 'ngx-cookie-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,private cookieService: CookieService) { }
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
var token = this.cookieService.get("token")
|
||
|
var refreshToken = this.cookieService.get("refreshToken");
|
||
|
if(token && refreshToken) {
|
||
|
this.http.post(
|
||
|
'/api/CompanyAccount/RefreshToken',
|
||
|
{
|
||
|
token: token,
|
||
|
refreshToken: refreshToken
|
||
|
}
|
||
|
).subscribe(
|
||
|
(data: Data) => {
|
||
|
sessionStorage.setItem("token",data.token);
|
||
|
this.cookieService.set("token",data.token,null,'/');
|
||
|
this.cookieService.set("refreshToken",data.refreshToken,null,'/');
|
||
|
this.token.startUp()
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|