Commit f324f4af authored by 武广's avatar 武广

feat: 处理tob 接口请求token过期问题

parent a39c5a94
......@@ -228,6 +228,7 @@ const BasicLayout = props => {
return qianKunLayout();
}
if (isTob && searchPrams.token) {
console.log('window.parent :>> ', window.parent);
localStorage.set('tobToken', searchPrams.token || '');
return tobLayout();
}
......
......@@ -6,6 +6,7 @@
/* eslint-disable no-underscore-dangle */
import { extend } from 'umi-request';
import { notification } from 'antd';
import { getUrlSearchParams } from './utils';
import localStorage from './localStorage';
import config from '../../config/env.config';
......@@ -70,13 +71,21 @@ const refreshRequest = async (url, options) => {
}
return promise;
};
// 判断是否从tob进入
const searchPrams = getUrlSearchParams();
const isTob = searchPrams.source === 'tob';
/**
* 异常处理程序
*/
// request拦截器, 改变url 或 options.
request.interceptors.request.use(async (url, options) => {
const token = localStorage.get('tobToken') || localStorage.get('token');
let token = localStorage.get('token');
// tob进入使用tob token
if (isTob && localStorage.get('tobToken')) {
token = localStorage.get('tobToken');
}
if (!token && !url.includes('/v2/oauth/login')) {
window.location.href = `${window.origin}/user/login`;
}
......@@ -120,8 +129,12 @@ request.interceptors.response.use(async (response, options) => {
notification.warning({
message: data.msg,
});
if (isTob) {
localStorage.remove('tobToken');
} else {
window.location.href = loginPath;
}
}
if (data.businessCode && data.businessCode !== '0000' && !options.notTip) {
notification.warning({
message: data.detail || data.msg || '操作失败',
......
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