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