This commit is contained in:
Taric Xin
2021-12-24 15:26:03 +08:00
parent 1026847317
commit 8905745828
4 changed files with 68 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import { environment } from '@env/environment';
import { EAEnvironmentService, EAUserService } from '@shared';
import { Observable, of } from 'rxjs';
import { catchError, mergeMap } from 'rxjs/operators';
import { CoreService } from '../core.service';
@Injectable()
export class BusinessInterceptor implements HttpInterceptor {
@ -21,7 +22,8 @@ export class BusinessInterceptor implements HttpInterceptor {
private eaUserSrv: EAUserService,
@Optional()
@Inject(DA_SERVICE_TOKEN)
private tokenSrv: ITokenService
private tokenSrv: ITokenService,
private coreSrv: CoreService
) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// 构造新的请求URL
@ -52,12 +54,19 @@ export class BusinessInterceptor implements HttpInterceptor {
* 附加额外的请求头
*/
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 = {
appId: this.envSrv.env.appId,
tenantId: this.envSrv.env.tenantId,
enterpriseId: '0'
enterpriseId: '0',
...position
};
console.log(header);
// 附加授权声明
const token = this.tokenSrv.get()?.token;