diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 73af1c10..32f1b6a4 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 @@ -53,6 +54,7 @@ import { RoutesModule } from './routes/routes.module'; import { SharedModule } from './shared/shared.module'; import { STWidgetModule } from './shared/widget/st-widget.module'; 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 dc51f81d..1161c714 100644 --- a/src/app/core/guards/auth.guard.ts +++ b/src/app/core/guards/auth.guard.ts @@ -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 | Promise { - console.log(route); - - 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/global-config.module.ts b/src/app/global-config.module.ts index 48e8a9ea..6db7bd50 100644 --- a/src/app/global-config.module.ts +++ b/src/app/global-config.module.ts @@ -19,7 +19,8 @@ const alainConfig: AlainConfig = { }, sf: { button: { search: '查询' } }, 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/img-view/img-view.component.spec.ts b/src/app/routes/vehicle/components/list/img-view/img-view.component.spec.ts deleted file mode 100644 index 014df68a..00000000 --- a/src/app/routes/vehicle/components/list/img-view/img-view.component.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * @Author: your name - * @Date: 2021-12-07 17:30:18 - * @LastEditTime: 2021-12-09 17:47: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\img-view\img-view.component.spec.ts - */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { VehicleImgViewComponent } from './img-view.component'; - -describe('VehicleImgViewComponent', () => { - let component: VehicleImgViewComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [VehicleImgViewComponent], - }).compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(VehicleImgViewComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/routes/vehicle/components/list/list.component.html b/src/app/routes/vehicle/components/list/list.component.html index eec3ddbb..9e3cdc17 100644 --- a/src/app/routes/vehicle/components/list/list.component.html +++ b/src/app/routes/vehicle/components/list/list.component.html @@ -7,69 +7,47 @@ * @FilePath: \tms-obc-web\src\app\routes\usercenter\components\freight\list\list.component.html --> - +
- -
- - +
+ +
+
+ + + +
- - - - -
- -
-
- - - - -
-
- + [loading]="service.http.loading"> -
{{item?.carModelLabel }}-{{item?.carLengthLabel? item?.carLengthLabel + '米' : ''}}-{{ item?.carLoad? item?.carLoad + '吨' : ''}}
+
{{item?.carModelLabel }}-{{item?.carLengthLabel? item?.carLengthLabel + '米' : ''}}-{{ item?.carLoad? + item?.carLoad + '吨' : ''}}
-
- {{ item?.isSelf ? '是' : '否' }} +
+ {{ item?.isSelf ? '是' : '否' }}
-
- {{ item?.putOnRecord ? '是' : '否' }} +
+ {{ item?.putOnRecord ? '是' : '否' }}
@@ -89,4 +67,4 @@ 正常 - + \ No newline at end of file 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 61641d78..65c5d7a1 100644 --- a/src/app/routes/vehicle/components/list/list.component.ts +++ b/src/app/routes/vehicle/components/list/list.component.ts @@ -9,11 +9,10 @@ import { map } from 'rxjs/operators'; import { VehicleService } from '../../../vehicle/services/vehicle.service'; @Component({ selector: 'app-Vehicle-components-list', - templateUrl: './list.component.html', + templateUrl: './list.component.html' }) export class VehicleComponentsListComponent implements OnInit { _$expand = false; - url = `/rule?_allow_anonymous=true`; ui!: SFUISchema; schema!: SFSchema; @@ -22,19 +21,13 @@ 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; - } /** * 查询参数 */ get reqParams() { const params: any = { - ...(this.sf && this.sf.value), + ...(this.sf && this.sf.value) }; if (this.sf?.value.effectiveDate) { params.effectiveDateStart = this.sf?.value.effectiveDate[0]; @@ -45,14 +38,10 @@ export class VehicleComponentsListComponent implements OnInit { return params; } - get selectedRows() { - return this.st?.list.filter((item) => item.checked) || []; - } - ngOnInit() { this.initSF(); this.initST(); - this.ar.url.subscribe((params) => { + this.ar.url.subscribe(params => { this.st?.load(1); }); } @@ -68,8 +57,8 @@ export class VehicleComponentsListComponent implements OnInit { expand: { type: 'boolean', ui: { - hidden: true, - }, + hidden: true + } }, carNo: { title: '车牌号', @@ -91,9 +80,6 @@ export class VehicleComponentsListComponent implements OnInit { } else { return of([]); } - }, - visibleIf: { - _$expand: (value: boolean) => value } } as SFSelectWidgetSchema }, @@ -103,20 +89,20 @@ export class VehicleComponentsListComponent implements OnInit { ui: { widget: 'dict-select', containsAllLable: true, - params: { dictKey: 'car:color' }, - }, + params: { dictKey: 'car:color' } + } }, carStatus: { title: '运营状态', type: 'string', enum: [ { label: '空闲', value: 0 }, - { label: '运输中', value: 1 }, + { label: '运输中', value: 1 } ], ui: { allowClear: true, - widget: 'select', - }, + widget: 'select' + } }, carModel: { title: '车型', @@ -126,36 +112,36 @@ export class VehicleComponentsListComponent implements OnInit { params: { dictKey: 'car:model' }, containsAllLable: true, visibleIf: { - expand: (value: boolean) => value, - }, - }, + expand: (value: boolean) => value + } + } }, carLength: { title: '车长', type: 'string', - ui: { + ui: { widget: 'dict-select', params: { dictKey: 'car:length' }, containsAllLable: true, visibleIf: { - expand: (value: boolean) => value, - }, - }, + expand: (value: boolean) => value + } + } }, isSelf: { type: 'string', title: '是否挂靠', enum: [ { label: '是', value: 1 }, - { label: '否', value: 0 }, + { label: '否', value: 0 } ], ui: { widget: 'select', allowClear: true, visibleIf: { - expand: (value: boolean) => value, - }, - }, + expand: (value: boolean) => value + } + } }, driverLicenseStatus: { type: 'string', @@ -163,16 +149,16 @@ export class VehicleComponentsListComponent implements OnInit { enum: [ { label: '正常', value: 1 }, { label: '即将到期', value: 2 }, - { label: '已到期', value: 3}, + { label: '已到期', value: 3 } ], default: '', ui: { widget: 'select', allowClear: true, visibleIf: { - expand: (value: boolean) => value, - }, - }, + expand: (value: boolean) => value + } + } }, roadTransportStatus: { type: 'string', @@ -180,16 +166,16 @@ export class VehicleComponentsListComponent implements OnInit { enum: [ { label: '正常', value: 1 }, { label: '即将到期', value: 2 }, - { label: '已到期', value: 3}, + { label: '已到期', value: 3 } ], ui: { widget: 'select', allowClear: true, visibleIf: { - expand: (value: boolean) => value, - }, - }, - }, + expand: (value: boolean) => value + } + } + } // putOnRecord: { // type: 'string', // title: '是否已备案', @@ -204,7 +190,7 @@ export class VehicleComponentsListComponent implements OnInit { // }, // }, // }, - }, + } }; this.ui = { '*': { spanLabelFixed: 130, grid: { span: 8, gutter: 4 }, enter: () => this.st.load() } }; } @@ -212,43 +198,47 @@ export class VehicleComponentsListComponent implements OnInit { initST() { this.columns = [ // { title: '', type: 'checkbox', className: 'text-center' }, - { title: '车牌号', width:'150px', className: 'text-center', index: 'carNo' }, - { title: '车牌颜色', width:'150px', className: 'text-center', index: 'carNoColorLabel' }, - { title: '车型-车长-载重',width:'150px', className: 'text-center', render: 'carLength' }, - { title: '运营状态',width:'150px', className: 'text-center', index: 'carStatus', - type: 'badge', - badge: { - true: { text: '运输中', color: 'success' }, - false: { text: '空闲', color: 'default' }, + { title: '车牌号', width: '150px', className: 'text-center', index: 'carNo' }, + { title: '车牌颜色', width: '150px', className: 'text-center', index: 'carNoColorLabel' }, + { title: '车型-车长-载重', width: '150px', className: 'text-center', render: 'carLength' }, + { + title: '运营状态', + width: '150px', + className: 'text-center', + index: 'carStatus', + type: 'badge', + badge: { + true: { text: '运输中', color: 'success' }, + false: { text: '空闲', color: 'default' } + } }, - }, { title: '行驶证到期状态', - width:'180px', + width: '180px', className: 'text-center', index: 'driverLicenseStatus', type: 'badge', badge: { 1: { text: '正常', color: 'success' }, 2: { text: '即将到期', color: 'warning' }, - 3: { text: '已到期', color: 'error' }, - }, + 3: { text: '已到期', color: 'error' } + } }, { title: '道运证到期状态', - width:'180px', + width: '180px', className: 'text-center', index: 'roadTransportStatus', type: 'badge', badge: { 1: { text: '正常', color: 'success' }, 2: { text: '即将到期', color: 'warning' }, - 3: { text: '已到期', color: 'error' }, - }, + 3: { text: '已到期', color: 'error' } + } }, - { title: '所有人',width:'150px', className: 'text-center', index: 'carOwner' }, - { title: '是否挂靠', width:'150px', className: 'text-center', render: 'isSelf', }, - { title: '挂靠协议', width:'150px', className: 'text-center', render: 'approvalAuditStatus' }, + { title: '所有人', width: '150px', className: 'text-center', index: 'carOwner' }, + { title: '是否挂靠', width: '150px', className: 'text-center', render: 'isSelf' }, + { title: '挂靠协议', width: '150px', className: 'text-center', render: 'approvalAuditStatus' }, // { title: '是否已备案', className: 'text-center', render: 'putOnRecord', }, { @@ -259,20 +249,20 @@ export class VehicleComponentsListComponent implements OnInit { buttons: [ { text: '查看', - click: (item) => { - this.router.navigate(['./detail', item.id], { relativeTo: this.ar,queryParams: { carId: item.carId } }); + 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 } }); - }, - }, + } + } // { // text: '申请备案', // click: (item) => { - - + // }, // }, - ], - }, + ] + } ]; } expandToggle() { @@ -280,7 +270,7 @@ export class VehicleComponentsListComponent implements OnInit { this.sf?.setValue('/expand', this._$expand); } creat() { - this.router.navigate(['./new',], { relativeTo: this.ar }); + this.router.navigate(['./new'], { relativeTo: this.ar }); } /** * 重置表单 @@ -291,6 +281,6 @@ export class VehicleComponentsListComponent implements OnInit { } // 导出 exportFire() { - this.service.downloadFile(this.service.$api_carLicense_export, this.reqParams ); + this.service.downloadFile(this.service.$api_carLicense_export, this.reqParams); } } diff --git a/src/app/routes/vehicle/vehicle-routing.module.ts b/src/app/routes/vehicle/vehicle-routing.module.ts index fa066cf2..7dc78201 100644 --- a/src/app/routes/vehicle/vehicle-routing.module.ts +++ b/src/app/routes/vehicle/vehicle-routing.module.ts @@ -8,23 +8,42 @@ */ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; +import { ACLGuard, ACLGuardType } from '@delon/acl'; +import { AuthGuard } from 'src/app/core/guards/auth.guard'; import { VehicleComponentsAuditComponent } from './components/audit/audit.component'; import { VehicleComponentsAuditDetailComponent } from './components/audit/detail/detail.component'; import { VehicleComponentsListDetailComponent } from './components/list/detail/detail.component'; import { VehicleComponentsListComponent } from './components/list/list.component'; - - const routes: Routes = [ - - { path: 'list', component: VehicleComponentsListComponent }, - { path: 'list/detail/:id', component: VehicleComponentsListDetailComponent }, - { path: 'audit', component: VehicleComponentsAuditComponent }, - { path: 'audit/detail/:id', component: VehicleComponentsAuditDetailComponent }, + { + path: '', + canLoad: [AuthGuard], + canActivate: [AuthGuard], + canActivateChild: [AuthGuard], + children: [ + { + path: 'list', + component: VehicleComponentsListComponent, + data: { guard: { ability: ['YUNLI-CART-SEARCH'] } as ACLGuardType } + }, + { + path: 'list/detail/:id', + component: VehicleComponentsListDetailComponent, + data: { guard: { ability: ['YUNLI-CART-DETAIL'] } as ACLGuardType } + }, + { + path: 'audit', + component: VehicleComponentsAuditComponent, + data: { guard: { ability: ['YUNLI-CART--AUDIT-SEARCH1'] } as ACLGuardType } + }, + { path: 'audit/detail/:id', component: VehicleComponentsAuditDetailComponent } + ] + } ]; @NgModule({ imports: [RouterModule.forChild(routes)], - exports: [RouterModule], + exports: [RouterModule] }) export class VehicleRoutingModule {} diff --git a/src/assets/mocks/menu-data.json b/src/assets/mocks/menu-data.json index 24ec1160..af8f9dab 100644 --- a/src/assets/mocks/menu-data.json +++ b/src/assets/mocks/menu-data.json @@ -103,7 +103,12 @@ }, { "text": "车辆审核列表", - "link": "/vehicle/audit" + "link": "/vehicle/audit", + "acl": { + "ability": [ + "YUNLI-CART-AUDIT-SEARCH" + ] + } }, { "hide": true,