fix: closes #2443
This commit is contained in:
parent
9c01fd3814
commit
c22a593396
@ -15,6 +15,14 @@ import projectConfig from './config';
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import { Message } from '@alifd/next';
|
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;
|
const global = window;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -484,9 +492,10 @@ const request = (function(_global) {
|
|||||||
config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]);
|
config = handleMiddleWare.apply(this, [config, ...args, middlewareBackList]);
|
||||||
let token = {};
|
let token = {};
|
||||||
try {
|
try {
|
||||||
token = JSON.parse(localStorage.token || '{}');
|
token = JSON.parse(localStorage.token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log('Token Erro', localStorage.token, e);
|
||||||
|
goLogin();
|
||||||
}
|
}
|
||||||
const { accessToken = '' } = token;
|
const { accessToken = '' } = token;
|
||||||
const [url, paramsStr = ''] = config.url.split('?');
|
const [url, paramsStr = ''] = config.url.split('?');
|
||||||
|
@ -7,6 +7,13 @@ import { isPlainObject } from './nacosutil';
|
|||||||
|
|
||||||
const API_GENERAL_ERROR_MESSAGE = 'Request error, please try again later!';
|
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 request = () => {
|
||||||
const instance = axios.create();
|
const instance = axios.create();
|
||||||
|
|
||||||
@ -19,9 +26,10 @@ const request = () => {
|
|||||||
if (!url.includes('auth/users/login')) {
|
if (!url.includes('auth/users/login')) {
|
||||||
let token = {};
|
let token = {};
|
||||||
try {
|
try {
|
||||||
token = JSON.parse(localStorage.token || '{}');
|
token = JSON.parse(localStorage.token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
goLogin();
|
||||||
}
|
}
|
||||||
const { accessToken = '' } = token;
|
const { accessToken = '' } = token;
|
||||||
config.params.accessToken = accessToken;
|
config.params.accessToken = accessToken;
|
||||||
|
Loading…
Reference in New Issue
Block a user