diff --git a/frontend/admin-web/src/hooks/useDashboard.ts b/frontend/admin-web/src/hooks/useDashboard.ts index 4408cc71..1abbeefa 100644 --- a/frontend/admin-web/src/hooks/useDashboard.ts +++ b/frontend/admin-web/src/hooks/useDashboard.ts @@ -40,7 +40,8 @@ export function useDashboardStats() { queryKey: dashboardKeys.stats(), queryFn: async () => { const response = await dashboardService.getStats(); - return response.data.stats; + // 确保返回数组,即使 API 返回 undefined 或非数组 + return response?.data?.stats ?? []; }, staleTime: 30 * 1000, gcTime: 5 * 60 * 1000, @@ -71,7 +72,8 @@ export function useDashboardRegion() { queryKey: dashboardKeys.region(), queryFn: async () => { const response = await dashboardService.getRegionDistribution(); - return response.data.regions; + // 确保返回数组 + return response?.data?.regions ?? []; }, staleTime: 5 * 60 * 1000, // 5分钟后标记为过期 gcTime: 10 * 60 * 1000, @@ -87,7 +89,8 @@ export function useDashboardActivities(limit = 5) { queryKey: dashboardKeys.activities(limit), queryFn: async () => { const response = await dashboardService.getRecentActivities(limit); - return response.data.activities; + // 确保返回数组 + return response?.data?.activities ?? []; }, staleTime: 30 * 1000, // 30秒后标记为过期 gcTime: 5 * 60 * 1000,