This commit is contained in:
LoadChange 2020-03-15 20:51:01 +08:00 committed by Asa
parent 9c01fd3814
commit c22a593396
2 changed files with 20 additions and 3 deletions

View File

@ -15,6 +15,14 @@ import projectConfig from './config';
import $ from 'jquery';
import { Message } from '@alifd/next';
function goLogin() {
const url = window.location.href;
localStorage.removeItem('token');
const base_url = url.split('#')[0];
console.log('base_url', base_url);
window.location = `${base_url}#/login`;
}
const global = window;
/**
@ -484,9 +492,10 @@ const request = (function(_global) {
config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]);
let token = {};
try {
token = JSON.parse(localStorage.token || '{}');
token = JSON.parse(localStorage.token);
} catch (e) {
console.log(e);
console.log('Token Erro', localStorage.token, e);
goLogin();
}
const { accessToken = '' } = token;
const [url, paramsStr = ''] = config.url.split('?');

View File

@ -7,6 +7,13 @@ import { isPlainObject } from './nacosutil';
const API_GENERAL_ERROR_MESSAGE = 'Request error, please try again later!';
function goLogin() {
const url = window.location.href;
localStorage.removeItem('token');
const base_url = url.split('#')[0];
window.location.href = `${base_url}#/login`;
}
const request = () => {
const instance = axios.create();
@ -19,9 +26,10 @@ const request = () => {
if (!url.includes('auth/users/login')) {
let token = {};
try {
token = JSON.parse(localStorage.token || '{}');
token = JSON.parse(localStorage.token);
} catch (e) {
console.log(e);
goLogin();
}
const { accessToken = '' } = token;
config.params.accessToken = accessToken;