feat: 就地通过评审,并为已过审用户提供默认可关的免审发布

帖/评管理入口可直接通过;站点默认信任已有 published 内容的用户后续直发。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 05:37:57 +08:00
parent b0170a99fd
commit f3145b24ff
14 changed files with 330 additions and 40 deletions

View File

@@ -3,9 +3,17 @@
import { useRef, useState } from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { Trash2, MessagesSquare, ChevronRight, ChevronDown } from "lucide-react";
import { Trash2, MessagesSquare, ChevronRight, ChevronDown, BadgeCheck } from "lucide-react";
import ReactMarkdown from "react-markdown";
import { apiCreateComment, apiDeleteComment, apiAcceptBounty, apiAcceptQuestion, type CommentNode, type User } from "@/lib/api";
import {
apiCreateComment,
apiDeleteComment,
apiAcceptBounty,
apiAcceptQuestion,
apiAdminApproveComment,
type CommentNode,
type User,
} from "@/lib/api";
import { canModerateBoard } from "@/lib/roles";
import { toast } from "@/lib/toast";
import Avatar from "./Avatar";
@@ -59,6 +67,7 @@ export default function CommentSection({
const [deletingId, setDeletingId] = useState<number | null>(null);
const [confirmingId, setConfirmingId] = useState<number | null>(null);
const [acceptingId, setAcceptingId] = useState<number | null>(null);
const [approvingId, setApprovingId] = useState<number | null>(null);
// 折叠状态:哪些楼层展开了子回复(默认全部折叠,SSR 初始为收起)
const [expandedFloors, setExpandedFloors] = useState<Set<number>>(new Set());
const textareaRef = useRef<HTMLTextAreaElement>(null);
@@ -163,11 +172,27 @@ export default function CommentSection({
}
};
const handleApprove = async (commentId: number) => {
setApprovingId(commentId);
try {
await apiAdminApproveComment(commentId);
toast("已通过评审", "ok");
router.refresh();
} catch (e) {
toast(e instanceof Error ? e.message : "通过评审失败");
} finally {
setApprovingId(null);
}
};
// 引用功能已移除:与"回复"功能重叠,且会割裂讨论上下文(抖音风格无此功能)
const canDelete = (comment: CommentNode) =>
!!user && (user.id === comment.user.id || canModerateBoard(user, boardId));
const canApprove = (comment: CommentNode) =>
!!user && comment.status === "pending" && canModerateBoard(user, boardId);
const canAccept = (comment: CommentNode) =>
!!acceptMode &&
!!user &&
@@ -302,6 +327,18 @@ export default function CommentSection({
{acceptingId === c.id ? "采纳中…" : acceptMode === "question" ? "采纳答案" : "采纳"}
</button>
)}
{canApprove(c) && (
<button
type="button"
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
disabled={approvingId === c.id}
onClick={() => void handleApprove(c.id)}
data-tip="通过评审,公开此评论"
>
<BadgeCheck size={13} />
{approvingId === c.id ? "通过中…" : "通过评审"}
</button>
)}
</div>
{canDelete(c) && (
<button
@@ -394,6 +431,18 @@ export default function CommentSection({
{acceptingId === c.id ? "采纳中…" : acceptMode === "question" ? "采纳答案" : "采纳"}
</button>
)}
{canApprove(c) && (
<button
type="button"
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
disabled={approvingId === c.id}
onClick={() => void handleApprove(c.id)}
data-tip="通过评审,公开此评论"
>
<BadgeCheck size={13} />
{approvingId === c.id ? "通过中…" : "通过评审"}
</button>
)}
</div>
{canDelete(c) && (
<button

View File

@@ -3,8 +3,8 @@
import { useState, useEffect, useRef } from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { Pencil, Trash2, Pin, Star, SlidersHorizontal, ChevronDown, Check } from "lucide-react";
import { apiMe, apiDeletePost, apiTogglePin, apiToggleRecommend, type User } from "@/lib/api";
import { Pencil, Trash2, Pin, Star, SlidersHorizontal, ChevronDown, Check, BadgeCheck } from "lucide-react";
import { apiMe, apiDeletePost, apiTogglePin, apiToggleRecommend, apiAdminApprovePost, type User } from "@/lib/api";
import { canModerateBoard, isAdminOrAbove } from "@/lib/roles";
import { toast } from "@/lib/toast";
import ConfirmDialog from "@/components/ConfirmDialog";
@@ -15,9 +15,18 @@ interface PostActionsProps {
boardId: number;
pinned: number;
recommended: boolean;
/** 帖子审核状态:pending 时对可审者显示「通过评审」 */
status: string;
}
export default function PostActions({ postId, authorId, boardId, pinned, recommended }: PostActionsProps) {
export default function PostActions({
postId,
authorId,
boardId,
pinned,
recommended,
status,
}: PostActionsProps) {
const router = useRouter();
const [user, setUser] = useState<User | null>(null);
const [open, setOpen] = useState(false);
@@ -54,6 +63,7 @@ export default function PostActions({ postId, authorId, boardId, pinned, recomme
// 作者本人或有该板块审核权的管理团队可管理;置顶/加精仅管理员及以上
const canManage = !!user && (user.id === authorId || canModerateBoard(user, boardId));
const isAdmin = !!user && isAdminOrAbove(user.role);
const canApprove = !!user && status === "pending" && canModerateBoard(user, boardId);
const handleDelete = async () => {
setDeleting(true);
@@ -73,6 +83,20 @@ export default function PostActions({ postId, authorId, boardId, pinned, recomme
}
};
const handleApprove = async () => {
setActing(true);
setOpen(false);
try {
await apiAdminApprovePost(Number(postId));
toast("已通过评审", "ok");
router.refresh();
} catch (e) {
toast(e instanceof Error ? e.message : "通过评审失败");
} finally {
setActing(false);
}
};
const handlePin = async () => {
setActing(true);
setOpen(false);
@@ -137,6 +161,21 @@ export default function PostActions({ postId, authorId, boardId, pinned, recomme
boxShadow: "var(--shadow-lg)",
}}
>
{canApprove && (
<>
<button
type="button"
role="menuitem"
onClick={handleApprove}
className={itemCls}
style={{ color: "var(--accent)" }}
>
<BadgeCheck size={14} className="shrink-0" />
<span className="flex-1 text-left">通过评审</span>
</button>
<div style={{ height: 1, background: "var(--line)" }} />
</>
)}
{isAdmin && (
<>
<button