(no commit message provided)
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
@ -11,7 +11,6 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
// 2. Actions
|
// 2. Actions
|
||||||
// 登录逻辑
|
// 登录逻辑
|
||||||
const handleLogin = async (loginForm: any) => {
|
const handleLogin = async (loginForm: any) => {
|
||||||
try {
|
|
||||||
const res = await login(loginForm)
|
const res = await login(loginForm)
|
||||||
|
|
||||||
// [调试日志] 查看实际返回的数据结构
|
// [调试日志] 查看实际返回的数据结构
|
||||||
@ -26,7 +25,7 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
// 安全检查:确保 data 存在且包含 access_token
|
// 安全检查:确保 data 存在且包含 access_token
|
||||||
if (!data || !data.access_token) {
|
if (!data || !data.access_token) {
|
||||||
console.error('Login Error: 响应数据中缺少 access_token', data)
|
console.error('Login Error: 响应数据中缺少 access_token', data)
|
||||||
return false
|
throw new Error('登录失败: 响应数据异常')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新 Pinia 状态 (内存)
|
// 更新 Pinia 状态 (内存)
|
||||||
@ -46,11 +45,6 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
localStorage.setItem('token', data.access_token)
|
localStorage.setItem('token', data.access_token)
|
||||||
|
|
||||||
return true // 返回 true 表示登录成功
|
return true // 返回 true 表示登录成功
|
||||||
} catch (error) {
|
|
||||||
console.error('Login failed:', error)
|
|
||||||
// 返回 false 表示登录失败,Login 组件会据此停止跳转
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 退出逻辑
|
// 退出逻辑
|
||||||
|
|||||||
@ -57,10 +57,13 @@ service.interceptors.response.use(
|
|||||||
const data = error.response.data
|
const data = error.response.data
|
||||||
|
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
|
// 对于登录接口的401错误,不执行登出重定向,仅提示错误
|
||||||
|
if (error.config && !error.config.url.includes('/login')) {
|
||||||
message = '登录已过期,请重新登录'
|
message = '登录已过期,请重新登录'
|
||||||
// 这里可以触发登出逻辑
|
|
||||||
localStorage.clear()
|
localStorage.clear()
|
||||||
window.location.href = '/login'
|
window.location.href = '/login'
|
||||||
|
}
|
||||||
|
// 如果是登录接口,message会被后面的data.msg覆盖
|
||||||
} else if (status === 403) {
|
} else if (status === 403) {
|
||||||
message = '权限不足'
|
message = '权限不足'
|
||||||
} else if (status === 404) {
|
} else if (status === 404) {
|
||||||
|
|||||||
Reference in New Issue
Block a user