From 7b4b41053866760ed6e7b0537d5e8cb5b3530bc6 Mon Sep 17 00:00:00 2001 From: guoyue Date: Sat, 8 Oct 2022 14:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91=E8=A7=A3=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/utils/request.js | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) 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