diff --git a/front/src/utils/request.js b/front/src/utils/request.js index 9b597979..4721f5c7 100644 --- a/front/src/utils/request.js +++ b/front/src/utils/request.js @@ -82,9 +82,9 @@ instance.interceptors.request.use( if (debounce.some((item) => config.url.includes(item))) { //这里写加载动画 } - // if (!config.headers.REQUESTURI) { - // config.headers.REQUESTURI = window.location.href - // } + if (!config.headers.REQUESTURI) { + config.headers.REQUESTURI = window.location.href + } return config }, @@ -108,19 +108,19 @@ instance.interceptors.response.use( message } = response.data - // if (response.headers.token) { - // setAccessToken(response.headers.token) - // } - // if (response.headers.redirect) { - // const _old_href = window.location.href.split('#')[0]; - // const _new_href = response.headers.redirect.split('#')[0]; - // window.location.replace(response.headers.redirect) - // // url 相同,强制刷新 - // if (_old_href === _new_href) { - // location.reload() - // } - // return response - // } + if (response.headers.token) { + setAccessToken(response.headers.token) + } + if (response.headers.redirect) { + const _old_href = window.location.href.split('#')[0]; + const _new_href = response.headers.redirect.split('#')[0]; + window.location.replace(response.headers.redirect) + // url 相同,强制刷新 + if (_old_href === _new_href) { + location.reload() + } + return response + } if (response.headers.redirect === '/#/login') { var keys = document.cookie.match(/[^ =;]+(?=\=)/g) if (keys) { @@ -179,10 +179,10 @@ instance.interceptors.response.use( if (response.headers.token) { setAccessToken(response.headers.token) } - // if (response.headers.redirect) { - // window.location.replace(response.headers.redirect) - // return Promise.resolve() - // } + if (response.headers.redirect) { + window.location.replace(response.headers.redirect) + return Promise.resolve() + } const { status, data