import Link from "next/link"; import { Metadata } from "next"; import { fetchUserProfile, type UserProfile } from "@/lib/api"; import Pagination from "@/components/Pagination"; import UserProfileClient from "./UserProfileClient"; interface UserPageProps { params: Promise<{ id: string }>; searchParams: Promise<{ page?: string; tab?: string }>; } export async function generateMetadata({ params }: UserPageProps): Promise { const { id } = await params; return { title: `用户资料 - 姜十三论坛`, description: `查看用户 ${id} 的资料、发帖与评论`, }; } export default async function UserPage({ params, searchParams }: UserPageProps) { const { id } = await params; const { page: pageStr } = await searchParams; const page = Math.max(1, parseInt(pageStr || "1", 10) || 1); let data: UserProfile; try { data = await fetchUserProfile(id, page); } catch { return (

用户不存在

返回首页
); } const u = data.user; const roleLabel = u.role === "admin" ? "管理员" : "用户"; return (
{/* 用户信息卡片 */}
{u.avatar ? ( {u.nickname} ) : ( (u.nickname || u.username).charAt(0).toUpperCase() )}

{u.nickname || u.username}

{u.role === "admin" && ( {roleLabel} )}

@{u.username} · 加入于 {new Date(u.created_at).toLocaleDateString("zh-CN")}

{data.stats.post_count}{" "} 帖子 {data.stats.comment_count}{" "} 评论
{/* 发帖 / 评论 切换 */}
); }