edit
This commit is contained in:
@ -1,16 +1,31 @@
|
||||
import { Inject, Injectable, Injector } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router';
|
||||
import { ACLGuard, ACLService } from '@delon/acl';
|
||||
import {
|
||||
ActivatedRouteSnapshot,
|
||||
CanActivate,
|
||||
CanActivateChild,
|
||||
CanDeactivate,
|
||||
CanLoad,
|
||||
Data,
|
||||
Route,
|
||||
Router,
|
||||
RouterStateSnapshot,
|
||||
UrlTree
|
||||
} from '@angular/router';
|
||||
import { ACLCanType, ACLGuard, ACLGuardType, ACLService } from '@delon/acl';
|
||||
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-DAOC1HU', 'YUNLI-CART-DETAIL', 'YUNLI-CART-AUDIT-SEARCH'];
|
||||
import { delay, map, switchMap, tap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
constructor(private srv: ACLService, private baseService: BaseService, private menuService: MenuService) {}
|
||||
constructor(
|
||||
private srv: ACLService,
|
||||
private baseService: BaseService,
|
||||
private menuService: MenuService,
|
||||
private router: Router,
|
||||
private injector: Injector
|
||||
) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot | null): Observable<boolean> {
|
||||
if (Object.keys(route.params)?.length > 0 || !route.routeConfig?.path) {
|
||||
@ -28,24 +43,29 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
if (!route) {
|
||||
return of(true);
|
||||
}
|
||||
console.log(route);
|
||||
|
||||
return this.baseService.request('/api/mdc/cuc/functionButton/getPermissionsCodeoByLink', { link: route }).pipe(
|
||||
map(_ => {
|
||||
this.srv.setAbility(auths);
|
||||
this.menuService.resume();
|
||||
return true;
|
||||
switchMap(res => {
|
||||
if (res) {
|
||||
this.srv.setAbility(res.permissionsCodeList || []);
|
||||
this.menuService.resume();
|
||||
}
|
||||
|
||||
return of(true);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private settingRoute(params: any, route: string) {
|
||||
let _route = route;
|
||||
if (_route.indexOf('?') > -1) {
|
||||
_route = route.split('?')[0];
|
||||
}
|
||||
for (const key of Object.keys(params)) {
|
||||
if (_route.indexOf(params[key]) > -1) {
|
||||
_route = _route.replace(params[key], ':id');
|
||||
}
|
||||
}
|
||||
|
||||
return _route;
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ export class StartupService {
|
||||
enterpriseId: userData?.enterpriseId || sysConf.enterpriseId
|
||||
});
|
||||
// ACL:设置权限为全量
|
||||
this.aclService.setFull(true);
|
||||
this.aclService.setFull(false);
|
||||
// 初始化菜单
|
||||
this.menuService.add(menuData);
|
||||
// 设置页面标题的后缀
|
||||
|
||||
Reference in New Issue
Block a user