Merge branch 'PingChuan' into shiy-login

# Conflicts:
#	app/config/api-config.ts
fix: 1. 修复无法加载数据的问题:没有从入口页中进来会缺少数据。
2. 加强后端接口关于token的校验错误和权限校验错误的管理。

feat: 1. 对接后端的数据看板的接口。
2. 将系统设置单独抽出来作为管理员的固定一个入口。
This commit is contained in:
2025-11-22 15:57:22 +08:00
27 changed files with 1972 additions and 643 deletions
+28 -2
View File
@@ -443,9 +443,35 @@ export async function apiRequest<T>(
// 检查API返回的状态码
const data = response.data;
if (data && typeof data === 'object' && 'code' in data && data.code !== 0) {
console.error(`API请求失败: ${data.message || data.msg || '未知错误'} - ${url}`);
const errorMessage = data.message || data.msg || '未知错误';
console.error(`API请求失败: ${errorMessage} - ${url}`);
// 🔑 检测令牌过期错误
const isTokenExpired = errorMessage.includes('令牌已过期') ||
errorMessage.includes('令牌') ||
errorMessage.includes('token') ||
errorMessage.includes('expired') ||
errorMessage.includes('认证') ||
errorMessage.includes('未授权');
if (isTokenExpired) {
console.error('🔑 [API Client] 检测到令牌过期,准备清除会话并重定向...');
// 只在客户端执行重定向
if (typeof window !== 'undefined') {
console.error('🔑 [API Client] 客户端环境,清除 localStorage 并重定向到登录页');
// 清除所有认证相关数据
localStorage.removeItem('access_token');
localStorage.removeItem('user_info');
sessionStorage.clear();
// 重定向到登录页
window.location.href = '/login?expired=true';
}
}
return {
error: data.message || data.msg || '请求失败',
error: errorMessage,
status: response.status,
headers: responseHeaders
};