import type { Metadata } from 'next'; import { publicApi } from '@/lib/services'; import { ProductCard } from '@/components/front/ProductCard'; import type { ProductCategory } from '@/lib/types'; export const metadata: Metadata = { title: '产品中心', description: '查看我们的全部产品与解决方案。', }; export const revalidate = 60; interface PageProps { searchParams: { categoryId?: string; keyword?: string; page?: string }; } export default async function ProductsPage({ searchParams }: PageProps) { const page = Number(searchParams.page ?? 1); const categoryId = searchParams.categoryId ? Number(searchParams.categoryId) : undefined; const [categories, productsRes] = await Promise.all([ publicApi.getProductCategories().catch(() => [] as ProductCategory[]), publicApi .getProducts({ page, pageSize: 12, categoryId, keyword: searchParams.keyword, }) .catch(() => ({ list: [], total: 0, page, pageSize: 12 })), ]); return (

产品中心

共 {productsRes.total} 款产品

{/* 分类筛选 */}
全部 {categories.map((c) => ( {c.name} ))}
{/* 列表 */}
{productsRes.list.map((p) => ( ))}
{productsRes.list.length === 0 && (
暂无产品
)} {/* 分页 */} {productsRes.total > 12 && ( )}
); } function Pagination({ page, total, pageSize, baseQuery, }: { page: number; total: number; pageSize: number; baseQuery: Record; }) { const totalPages = Math.ceil(total / pageSize); const buildHref = (p: number) => { const qs = new URLSearchParams({ ...(baseQuery as Record), page: String(p), }).toString(); return `/products?${qs}`; }; return (
上一页 {page} / {totalPages} = totalPages ? 'pointer-events-none opacity-50' : 'hover:bg-gray-50' }`} > 下一页
); }