重新登录

This commit is contained in:
刘玉霞 2024-07-22 09:37:33 +08:00
parent 387d1d9410
commit f41ae0ef8c

View File

@ -120,7 +120,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(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<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
// router.push({ path: response.data.data.routePath ?? '', name: response.data.data.routeName ?? '' })
// }
// if (response.data.code == 401) {
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<Data = any, T = ApiPromise<Data>>(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!')