fix(admin): 后台列表切换保留当前内容,去掉加载占位
用户档案、用户列表、内容筛选与公告页等数据到达后再换视图,避免滚动条闪动。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import type { Metadata } from "next";
|
||||
import { cookies } from "next/headers";
|
||||
import { authCookieHeader } from "@/lib/cookies";
|
||||
import { fetchAdminUserAudit } from "@/lib/api";
|
||||
import {
|
||||
fetchAdminUserAudit,
|
||||
fetchAdminUserAuditPosts,
|
||||
type AdminAuditPostItem,
|
||||
} from "@/lib/api";
|
||||
import { getMeCached } from "@/lib/serverData";
|
||||
import { isOwner, isSuperOrOwner } from "@/lib/roles";
|
||||
import Forbidden from "../../Forbidden";
|
||||
@@ -32,13 +36,38 @@ export default async function AdminUserAuditPage({ params }: PageProps) {
|
||||
return <Forbidden text="用户内容档案仅站长可查看。" />;
|
||||
}
|
||||
|
||||
let profile;
|
||||
try {
|
||||
profile = await fetchAdminUserAudit(userId, cookie || undefined);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : "获取用户档案失败";
|
||||
return <Forbidden text={msg} />;
|
||||
const cookieOrUndef = cookie || undefined;
|
||||
const [profileSettled, postsSettled] = await Promise.all([
|
||||
fetchAdminUserAudit(userId, cookieOrUndef)
|
||||
.then((profile) => ({ ok: true as const, profile }))
|
||||
.catch((e) => ({
|
||||
ok: false as const,
|
||||
error: e instanceof Error ? e.message : "获取用户档案失败",
|
||||
})),
|
||||
fetchAdminUserAuditPosts(userId, 1, cookieOrUndef)
|
||||
.then((res) => ({ ok: true as const, res }))
|
||||
.catch((e) => ({
|
||||
ok: false as const,
|
||||
error: e instanceof Error ? e.message : "获取帖子失败",
|
||||
})),
|
||||
]);
|
||||
|
||||
if (!profileSettled.ok) {
|
||||
return <Forbidden text={profileSettled.error} />;
|
||||
}
|
||||
|
||||
return <UserAuditClient userId={userId} initial={profile} />;
|
||||
const initialPosts: AdminAuditPostItem[] = postsSettled.ok ? postsSettled.res.items || [] : [];
|
||||
const initialPostsTotal = postsSettled.ok ? postsSettled.res.total : 0;
|
||||
const initError = postsSettled.ok ? "" : postsSettled.error;
|
||||
const profile = profileSettled.profile;
|
||||
|
||||
return (
|
||||
<UserAuditClient
|
||||
userId={userId}
|
||||
initial={profile}
|
||||
initialPosts={initialPosts}
|
||||
initialPostsTotal={initialPostsTotal}
|
||||
initError={initError}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user