From e72b3727af08822318eecea75494464ecf34b35a Mon Sep 17 00:00:00 2001 From: Taric Xin Date: Mon, 17 Jan 2022 13:27:36 +0800 Subject: [PATCH 1/2] edit --- src/app/app.module.ts | 4 +- src/app/core/guards/auth.guard.ts | 46 +++++++++---------- src/app/core/startup/startup.service.ts | 2 +- src/app/global-config.module.ts | 3 +- .../components/list/list.component.html | 45 +++++++----------- .../routes/vehicle/vehicle-routing.module.ts | 33 +++++++++---- src/assets/mocks/menu-data.json | 6 ++- 7 files changed, 74 insertions(+), 65 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 2c30b188..726c4ce3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -41,7 +41,8 @@ const APPINIT_PROVIDES = [ deps: [StartupService], multi: true }, - { provide: DEFAULT_CURRENCY_CODE, useValue: '¥' } + { provide: DEFAULT_CURRENCY_CODE, useValue: '¥' }, + AuthGuard ]; // #endregion @@ -54,6 +55,7 @@ import { SharedModule } from './shared/shared.module'; import { STWidgetModule } from './shared/widget/st-widget.module'; import { Observable } from 'rxjs'; import { registerLocaleData } from '@angular/common'; +import { AuthGuard } from './core/guards/auth.guard'; @NgModule({ declarations: [AppComponent], diff --git a/src/app/core/guards/auth.guard.ts b/src/app/core/guards/auth.guard.ts index 23ae320d..36560587 100644 --- a/src/app/core/guards/auth.guard.ts +++ b/src/app/core/guards/auth.guard.ts @@ -13,41 +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 | Promise { - throw true; + return true; } canActivate(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot | null): Observable { - 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 { - 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 { + // 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; + }) + ); } } diff --git a/src/app/core/startup/startup.service.ts b/src/app/core/startup/startup.service.ts index 95350c7b..4e68b7e9 100644 --- a/src/app/core/startup/startup.service.ts +++ b/src/app/core/startup/startup.service.ts @@ -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); // 设置页面标题的后缀 diff --git a/src/app/global-config.module.ts b/src/app/global-config.module.ts index 1e998b36..dabcdbb4 100644 --- a/src/app/global-config.module.ts +++ b/src/app/global-config.module.ts @@ -13,7 +13,8 @@ import { environment } from '@env/environment'; const alainConfig: AlainConfig = { st: { modal: { size: 'lg' } }, pageHeader: { homeI18n: 'home', recursiveBreadcrumb: true }, - auth: { login_url: '/dashboard' } + auth: { login_url: '/passport/login' }, + acl: { guard_url: '/' } }; const alainModules = [AlainThemeModule.forRoot(), DelonACLModule.forRoot()]; diff --git a/src/app/routes/vehicle/components/list/list.component.html b/src/app/routes/vehicle/components/list/list.component.html index eec3ddbb..4f7d82ea 100644 --- a/src/app/routes/vehicle/components/list/list.component.html +++ b/src/app/routes/vehicle/components/list/list.component.html @@ -7,23 +7,16 @@ * @FilePath: \tms-obc-web\src\app\routes\usercenter\components\freight\list\list.component.html --> - +
- - + +
@@ -33,9 +26,10 @@
- - - + + + + + +
- - - - -
- -
-
- - - - -
-
diff --git a/src/app/routes/vehicle/components/list/list.component.spec.ts b/src/app/routes/vehicle/components/list/list.component.spec.ts deleted file mode 100644 index e815b19d..00000000 --- a/src/app/routes/vehicle/components/list/list.component.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * @Author: your name - * @Date: 2021-12-01 20:05:59 - * @LastEditTime: 2021-12-01 20:35:33 - * @LastEditors: your name - * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE - * @FilePath: \tms-obc-web\src\app\routes\vehicle\components\list\list.component.spec.ts - */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { VehicleComponentsListComponent } from './list.component'; - -describe('VehicleComponentsListComponent', () => { - let component: VehicleComponentsListComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [VehicleComponentsListComponent], - }).compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(VehicleComponentsListComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/routes/vehicle/components/list/list.component.ts b/src/app/routes/vehicle/components/list/list.component.ts index e83259e5..aa913cbb 100644 --- a/src/app/routes/vehicle/components/list/list.component.ts +++ b/src/app/routes/vehicle/components/list/list.component.ts @@ -13,7 +13,6 @@ import { VehicleService } from '../../../vehicle/services/vehicle.service'; }) export class VehicleComponentsListComponent implements OnInit { _$expand = false; - url = `/rule?_allow_anonymous=true`; ui!: SFUISchema; schema!: SFSchema; @@ -22,12 +21,6 @@ export class VehicleComponentsListComponent implements OnInit { @ViewChild('sf', { static: false }) sf!: SFComponent; constructor(public service: VehicleService, private modal: NzModalService, private router: Router, private ar: ActivatedRoute) {} - /** - * 查询字段个数navigate - */ - get queryFieldCount(): number { - return Object.keys(this.schema?.properties || {}).length; - } /** * 查询参数 @@ -45,10 +38,6 @@ export class VehicleComponentsListComponent implements OnInit { return params; } - get selectedRows() { - return this.st?.list.filter((item) => item.checked) || []; - } - ngOnInit() { this.initSF(); this.initST(); @@ -91,9 +80,6 @@ export class VehicleComponentsListComponent implements OnInit { return of([]); } }, - visibleIf: { - _$expand: (value: boolean) => value - } } as SFSelectWidgetSchema }, carNoColor: { diff --git a/src/app/routes/vehicle/vehicle-routing.module.ts b/src/app/routes/vehicle/vehicle-routing.module.ts index 69e6ab7f..7dc78201 100644 --- a/src/app/routes/vehicle/vehicle-routing.module.ts +++ b/src/app/routes/vehicle/vehicle-routing.module.ts @@ -18,7 +18,9 @@ import { VehicleComponentsListComponent } from './components/list/list.component const routes: Routes = [ { path: '', + canLoad: [AuthGuard], canActivate: [AuthGuard], + canActivateChild: [AuthGuard], children: [ { path: 'list',