edit
This commit is contained in:
@ -13,43 +13,39 @@ import {
|
||||
import { sysConf } from '@conf/sys.conf';
|
||||
import { CoreService } from '@core';
|
||||
import { ACLGuard, ACLService } from '@delon/acl';
|
||||
import { EAUserService } from '@shared';
|
||||
import { MenuService } from '@delon/theme';
|
||||
import { BaseService, EAUserService } from '@shared';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
const auths = ['YUNLI-CART-SEARCH', 'YUNLI-CART-DAOCHU', 'YUNLI-CART-DETAIL'];
|
||||
const auths = ['YUNLI-CART-SEARCH', 'YUNLI-CART-DAOC1HU', 'YUNLI-CART-DETAIL', 'YUNLI-CART-AUDIT-SEARCH'];
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
|
||||
constructor(srv: ACLService, router: Router, private eaUserSrv: CoreService, private router2: Router, private inject: Injector) {}
|
||||
constructor(private srv: ACLService, router: Router, private baseService: BaseService, private menuService: MenuService) {}
|
||||
canLoad(route: Route, segments: UrlSegment[]): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
|
||||
console.log(route);
|
||||
|
||||
throw true;
|
||||
return 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);
|
||||
return this.handle();
|
||||
}
|
||||
|
||||
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);
|
||||
return this.handle();
|
||||
}
|
||||
|
||||
private handle(): Observable<boolean> {
|
||||
// 1
|
||||
return this.baseService.request('/api/mdc/cuc/user/getUserDetail').pipe(
|
||||
map(_ => {
|
||||
console.log(this.srv.data);
|
||||
this.srv.setAbility(auths);
|
||||
this.menuService.resume();
|
||||
console.log(this.srv.data);
|
||||
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user