This commit is contained in:
2026-03-23 13:20:19 +08:00
parent bdcdd8106c
commit fea4745142
2 changed files with 10 additions and 3 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
@import './base.css'; @import './base.css';
@import 'tailwindcss'; @import 'tailwindcss/theme' layer(theme);
@import 'tailwindcss/utilities' layer(utilities);
/* 应用全局样式 */ /* 应用全局样式 */
#app { #app {
+8 -2
View File
@@ -53,7 +53,7 @@ async function request<T = unknown>(url: string, options: RequestOptions = {}):
signal: controller.signal, signal: controller.signal,
}) })
// 401 未授权:跳过登录/注册接口(由页面自行处理错误提示),其余接口重定向到登录页 // 401 未授权:登录/注册接口解析后端错误信息,其余接口重定向到登录页
if (response.status === 401) { if (response.status === 401) {
const isAuthEndpoint = /\/api\/v1\/(login|register)$/.test(url) const isAuthEndpoint = /\/api\/v1\/(login|register)$/.test(url)
if (!isAuthEndpoint) { if (!isAuthEndpoint) {
@@ -64,9 +64,15 @@ async function request<T = unknown>(url: string, options: RequestOptions = {}):
window.location.pathname + window.location.search, window.location.pathname + window.location.search,
) )
window.location.href = `/login?redirect=${redirect}` window.location.href = `/login?redirect=${redirect}`
}
throw new ApiError('登录已过期,请重新登录', 401) throw new ApiError('登录已过期,请重新登录', 401)
} }
let msg = '用户名或密码错误'
try {
const body = await response.json()
if (body.message) msg = body.message
} catch { /* ignore parse error */ }
throw new ApiError(msg, 401)
}
// 防护非 JSON 响应(如网关 HTML 错误页) // 防护非 JSON 响应(如网关 HTML 错误页)
let result let result