edit
This commit is contained in:
53
src/app/core/guards/auth.guard.ts
Normal file
53
src/app/core/guards/auth.guard.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { Inject, Injectable, Injector } from '@angular/core';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
CanActivate,
|
||||
CanActivateChild,
|
||||
CanLoad,
|
||||
Route,
|
||||
Router,
|
||||
RouterStateSnapshot,
|
||||
UrlSegment,
|
||||
UrlTree
|
||||
} from '@angular/router';
|
||||
import { sysConf } from '@conf/sys.conf';
|
||||
import { CoreService } from '@core';
|
||||
import { ACLGuard, ACLService } from '@delon/acl';
|
||||
import { EAUserService } from '@shared';
|
||||
import { Observable, of } from 'rxjs';
|
||||
|
||||
const auths = ['YUNLI-CART-SEARCH', 'YUNLI-CART-DAOCHU', 'YUNLI-CART-DETAIL'];
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
|
||||
constructor(srv: ACLService, router: Router, private eaUserSrv: CoreService, private router2: Router, private inject: Injector) {}
|
||||
canLoad(route: Route, segments: UrlSegment[]): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
|
||||
throw true;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot | null): Observable<boolean> {
|
||||
const canOpen = this.eaUserSrv.loginStatus;
|
||||
if (!canOpen) {
|
||||
this.router2.navigate([sysConf.login_url], {
|
||||
queryParams: {
|
||||
returnUrl: _state?.url
|
||||
}
|
||||
});
|
||||
return of(!canOpen);
|
||||
}
|
||||
return of(true);
|
||||
}
|
||||
|
||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
const canOpen = this.eaUserSrv.loginStatus;
|
||||
if (!canOpen) {
|
||||
this.router2.navigate([sysConf.login_url], {
|
||||
queryParams: {
|
||||
returnUrl: state?.url
|
||||
}
|
||||
});
|
||||
return of(!canOpen);
|
||||
}
|
||||
return of(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user