import { useQuery } from '@tanstack/react-query' import api from '@/lib/api' import { LoadingSpinner } from '@/components/LoadingSpinner' const LEVEL_STYLES: Record = { red: { bg: 'bg-red-50', border: 'border-red-200', text: 'text-red-700', icon: '🔴' }, orange: { bg: 'bg-orange-50', border: 'border-orange-200', text: 'text-orange-700', icon: '🟠' }, yellow: { bg: 'bg-yellow-50', border: 'border-yellow-200', text: 'text-yellow-700', icon: '🟡' }, green: { bg: 'bg-green-50', border: 'border-green-200', text: 'text-green-700', icon: '🟢' }, } const CATEGORY_LABELS: Record = { '人效': '人效分析', '成本': '成本管控', '加班': '加班管理', '客流': '客流规律', '考勤': '考勤管理', '离职': '人员稳定', } export function OverallAnalysisTab({ month }: { month: string }) { const { data, isLoading } = useQuery({ queryKey: ['ss/overall-analysis', month], queryFn: () => api.get('/smart-scheduling/overall-analysis', { params: { month } }), }) if (isLoading) return const result = (data as any)?.data || {} const kpis: any[] = result.kpis || [] const insights: any[] = result.insights || [] const redCount = insights.filter(i => i.level === 'red').length const orangeCount = insights.filter(i => i.level === 'orange').length const yellowCount = insights.filter(i => i.level === 'yellow').length const greenCount = insights.filter(i => i.level === 'green').length return (
{/* KPI 卡片 */}
{kpis.map((k) => (

{k.label}

{k.value} {k.unit}

))}
{/* 预警汇总 */}

红色预警

{redCount}

橙色预警

{orangeCount}

黄色提醒

{yellowCount}

良好表现

{greenCount}

{/* 智能诊断建议 */}

智能诊断建议

基于人效、客流、考勤、离职等多维度数据自动生成
{insights.length === 0 ? (
暂无异常,各项指标正常
) : (
{insights.map((ins, i) => { const style = LEVEL_STYLES[ins.level] || LEVEL_STYLES.yellow return (
{style.icon}
{CATEGORY_LABELS[ins.category] || ins.category}

{ins.title}

{ins.detail}

💡 建议:

{ins.suggestion}

) })}
)}
) }