Commit b18e7ddd by 杨子

添加拦截器代码

parent aba9e965
import { Injectable, Injector } from '@angular/core'; import { Injectable, Injector, Inject } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { import {
HttpInterceptor, HttpInterceptor,
...@@ -39,7 +39,7 @@ const CODEMESSAGE = { ...@@ -39,7 +39,7 @@ const CODEMESSAGE = {
*/ */
@Injectable() @Injectable()
export class DefaultInterceptor implements HttpInterceptor { export class DefaultInterceptor implements HttpInterceptor {
constructor(private injector: Injector) {} constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private injector: Injector) {}
private get notification(): NzNotificationService { private get notification(): NzNotificationService {
return this.injector.get(NzNotificationService); return this.injector.get(NzNotificationService);
...@@ -112,7 +112,25 @@ export class DefaultInterceptor implements HttpInterceptor { ...@@ -112,7 +112,25 @@ export class DefaultInterceptor implements HttpInterceptor {
// 统一加上服务端前缀 // 统一加上服务端前缀
let url = req.url; let url = req.url;
if (!url.startsWith('https://') && !url.startsWith('http://')) { if (!url.startsWith('https://') && !url.startsWith('http://')) {
console.log(url.indexOf('asset'));
console.log(url.indexOf('/login'));
// asset/a/assets/.....
//asset/a/login
//qita
// const rg = /asset\/a\/[^(login)].*/g;
// if (rg.match(url)) url = environment.SERVER_URL + url;
// const reg = [/\/login/, /assets\//, /passport\//];
url = environment.SERVER_URL + url; url = environment.SERVER_URL + url;
console.log(url);
if (url.indexOf('asset') === 0) {
if (url.indexOf('/login') === -1) {
console.log(1111);
url += `JSESSIONID=${this.tokenService.get().token}?_ajax=true&mobileLogin=true`;
} else {
console.log(2222);
}
}
} }
const newReq = req.clone({ url }); const newReq = req.clone({ url });
......
...@@ -7,7 +7,7 @@ import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; ...@@ -7,7 +7,7 @@ import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
}) })
export class ListService { export class ListService {
constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private http: _HttpClient) {} constructor(@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService, private http: _HttpClient) {}
private url = `asset/a/asset/assets/data;JSESSIONID=${this.tokenService.get().token}?_ajax=true&mobileLogin=true`; private url = `asset/a/asset/assets/data;`;
/** /**
*获取资产台账列表 *获取资产台账列表
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment