import { useEffect, useState } from "react";
import { Package, ClipboardList, Loader2, AlertCircle } from "lucide-react";
import { fetchDashboardStats, type DashboardStats } from "../../services/dashboardApi";
function StatCard({
label,
total,
pending,
progress,
done,
icon: Icon,
}: {
label: string;
total: number;
pending: number;
progress: number;
done: number;
icon: React.ComponentType<{ className?: string }>;
}) {
return (
{label}
{total}
{pending > 0 && (
)}
{progress > 0 && (
)}
{done > 0 && (
)}
待处理 {pending}
进行中 {progress}
已完成 {done}
);
}
export default function AdminDashboard() {
const [stats, setStats] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
fetchDashboardStats()
.then(setStats)
.catch(() => setError("加载统计数据失败,请确认后端已启动"))
.finally(() => setLoading(false));
}, []);
if (loading) {
return
;
}
if (error) {
return ;
}
if (!stats) return null;
return (
);
}