Merge branch 'develop' of https://gitlab.eascs.com/tms-ui/tms-obc-web into develop
This commit is contained in:
		| @ -15,7 +15,7 @@ import { EnvironmentService } from '@env/environment.service'; | |||||||
| import { NzMessageService } from 'ng-zorro-antd/message'; | import { NzMessageService } from 'ng-zorro-antd/message'; | ||||||
|  |  | ||||||
| @Injectable({ | @Injectable({ | ||||||
|   providedIn: 'root', |   providedIn: 'root' | ||||||
| }) | }) | ||||||
| export class CoreService { | export class CoreService { | ||||||
|   // 获取当前登录用户信息 |   // 获取当前登录用户信息 | ||||||
| @ -24,6 +24,8 @@ export class CoreService { | |||||||
|   // 获取当前用户所拥有的菜单 |   // 获取当前用户所拥有的菜单 | ||||||
|   public $api_get_current_user_menus = `/scm/cuc/cuc/functionInfo/getUserHaveFunctionsList`; |   public $api_get_current_user_menus = `/scm/cuc/cuc/functionInfo/getUserHaveFunctionsList`; | ||||||
|  |  | ||||||
|  |   position = { lat: '', lng: '' }; | ||||||
|  |  | ||||||
|   constructor(private injector: Injector) {} |   constructor(private injector: Injector) {} | ||||||
|   // 注入路由 |   // 注入路由 | ||||||
|   public get router(): Router { |   public get router(): Router { | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ import { environment } from '@env/environment'; | |||||||
| import { EAEnvironmentService, EAUserService } from '@shared'; | import { EAEnvironmentService, EAUserService } from '@shared'; | ||||||
| import { Observable, of } from 'rxjs'; | import { Observable, of } from 'rxjs'; | ||||||
| import { catchError, mergeMap } from 'rxjs/operators'; | import { catchError, mergeMap } from 'rxjs/operators'; | ||||||
|  | import { CoreService } from '../core.service'; | ||||||
|  |  | ||||||
| @Injectable() | @Injectable() | ||||||
| export class BusinessInterceptor implements HttpInterceptor { | export class BusinessInterceptor implements HttpInterceptor { | ||||||
| @ -21,7 +22,8 @@ export class BusinessInterceptor implements HttpInterceptor { | |||||||
|     private eaUserSrv: EAUserService, |     private eaUserSrv: EAUserService, | ||||||
|     @Optional() |     @Optional() | ||||||
|     @Inject(DA_SERVICE_TOKEN) |     @Inject(DA_SERVICE_TOKEN) | ||||||
|     private tokenSrv: ITokenService |     private tokenSrv: ITokenService, | ||||||
|  |     private coreSrv: CoreService | ||||||
|   ) {} |   ) {} | ||||||
|   intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { |   intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | ||||||
|     // 构造新的请求URL |     // 构造新的请求URL | ||||||
| @ -52,11 +54,16 @@ export class BusinessInterceptor implements HttpInterceptor { | |||||||
|    * 附加额外的请求头 |    * 附加额外的请求头 | ||||||
|    */ |    */ | ||||||
|   private attachAdditionalHeaders(req: HttpRequest<any>): HttpRequest<any> { |   private attachAdditionalHeaders(req: HttpRequest<any>): HttpRequest<any> { | ||||||
|  |     let position = {}; | ||||||
|  |     if (this.coreSrv.position.lat && this.coreSrv.position.lng) { | ||||||
|  |       position = { lat: this.coreSrv.position.lat.toString(), lng: this.coreSrv.position.lng.toString() }; | ||||||
|  |     } | ||||||
|     // 附加环境变量 |     // 附加环境变量 | ||||||
|     const header: any = { |     const header: any = { | ||||||
|       appId: this.envSrv.env.appId, |       appId: this.envSrv.env.appId, | ||||||
|       tenantId: this.envSrv.env.tenantId, |       tenantId: this.envSrv.env.tenantId, | ||||||
|       enterpriseId: '0' |       enterpriseId: '0', | ||||||
|  |       ...position | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     // 附加授权声明 |     // 附加授权声明 | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ import { HttpClient } from '@angular/common/http'; | |||||||
| import { Inject, Injectable } from '@angular/core'; | import { Inject, Injectable } from '@angular/core'; | ||||||
| import { ACLService } from '@delon/acl'; | import { ACLService } from '@delon/acl'; | ||||||
| import { MenuService, SettingsService, TitleService, _HttpClient } from '@delon/theme'; | import { MenuService, SettingsService, TitleService, _HttpClient } from '@delon/theme'; | ||||||
| import { EAUserService } from '@shared'; | import { AmapService, EAUserService } from '@shared'; | ||||||
| import { NzSafeAny } from 'ng-zorro-antd/core/types'; | import { NzSafeAny } from 'ng-zorro-antd/core/types'; | ||||||
| import { NzIconService } from 'ng-zorro-antd/icon'; | import { NzIconService } from 'ng-zorro-antd/icon'; | ||||||
| import { Observable, zip } from 'rxjs'; | import { Observable, zip } from 'rxjs'; | ||||||
| @ -26,6 +26,7 @@ export class StartupService { | |||||||
|     private titleService: TitleService, |     private titleService: TitleService, | ||||||
|     private httpClient: _HttpClient, |     private httpClient: _HttpClient, | ||||||
|     private userSrv: EAUserService, |     private userSrv: EAUserService, | ||||||
|  |     private amapService: AmapService, | ||||||
|     private coreSrv: CoreService |     private coreSrv: CoreService | ||||||
|   ) { |   ) { | ||||||
|     iconSrv.addIcon(...ICONS_AUTO, ...ICONS); |     iconSrv.addIcon(...ICONS_AUTO, ...ICONS); | ||||||
| @ -35,6 +36,12 @@ export class StartupService { | |||||||
|  |  | ||||||
|   load(): Promise<void> { |   load(): Promise<void> { | ||||||
|     return new Promise(resolve => { |     return new Promise(resolve => { | ||||||
|  |       this.amapService.getCurrentPosition().subscribe(res => { | ||||||
|  |         if (res.position) { | ||||||
|  |           this.coreSrv.position = { lat: res.position.lat, lng: res.position.lng }; | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |  | ||||||
|       let data; |       let data; | ||||||
|       if (this.coreSrv.loginStatus) { |       if (this.coreSrv.loginStatus) { | ||||||
|         // 本地菜单 |         // 本地菜单 | ||||||
|  | |||||||
| @ -1,6 +1,10 @@ | |||||||
| import { Injectable } from '@angular/core'; | import { Injectable } from '@angular/core'; | ||||||
| import { Observable, Subject } from 'rxjs'; | import { Observable, Subject, throwError } from 'rxjs'; | ||||||
|  | import AMapLoader from '@amap/amap-jsapi-loader'; | ||||||
|  | import { amapConf } from '@conf/amap.config'; | ||||||
| declare var AMap: any; | declare var AMap: any; | ||||||
|  |  | ||||||
|  | const CONFIG = amapConf; | ||||||
| @Injectable({ | @Injectable({ | ||||||
|   providedIn: 'root' |   providedIn: 'root' | ||||||
| }) | }) | ||||||
| @ -10,6 +14,7 @@ export class AmapService { | |||||||
|   public time = 0; |   public time = 0; | ||||||
|  |  | ||||||
|   sub = new Subject<any>(); |   sub = new Subject<any>(); | ||||||
|  |   currentSub = new Subject<any>(); | ||||||
|  |  | ||||||
|   //计算路径驾车最优路线的长度与所需时间 |   //计算路径驾车最优路线的长度与所需时间 | ||||||
|   drivingCompute(starts: any[], ends: any[]): Observable<any> { |   drivingCompute(starts: any[], ends: any[]): Observable<any> { | ||||||
| @ -28,4 +33,42 @@ export class AmapService { | |||||||
|     }); |     }); | ||||||
|     return this.sub; |     return this.sub; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   getCurrentPosition(): Observable<any> { | ||||||
|  |     AMapLoader.load({ | ||||||
|  |       key: CONFIG.key, | ||||||
|  |       version: CONFIG.version, | ||||||
|  |       plugins: [ | ||||||
|  |         // 需要使用的的插件列表,如比例尺'AMap.Scale'等 | ||||||
|  |         'AMap.PathSimplifier' | ||||||
|  |       ], | ||||||
|  |       AMapUI: { | ||||||
|  |         version: CONFIG.AMapUIVersion, | ||||||
|  |         plugins: ['misc/PathSimplifier'] // 需要加载的 AMapUI ui插件 | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  |       .then(AMap => { | ||||||
|  |         AMap.plugin('AMap.Geolocation', () => { | ||||||
|  |           let driving = new AMap.Geolocation({ | ||||||
|  |             enableHighAccuracy: true, //是否使用高精度定位,默认:true | ||||||
|  |             timeout: 10000, //超过10秒后停止定位,默认:5s | ||||||
|  |             buttonPosition: 'RB', //定位按钮的停靠位置 | ||||||
|  |             buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20) | ||||||
|  |             zoomToAccuracy: true //定位成功后是否自动调整地图视野到定位点 | ||||||
|  |           }); | ||||||
|  |           driving.getCurrentPosition((status: string, result: any) => { | ||||||
|  |             if (status == 'complete') { | ||||||
|  |               this.currentSub.next(result); | ||||||
|  |             } else { | ||||||
|  |               console.log('定位获取失败'); | ||||||
|  |             } | ||||||
|  |           }); | ||||||
|  |         }); | ||||||
|  |       }) | ||||||
|  |       .catch(e => { | ||||||
|  |         throwError(e); | ||||||
|  |       }); | ||||||
|  |  | ||||||
|  |     return this.currentSub; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user