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!')