import Link from "next/link"; import { Metadata } from "next"; import { ChevronRight, FileText, MessageCircle, Flame, AlertCircle } from "lucide-react"; import { fetchUserProfile, fetchUserComments, type UserProfile, type UserCommentsResponse } from "@/lib/api"; import UserProfileContent from "./UserProfileContent"; import Avatar from "@/components/Avatar"; interface UserPageProps { params: Promise<{ id: string }>; searchParams: Promise<{ page?: string; tab?: string }>; } export async function generateMetadata({ params }: UserPageProps): Promise { const { id } = await params; try { const data = await fetchUserProfile(id, 1); return { title: data.user.nickname || data.user.username, description: `查看 ${data.user.nickname} 的资料、发帖与评论`, }; } catch { return { title: "用户不存在" }; } } export default async function UserPage({ params, searchParams }: UserPageProps) { const { id } = await params; const sp = await searchParams; const page = Math.max(1, parseInt(sp.page || "1", 10) || 1); const tab: "posts" | "comments" = sp.tab === "comments" ? "comments" : "posts"; let data: UserProfile; try { data = await fetchUserProfile(id, page); } catch { return (

用户不存在

该用户可能已注销或链接有误

返回首页
); } // 评论 tab:SSR 直出对应分页,URL(?tab=comments&page=N)与内容严格一致 let commentData: UserCommentsResponse | null = null; let commentError = false; if (tab === "comments") { try { commentData = await fetchUserComments(id, page); } catch { commentError = true; } } const u = data.user; const stats = [ { label: "发帖", value: data.stats.post_count, icon: }, { label: "评论", value: data.stats.comment_count, icon: }, ]; const showPoints = data.stats.points > 0; return (
{/* 用户信息卡片 */}

{u.nickname || u.username}

{u.role === "admin" && ( 管理员 )}

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

{u.signature && (

{u.signature}

)}
{stats.map((s) => ( {s.icon} {s.value} {s.label} ))} {showPoints && ( {data.stats.points} 积分 {data.stats.streak > 0 && · 连签 {data.stats.streak} 天} )}
{/* 发帖 / 评论 切换(URL 驱动,SSR 直出) */}
); }