feat: 添加用户个人资料编辑功能,优化页面布局与导航

1. 后端新增用户资料更新接口,支持修改昵称、头像、邮箱和签名
2. 前端新增资料编辑表单页面,适配响应式布局
3. 优化帖子详情页布局与移动端适配逻辑
4. 重构首页侧边栏导航,使用卡片式板块展示
5. 移除全局板块缓存,调整Header导航移除板块菜单
6. 补充用户签名展示功能,完善用户信息返回字段
This commit is contained in:
2026-09-14 16:10:38 +08:00
parent e8882664fb
commit e2e5ba077c
16 changed files with 388 additions and 187 deletions

View File

@@ -26,6 +26,9 @@ export interface User {
nickname: string;
avatar: string;
role: string;
// 仅 /api/me 与 /api/profile 响应中返回(用户自身敏感信息)
email?: string;
signature?: string;
}
// /api/me 响应:用户信息 + 未读通知数(SSR layout 一次请求直出)
@@ -206,6 +209,7 @@ export interface UserProfile {
username: string;
nickname: string;
avatar: string;
signature: string;
role: string;
created_at: string;
};
@@ -510,6 +514,21 @@ export async function apiChangePassword(oldPassword: string, newPassword: string
return res.json();
}
// 更新当前用户资料(昵称、头像、邮箱、签名)
export async function apiUpdateProfile(data: {
nickname: string;
avatar?: string;
email?: string;
signature?: string;
}): Promise<{ user?: User; error?: string }> {
const res = await fetchWithRefresh("/api/profile", {
method: "PUT",
headers: clientHeaders({ "Content-Type": "application/json" }),
body: JSON.stringify(data),
});
return res.json();
}
export async function apiToggleLike(postId: string) {
const res = await fetchWithRefresh(`/api/posts/${postId}/like`, {
method: "POST",

View File

@@ -1,16 +1,6 @@
import { cache } from "react";
import { fetchBoards, fetchMe } from "./api";
import { fetchMe } from "./api";
// 同一 SSR 请求内去重:layout 与页面可能同时需要当前用户,
// 相同 Cookie 头参数下只产生一次 /api/me 调用。
export const getMeCached = cache((cookieHeader?: string) => fetchMe(cookieHeader));
// 全站导航需要板块列表:layout 每请求调用,失败降级为空列表(导航隐藏,不阻塞页面)
export const getBoardsCached = cache(async () => {
try {
const { boards } = await fetchBoards();
return boards;
} catch {
return [];
}
});