From f2779a13d62594a8e1e9b6c3d6f826077aafc8ad Mon Sep 17 00:00:00 2001 From: Taric Xin Date: Tue, 25 Jan 2022 15:59:01 +0800 Subject: [PATCH] edit --- src/app/core/guards/auth.guard.ts | 44 +++++--- src/app/core/startup/startup.service.ts | 2 +- src/app/routes/routes-routing.module.ts | 7 +- .../components/audit/audit.component.ts | 3 +- .../audit/detail/detail.component.html | 6 +- .../list/detail/detail.component.html | 2 +- .../components/list/list.component.html | 2 +- .../vehicle/components/list/list.component.ts | 5 +- .../routes/vehicle/vehicle-routing.module.ts | 27 +---- .../dynamic-setting-h5.component.html | 9 +- .../dynamic-setting-h5.component.ts | 2 + .../freight-table.component.html | 85 +++++++++++---- .../freight-table.component.less | 14 +++ .../freight-table/freight-table.component.ts | 100 +++++++++++++++++- src/assets/mocks/menu-data.json | 7 +- 15 files changed, 235 insertions(+), 80 deletions(-) diff --git a/src/app/core/guards/auth.guard.ts b/src/app/core/guards/auth.guard.ts index 47b7dcca..920095b6 100644 --- a/src/app/core/guards/auth.guard.ts +++ b/src/app/core/guards/auth.guard.ts @@ -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 { 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; } } 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/routes/routes-routing.module.ts b/src/app/routes/routes-routing.module.ts index d538081c..cb111d43 100644 --- a/src/app/routes/routes-routing.module.ts +++ b/src/app/routes/routes-routing.module.ts @@ -1,5 +1,5 @@ /* - * @Description : + * @Description : * @Version : 1.0 * @Author : Shiming * @Date : 2022-01-13 19:22:47 @@ -15,6 +15,7 @@ import { RouterModule, Routes } from '@angular/router'; import { LayoutProComponent } from '@brand'; import { EATokenGuard } from '@core'; import { environment } from '@env/environment'; +import { AuthGuard } from '../core/guards/auth.guard'; // dashboard pages import { DashboardComponent } from './dashboard/dashboard.component'; @@ -23,8 +24,8 @@ const routes: Routes = [ { path: '', component: LayoutProComponent, - canActivate: [EATokenGuard], - canActivateChild: [EATokenGuard], + canActivate: [AuthGuard, EATokenGuard], + canActivateChild: [AuthGuard, EATokenGuard], children: [ { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, { path: 'dashboard', component: DashboardComponent }, diff --git a/src/app/routes/vehicle/components/audit/audit.component.ts b/src/app/routes/vehicle/components/audit/audit.component.ts index 9e0a397a..a11c32f4 100644 --- a/src/app/routes/vehicle/components/audit/audit.component.ts +++ b/src/app/routes/vehicle/components/audit/audit.component.ts @@ -182,10 +182,11 @@ export class VehicleComponentsAuditComponent implements OnInit { title: '操作', fixed: 'right', width: '100px', - className: 'text-left', + className: 'text-center', buttons: [ { text: '查看', + acl: { ability: ['VEHICLE-AUDIT-view'] }, 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 } }); diff --git a/src/app/routes/vehicle/components/audit/detail/detail.component.html b/src/app/routes/vehicle/components/audit/detail/detail.component.html index 53fcbf10..78cec574 100644 --- a/src/app/routes/vehicle/components/audit/detail/detail.component.html +++ b/src/app/routes/vehicle/components/audit/detail/detail.component.html @@ -17,9 +17,9 @@ 证件过期
- - - + + + diff --git a/src/app/routes/vehicle/components/list/detail/detail.component.html b/src/app/routes/vehicle/components/list/detail/detail.component.html index e1bcaa06..50ea5f98 100644 --- a/src/app/routes/vehicle/components/list/detail/detail.component.html +++ b/src/app/routes/vehicle/components/list/detail/detail.component.html @@ -11,7 +11,7 @@
- + diff --git a/src/app/routes/vehicle/components/list/list.component.html b/src/app/routes/vehicle/components/list/list.component.html index 9e3cdc17..651c90cf 100644 --- a/src/app/routes/vehicle/components/list/list.component.html +++ b/src/app/routes/vehicle/components/list/list.component.html @@ -18,7 +18,7 @@
+ [acl-ability]="'VEHICLE-LIST-view'">导出 +
diff --git a/src/app/shared/components/dynamic-setting/dynamic-setting-h5/dynamic-setting-h5.component.ts b/src/app/shared/components/dynamic-setting/dynamic-setting-h5/dynamic-setting-h5.component.ts index fde89615..7bd096d5 100644 --- a/src/app/shared/components/dynamic-setting/dynamic-setting-h5/dynamic-setting-h5.component.ts +++ b/src/app/shared/components/dynamic-setting/dynamic-setting-h5/dynamic-setting-h5.component.ts @@ -33,6 +33,8 @@ export class DynamicSettingH5Component implements OnInit { changeType(type: any): void { this.selectedTab = type; + console.log(type); + this.selectedEvent.emit(this.selectedTab); } diff --git a/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.html b/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.html index e14c7991..224b4551 100644 --- a/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.html +++ b/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.html @@ -1,22 +1,63 @@ - - - - 公里数 - 计算方式 - 车长(米) - 操作 - - - - - - - {{ item.startKm }} - {{ item.endKm }} - {{ item.computeMode }} - 最高{{ node.maxPrice }} 预警{{ - node.ewPrice }} - 删除 - - - \ No newline at end of file +
+
+
+ + +
+ + + + + 公里数 + 计算方式 + 车长(米) + 操作 + + + +
+ + + + +
+ + + + + + +
+ + + + +
+ + {{computeMode[item.computeMode] }} + +
+ + + + + + +
+ + + 删除 + + + +
+ + +
+
\ No newline at end of file diff --git a/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.less b/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.less index e69de29b..d2c457ab 100644 --- a/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.less +++ b/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.less @@ -0,0 +1,14 @@ +:host::ng-deep { + nz-input-number { + width: 85px; + + input { + width : 100%; + margin: 0; + } + + .ant-input-number-handler-wrap { + display: none; + } + } +} \ No newline at end of file diff --git a/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.ts b/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.ts index 2ed7b501..3a5acc5f 100644 --- a/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.ts +++ b/src/app/shared/components/dynamic-setting/freight-table/freight-table.component.ts @@ -9,6 +9,12 @@ import { BaseService } from '@shared'; export class FreightTableComponent implements OnInit { data: any[] = []; headers: any[] = []; + + formatterDollar = (value: number): string => `${value} (含)`; + computeMode: any = { + 0: '总运价', + 1: '单公里运价' + }; constructor(public service: BaseService) {} ngOnInit(): void { @@ -32,7 +38,99 @@ export class FreightTableComponent implements OnInit { }); } + /** + * 修改结束车长 + * @param event 车长 + * @param i 下标 + */ changeEndLength(event: any, i: number) { - console.log(event, i); + if (event <= this.headers[i].startLength) { + this.headers[i].endLength = this.headers[i].startLength + 1; + this.changeNextStartLength(event, i + 1); + return; + } + this.headers[i].endLength = event; + this.changeNextStartLength(event, i + 1); + } + + /** + * 修改结束公里数 + * @param event 车长 + * @param i 下标 + */ + changeEndKm(event: any, i: number) { + if (event <= this.data[i].startKm) { + this.data[i].endKm = this.data[i].startKm + 1; + this.changeNextStartKm(event, i + 1); + return; + } + this.data[i].endKm = event; + this.changeNextStartKm(event, i + 1); + } + + add() { + console.log(this.data); + + const tem = this.data[this.data?.length - 1]; + if (tem && tem.endKm) { + const list = this.headers.map(item => ({ + ewPrice: null, + itemId: item.id, + maxPrice: null + })); + this.data.push({ + computeMode: 1, + configValue: list, + endKm: '', + startKm: tem.endKm + }); + this.data = [...this.data]; + } else { + this.service.msgSrv.warning('请填写完整公里数'); + } + } + + deleteRow(index: number) { + this.data = this.data.filter((d, i) => index !== i); + } + + save() { + this.service.request('/api/mdc/cuc/freightConfig/saveBatch', this.data).subscribe(res => { + if (res) { + console.log(res); + this.service.msgSrv.success('修改成功'); + this.loadData(); + } + }); + } + + /** + * 遍历同步后置位车长 + * @param event 车长 + * @param i 下标 + */ + private changeNextStartLength(event: number, i: number) { + if (this.headers[i]) { + this.headers[i].startLength = event; + if (this.headers[i].endLength <= event) { + this.headers[i].endLength = this.headers[i].startLength + 0.5; + this.changeNextStartLength(event + 0.5, i + 1); + } + } + } + + /** + * 遍历同步后置位公里数 + * @param event 车长 + * @param i 下标 + */ + private changeNextStartKm(event: number, i: number) { + if (this.data[i]) { + this.data[i].startKm = event; + if (this.data[i].endKm <= event) { + this.data[i].endKm = this.data[i].startKm + 1; + this.changeNextStartKm(event + 1, i + 1); + } + } } } diff --git a/src/assets/mocks/menu-data.json b/src/assets/mocks/menu-data.json index af8f9dab..24ec1160 100644 --- a/src/assets/mocks/menu-data.json +++ b/src/assets/mocks/menu-data.json @@ -103,12 +103,7 @@ }, { "text": "车辆审核列表", - "link": "/vehicle/audit", - "acl": { - "ability": [ - "YUNLI-CART-AUDIT-SEARCH" - ] - } + "link": "/vehicle/audit" }, { "hide": true,