提交 2f519bf9 编写于 作者: zcdtk's avatar zcdtk

拦截器处理

上级 efb12ebe
import { Store } from 'vuex'; import { Store } from 'vuex';
import axios from 'axios'; import axios from 'axios';
import Router from 'vue-router'; import Router from 'vue-router';
import i18n from '@/locale';
import ignoreProxyMap from './ignore-proxy'; import ignoreProxyMap from './ignore-proxy';
...@@ -77,17 +78,15 @@ export class Interceptors { ...@@ -77,17 +78,15 @@ export class Interceptors {
*/ */
private intercept(): void { private intercept(): void {
axios.interceptors.request.use((config: any) => { axios.interceptors.request.use((config: any) => {
let appdata: string | null = null; let appdata: any = this.store.getters.getAppData();;
if (this.router) { if (appdata && appdata.context) {
appdata = this.store.getters.getAppData(); config.headers['srforgsectorid'] = appdata.context.srforgsectorid;
}
if (!Object.is(appdata, '')) {
config.headers.srfappdata = appdata;
} }
if (window.localStorage.getItem('token')) { if (window.localStorage.getItem('token')) {
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
config.headers.Authorization = `Bearer ${token}`; config.headers.Authorization = `Bearer ${token}`;
} }
config.headers['Accept-Language'] = i18n.locale;
// 混合 app 代理处理 // 混合 app 代理处理
if (Object.is(process.env.VUE_APP_CURRENTMODE, 'hybridapp') && !config.url.startsWith('https://') && !config.url.startsWith('http://')) { if (Object.is(process.env.VUE_APP_CURRENTMODE, 'hybridapp') && !config.url.startsWith('https://') && !config.url.startsWith('http://')) {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册