fix: 修复评论提交状态处理和消息显示问题

修复requireReview配置的布尔转换问题,统一前后端评论状态处理逻辑
更新评论提交后的消息显示,支持从API响应中获取消息
This commit is contained in:
anghunk
2026-01-20 22:09:09 +08:00
parent 6a9d5c1167
commit cafabce917
4 changed files with 21 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@@ -230,7 +230,18 @@ export const postComment = async (c: Context<{ Bindings: Bindings }>) => {
}
})());
}
return c.json({ message: "Comment submitted. Awaiting moderation." });
if (defaultStatus === "pending") {
return c.json({
message: '已提交评论,待管理员审核后显示',
status: defaultStatus
});
}
return c.json({
message: '评论已提交',
status: defaultStatus
});
} catch (e: any) {
console.error("Create Comment Error:", e);

View File

@@ -157,9 +157,7 @@ export class CWDComments {
if (serverConfig.adminEnabled && serverConfig.adminBadge) {
this.config.adminBadge = serverConfig.adminBadge;
}
if (typeof serverConfig.requireReview === 'boolean') {
this.config.requireReview = serverConfig.requireReview;
}
this.config.requireReview = !!serverConfig.requireReview;
const api = createApiClient(this.config);
this.api = api;

View File

@@ -191,7 +191,7 @@ export function createCommentStore(config, fetchComments, submitComment) {
});
try {
await submitComment({
const result = await submitComment({
name: form.name,
email: form.email,
url: form.url,
@@ -199,9 +199,12 @@ export function createCommentStore(config, fetchComments, submitComment) {
adminToken: auth.getToken() // Add token if exists
});
const successMessage = config.requireReview
? '已提交评论,待管理员审核后显示'
: '评论已提交';
const successMessage =
result && typeof result.message === 'string'
? result.message
: config.requireReview
? '已提交评论,待管理员审核后显示'
: '评论已提交';
store.setState({
form: { ...form, content: '' },