'use client'; import { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; interface DashboardStats { customers: { total: number }; licenses: { total: number; byType: Record; byStatus: Record }; activations: { total: number; active: number }; alerts: { pending: number }; recentActivations: Array<{ id: string; licenseKey: string; licenseType: string; activatedAt: string; companyName: string | null; }>; } export default function AdminDashboard() { const router = useRouter(); const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetchStats(); }, []); const fetchStats = async () => { try { const res = await fetch('/api/admin/dashboard'); if (res.status === 401) { router.push('/admin/login'); return; } const data = await res.json(); setStats(data); } catch (error) { console.error('获取统计数据失败:', error); } finally { setLoading(false); } }; const handleLogout = async () => { await fetch('/api/admin/auth/logout', { method: 'POST' }); router.push('/admin/login'); }; if (loading) { return (
加载中...
); } return (
{/* 顶部导航 */}
{/* 统计卡片 */}
{/* 许可证分布 */}

许可证类型分布

{Object.entries(stats?.licenses.byType || {}).map(([type, count]) => (
{type} {count}
))}

许可证状态分布

{Object.entries(stats?.licenses.byStatus || {}).map(([status, count]) => (
{status === 'active' ? '正常' : status === 'disabled' ? '已禁用' : '已过期'} {count}
))}
{/* 最近激活 */}

最近激活

{stats?.recentActivations.map((activation) => ( ))} {!stats?.recentActivations.length && ( )}
许可证密钥 类型 客户 激活时间
{activation.licenseKey} {activation.companyName || '-'} {new Date(activation.activatedAt).toLocaleString()}
暂无激活记录
); } function StatCard({ title, value, highlight = false, }: { title: string; value: number; highlight?: boolean; }) { return (
{title}
{value}
); } function TypeBadge({ type }: { type: string }) { const colors: Record = { FREE: 'bg-gray-100 text-gray-700', STANDARD: 'bg-blue-100 text-blue-700', PRO: 'bg-purple-100 text-purple-700', }; return ( {type} ); }