edit
This commit is contained in:
@ -1,17 +1,5 @@
|
||||
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 { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router';
|
||||
import { ACLGuard, ACLService } from '@delon/acl';
|
||||
import { MenuService } from '@delon/theme';
|
||||
import { BaseService, EAUserService } from '@shared';
|
||||
@ -21,31 +9,43 @@ import { map } from 'rxjs/operators';
|
||||
const auths = ['YUNLI-CART-SEARCH', 'YUNLI-CART-DAOC1HU', 'YUNLI-CART-DETAIL', 'YUNLI-CART-AUDIT-SEARCH'];
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild, CanLoad {
|
||||
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> {
|
||||
return true;
|
||||
}
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
constructor(private srv: ACLService, private baseService: BaseService, private menuService: MenuService) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot | null): Observable<boolean> {
|
||||
if (Object.keys(route.params)?.length > 0 || !route.routeConfig?.path) {
|
||||
return this.handle();
|
||||
} else {
|
||||
return this.handle(_state?.url);
|
||||
}
|
||||
}
|
||||
|
||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
return this.handle();
|
||||
return this.handle(this.settingRoute(childRoute.params, state.url));
|
||||
}
|
||||
|
||||
private handle(): Observable<boolean> {
|
||||
// 1
|
||||
return this.baseService.request('/api/mdc/cuc/user/getUserDetail').pipe(
|
||||
private handle(route?: string): Observable<boolean> {
|
||||
if (!route) {
|
||||
return of(true);
|
||||
}
|
||||
console.log(route);
|
||||
|
||||
return this.baseService.request('/api/mdc/cuc/user/getUserDetail', { link: route }).pipe(
|
||||
map(_ => {
|
||||
console.log(this.srv.data);
|
||||
this.srv.setAbility(auths);
|
||||
this.menuService.resume();
|
||||
console.log(this.srv.data);
|
||||
|
||||
return true;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private settingRoute(params: any, route: string) {
|
||||
let _route = route;
|
||||
for (const key of Object.keys(params)) {
|
||||
if (_route.indexOf(params[key]) > -1) {
|
||||
_route = _route.replace(params[key], ':id');
|
||||
}
|
||||
}
|
||||
return _route;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +249,6 @@ export class VehicleComponentsListComponent implements OnInit {
|
||||
buttons: [
|
||||
{
|
||||
text: '查看',
|
||||
acl: 'SUPPLY-INDEX-bulkSearch',
|
||||
click: item => {
|
||||
this.router.navigate(['./detail', item.id], { relativeTo: this.ar, queryParams: { carId: item.carId } });
|
||||
// this.router.navigate(['./view', item.id], { relativeTo: this.ar, queryParams: { tenantId: item.tenantId } });
|
||||
|
||||
@ -18,7 +18,6 @@ import { VehicleComponentsListComponent } from './components/list/list.component
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
canLoad: [AuthGuard],
|
||||
canActivate: [AuthGuard],
|
||||
canActivateChild: [AuthGuard],
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user