[webapp,manager] 路由守卫,升级sureness

This commit is contained in:
tomsun28
2021-12-21 15:39:53 +08:00
parent 0bc7d4751a
commit a22548a06d
5 changed files with 36 additions and 5 deletions

View File

@@ -0,0 +1,27 @@
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from "@angular/router";
import {Observable} from "rxjs";
import {Injectable} from "@angular/core";
import {LocalStorageService} from "../../service/local-storage.service";
import {NzNotificationService} from "ng-zorro-antd/notification";
@Injectable({
providedIn: 'root'
})
export class DetectAuthGuard implements CanActivate {
constructor(private localStorageSvc : LocalStorageService,
private notifySvc: NzNotificationService,
private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
let activate = this.localStorageSvc.hasAuthorizationToken();
if (!activate) {
setTimeout(() => {
this.notifySvc.warning('请先登陆!','')
this.router.navigateByUrl('/passport/login');
});
}
return activate;
}
}