import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { CheckCircle2, FileEdit, FileText, Plus } from 'lucide-react' import { fetchStats, type Stats } from '@/api/posts' export default function DashboardPage() { const [stats, setStats] = useState(null) const [error, setError] = useState('') useEffect(() => { let cancelled = false fetchStats() .then((s) => { if (!cancelled) setStats(s) }) .catch((e: Error) => { if (!cancelled) setError(e.message) }) return () => { cancelled = true } }, []) const cards = [ { label: '文章总数', value: stats?.total, icon: FileText }, { label: '已发布', value: stats?.published, icon: CheckCircle2 }, { label: '草稿', value: stats?.draft, icon: FileEdit }, ] return (

仪表盘

内容概览

新建文章
{error && (

{error}

)}
{cards.map((c) => (
{c.label}
{c.value ?? '—'}
))}

最近更新

全部文章 →
{stats && stats.recent.length > 0 ? ( stats.recent.map((post) => ( {post.title} {post.published_at ? ( 已发布 ) : ( 草稿 )} {post.updated_at.slice(0, 10)} )) ) : (

{stats ? '还没有文章,点右上角新建' : '加载中…'}

)}
) }