401状态拦截

This commit is contained in:
xuxin
2026-06-04 17:47:28 +08:00
parent 540d61b6a0
commit 403e5e9fc9
+3 -2
View File
@@ -1,6 +1,7 @@
import axios from 'axios'
import type { AxiosResponse } from 'axios'
import store from '@/stores'
import router from '@/router'
/**
* 自定义 JSON 解析:将超出安全整数范围的数字转为字符串,防止精度丢失
@@ -39,9 +40,9 @@ service.interceptors.response.use(
(error) => {
const status = error.response?.status
if (status === 401) {
// 同步重置前端登录状态,弹出登录
// 同步重置前端登录状态,跳转登录
store.commit('SET_AUTHENTICATED', false)
store.dispatch('openLogin', window.location.pathname)
router.push({ name: 'Login', query: { redirect: window.location.pathname } })
ElMessage.error('登录已过期,请重新登录')
} else {
ElMessage.error(error.response?.data?.msg || '请求失败')