feat(settings): 后台可开关全站评论

关闭后禁止新评论与回复,已有内容仍可浏览;设置经 WS 同步到前台。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-16 07:01:46 +08:00
parent bcb4f6a603
commit 3e135542d3
5 changed files with 73 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import {
Code2,
Globe,
Loader2,
MessageSquare,
Save,
Sparkles,
UserPlus,
@@ -49,6 +50,7 @@ export default function SettingsAdmin({ initial }: { initial: PublicSettings })
const [siteName, setSiteName] = useState(initial.site_name);
const [siteDescription, setSiteDescription] = useState(initial.site_description);
const [allowRegister, setAllowRegister] = useState(initial.allow_register);
const [allowComments, setAllowComments] = useState(initial.allow_comments !== false);
const [codeAutoFold, setCodeAutoFold] = useState(
initial.code_block_auto_fold !== false
);
@@ -62,6 +64,7 @@ export default function SettingsAdmin({ initial }: { initial: PublicSettings })
const [savedDesc, setSavedDesc] = useState(initial.site_description);
const [saving, setSaving] = useState(false);
const [togglingReg, setTogglingReg] = useState(false);
const [togglingComments, setTogglingComments] = useState(false);
const [togglingFold, setTogglingFold] = useState(false);
const [savingFoldLines, setSavingFoldLines] = useState(false);
const [uiAnimations, setUiAnimations] = useState(initial.ui_animations !== false);
@@ -116,6 +119,20 @@ export default function SettingsAdmin({ initial }: { initial: PublicSettings })
}
};
const toggleComments = async () => {
if (togglingComments) return;
const next = !allowComments;
setTogglingComments(true);
try {
const res = await apiUpdateSiteSettings({ allow_comments: next });
setAllowComments(res.allow_comments);
toast(res.allow_comments ? "已开放评论" : "已关闭评论", "ok");
} catch (e) {
toast(e instanceof Error ? e.message : "保存失败");
} finally {
setTogglingComments(false);
}
};
const toggleCodeFold = async () => {
if (togglingFold) return;
@@ -201,7 +218,7 @@ export default function SettingsAdmin({ initial }: { initial: PublicSettings })
站点设置
</h1>
<p className="meta mt-1.5 text-[12.5px]">
配置站点名称、简介与注册开关;主题色请到「外观」页调整
配置站点名称、简介与注册/评论开关;主题色请到「外观」页调整
</p>
</div>
@@ -265,6 +282,23 @@ export default function SettingsAdmin({ initial }: { initial: PublicSettings })
/>
</section>
<section className="j13-module p-5 sm:p-6 mb-5 flex items-start justify-between gap-4 flex-wrap">
<div className="min-w-0 flex-1">
<h2 className="text-[15px] font-semibold flex items-center gap-1.5" style={{ color: "var(--ink)" }}>
<MessageSquare size={15} /> 开放评论
</h2>
<p className="meta text-[12.5px] mt-1 leading-relaxed">
关闭后全站禁止发表新评论与回复,已有评论仍可浏览。适用于 ICP/IPC
备案审核等合规需要;前台仅提示「暂停评论」,不会展示备案事由。
</p>
</div>
<Switch
checked={allowComments}
disabled={togglingComments}
onChange={() => void toggleComments()}
label="开放评论"
/>
</section>
<section className="j13-module p-5 sm:p-6 mb-5">
<div className="flex items-start justify-between gap-4 flex-wrap">