'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import useSWR from 'swr'; import { Newspaper, Package, MessageSquare, Users, Settings, ArrowUpRight, ExternalLink, ChevronRight, } from 'lucide-react'; import { AdminHeader } from '@/components/admin/AdminHeader'; import { Card, CardContent } from '@/components/ui/card'; import { adminApi } from '@/lib/admin-services'; import type { Message } from '@/lib/types'; export default function DashboardPage() { const [hydrated, setHydrated] = useState(false); useEffect(() => setHydrated(true), []); const { data: productCount } = useSWR( hydrated ? 'dashboard:product-count' : null, () => adminApi.productPaginate({ page: 1, pageSize: 1 }).then((r) => r.total), ); const { data: newsCount } = useSWR( hydrated ? 'dashboard:news-count' : null, () => adminApi.newsPaginate({ page: 1, pageSize: 1 }).then((r) => r.total), ); const { data: teamCount } = useSWR( hydrated ? 'dashboard:team-count' : null, () => adminApi.teamAll().then((r) => r.length), ); const { data: message } = useSWR<{ total: number; unread: number }>( hydrated ? 'dashboard:message-summary' : null, () => adminApi .messagePaginate({ page: 1, pageSize: 100 }) .then((r) => ({ total: r.total, unread: r.list.filter((m: Message) => m.isRead === 0).length, })), ); const stats = [ { href: '/admin/product', label: '产品管理', value: productCount, icon: , }, { href: '/admin/news', label: '新闻资讯', value: newsCount, icon: , }, { href: '/admin/team', label: '团队成员', value: teamCount, icon: , }, { href: '/admin/message', label: '客户留言', value: message?.total, icon: , badge: message && message.unread > 0 ? `${message.unread} 未读` : undefined, }, ]; const quickActions = [ { href: '/admin/product', label: '发布产品方案', hint: '新增 / 编辑产品', icon: , }, { href: '/admin/news', label: '发布新闻动态', hint: '撰写行业资讯', icon: , }, { href: '/admin/team', label: '维护团队', hint: '成员信息', icon: , }, { href: '/admin/site-config', label: '站点配置', hint: '基础信息 / 联系方式', icon: , }, ]; return (
{/* ===== 数据统计卡 ===== */}
{stats.map((s) => ( ))}
{/* ===== 主体两栏 ===== */}
{/* 快捷操作 */}

快捷操作

常用入口
{quickActions.map((a) => ( {a.icon}
{a.label}
{a.hint}
))}
{/* 系统信息 / 访问地址 */}
); } function Stat({ href, label, value, icon, badge, }: { href: string; label: string; value: number | undefined; icon: React.ReactNode; badge?: string; }) { return (
{icon} {badge ? ( {badge} ) : ( )}
{value ?? '—'}
{label}
); }