import { useEffect, useState } from 'react' import { ArrowUpRight, BookOpen, Flame, Newspaper, Siren, Store, Tags, Loader2 } from 'lucide-react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { api, type DashboardData, type OverviewStats } from '@/lib/api' export interface PageKeyHintType { onNavigate?: (page: 'intel' | 'qa' | 'analysis' | 'reports') => void } const statCards = (ovStats: OverviewStats) => [ { label: '知识条目', value: ovStats.knowledgeItems.toLocaleString(), icon: BookOpen, sub: '持续结构化沉淀', color: 'text-orange-500 bg-orange-50' }, { label: '今日新增情报', value: `+${ovStats.todayNew}`, icon: Newspaper, sub: `来自 ${ovStats.sourcesMp + ovStats.sourcesVideo} 个监控信源`, color: 'text-blue-500 bg-blue-50' }, { label: '追踪品牌', value: ovStats.brandsTracked, icon: Store, sub: '覆盖 12 个赛道', color: 'text-emerald-500 bg-emerald-50' }, { label: '已生成报告', value: ovStats.reportsTotal, icon: Tags, sub: '周报 / 专题报告', color: 'text-violet-500 bg-violet-50' }, ] const typeColor: Record = { 政策监管: 'bg-red-50 text-red-600 border-red-200', 品牌动态: 'bg-blue-50 text-blue-600 border-blue-200', 品类趋势: 'bg-violet-50 text-violet-600 border-violet-200', 经营干货: 'bg-emerald-50 text-emerald-600 border-emerald-200', 供应链: 'bg-amber-50 text-amber-600 border-amber-200', 消费洞察: 'bg-cyan-50 text-cyan-600 border-cyan-200', } export default function Dashboard({ onNavigate }: PageKeyHintType) { const [data, setData] = useState(null) const [stats, setStats] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { Promise.allSettled([api.getDashboard(), api.getStats()]).then(([dRes, sRes]) => { if (dRes.status === 'fulfilled') setData(dRes.value) if (sRes.status === 'fulfilled') setStats(sRes.value) setLoading(false) }) }, []) const topIntel = data?.topIntel ?? [] const policyAlerts = data?.policyAlerts?.map((p) => ({ ...p, type: '政策监管', sourceType: '公众号', category: '综合', keyPoints: [], entities: [], timeliness: '高', score: 0 })) ?? [] const hotKw = data?.hotKeywords ?? [] const ovStats: OverviewStats = { sourcesMp: stats?.sourcesMp ?? 0, sourcesVideo: stats?.sourcesVideo ?? 0, todayNew: stats?.todayNew ?? 0, knowledgeItems: stats?.knowledgeItems ?? 0, brandsTracked: stats?.brandsTracked ?? 0, reportsTotal: stats?.reportsTotal ?? 0, } if (loading) { return (
) } return (

仪表盘

面向餐饮经营者的行业情报总览

{/* 统计卡片 */}
{(statCards(ovStats)).map((s) => { const Icon = s.icon return (
{s.label}
{s.value}
{s.sub}
) })}
{/* 高价值情报 TOP5 */} 高价值情报 TOP 5 {topIntel.length === 0 && (
暂无情报数据
)} {topIntel.map((item, idx) => (
{idx + 1}
{item.title}
{item.source} · {item.date} {item.type}
{item.score}
价值分
))}
{/* 政策预警 */} 政策预警 {policyAlerts.length === 0 && (
暂无政策预警
)} {policyAlerts.map((p) => (
{p.title}
{p.date} · {p.source}
))}
{/* 热词榜 */} 本周热词 {hotKw.length === 0 ? (
暂无热词数据
) : (
{hotKw.map((k) => ( {k.word} +{k.change}% ))}
)}
) }