新增后端管理页面

This commit is contained in:
2026-01-28 15:35:01 +08:00
parent 5334ee9d41
commit 62ac723c95
11 changed files with 1515 additions and 51 deletions

View File

@@ -108,11 +108,18 @@ export class ApiClient {
// 检查响应状态
if (!response.ok) {
const errorData = await this.parseResponse(response)
throw new ApiError(
const apiError = new ApiError(
errorData?.message || `HTTP ${response.status}: ${response.statusText}`,
response.status,
errorData
)
// 401 未授权错误,自动跳转到登录页
if (response.status === 401) {
this.handle401Error()
}
throw apiError
}
return await this.parseResponse(response)
@@ -130,6 +137,24 @@ export class ApiClient {
}
}
/**
* 处理 401 错误
*/
private handle401Error() {
// 清除本地存储的 token
localStorage.removeItem('admin_token')
localStorage.removeItem('admin_token_expires')
this.clearAuthToken()
// 只有在管理页面时才跳转到登录页
if (typeof window !== 'undefined' && window.location.pathname.startsWith('/admin')) {
// 避免重复跳转
if (!window.location.pathname.includes('/admin/login')) {
window.location.href = '/admin/login'
}
}
}
/**
* 解析响应数据
*/