From f41ae0ef8c56b6f508add3865723360a527ebdaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=8E=89=E9=9C=9E?= Date: Mon, 22 Jul 2024 09:37:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/dasadmin/src/utils/axios.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ui/dasadmin/src/utils/axios.ts b/ui/dasadmin/src/utils/axios.ts index 78cf1cb9..4e8c7cfa 100644 --- a/ui/dasadmin/src/utils/axios.ts +++ b/ui/dasadmin/src/utils/axios.ts @@ -120,7 +120,7 @@ function createAxios>(axiosConfig: AxiosRequest options.loading && closeLoading(options) // 关闭loading if (response.config.responseType == 'json') { - if (response.data && response.data.code == 401) { + if (response.data && response.data.code != 200) { if (response.data.code == 409) { if (!window.tokenRefreshing) { window.tokenRefreshing = true @@ -162,12 +162,12 @@ function createAxios>(axiosConfig: AxiosRequest // router.push({ path: response.data.data.routePath ?? '', name: response.data.data.routeName ?? '' }) // } - // if (response.data.code == 401) { - let routerPath = adminBaseRoute.path - adminInfo.removeToken() - routerPath += '/login' - router.push({ path: routerPath }) - // } + if (response.data.code == 401) { + let routerPath = adminBaseRoute.path + adminInfo.removeToken() + routerPath += '/login' + router.push({ path: routerPath }) + } // code不等于1, 页面then内的具体逻辑就不执行了 return Promise.reject(response.data) } else if (options.showSuccessMessage && response.data && response.data.code == 200) { @@ -184,6 +184,12 @@ function createAxios>(axiosConfig: AxiosRequest error.config && removePending(error.config) options.loading && closeLoading(options) // 关闭loading options.showErrorMessage && httpErrorStatusHandle(error) // 处理错误状态码 + if (error.response.status == 401) { + let routerPath = adminBaseRoute.path + adminInfo.removeToken() + routerPath += '/login' + router.push({ path: routerPath }) + } return Promise.reject(error) // 错误继续返回给到具体页面 } ) @@ -209,7 +215,7 @@ function httpErrorStatusHandle(error: any) { message = i18n.global.t('axios.Incorrect parameter!') break case 401: - message = i18n.global.t('axios.You do not have permission to operate!') + message = '用户登录信息过期,请重新登录!' break case 403: message = i18n.global.t('axios.You do not have permission to operate!')