fix: 修复评论提交状态处理和消息显示问题
修复requireReview配置的布尔转换问题,统一前后端评论状态处理逻辑 更新评论提交后的消息显示,支持从API响应中获取消息
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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: '' },
|
||||
|
||||
Reference in New Issue
Block a user