feat(评论): 新增功能开关管理及评论点赞功能优化

- 在管理后台添加功能开关页面,支持控制评论点赞和文章点赞功能的开启/关闭
- 优化评论点赞功能,支持取消点赞和本地存储点赞状态
- 更新点赞UI样式,提升用户体验
- 添加相关API接口和文档说明
This commit is contained in:
anghunk
2026-01-22 22:26:43 +08:00
parent 74c7fa9e1c
commit e0be92b1fe
15 changed files with 806 additions and 120 deletions

View File

@@ -177,7 +177,7 @@ export function createCommentStore(config, fetchComments, submitComment, likeCom
});
}
async function likeComment(commentId) {
async function likeComment(commentId, isLike = true) {
const state = store.getState();
if (!likeCommentFn || state.commentLikeLoadingId === commentId) {
return;
@@ -196,6 +196,7 @@ export function createCommentStore(config, fetchComments, submitComment, likeCom
});
try {
const safeComments = Array.isArray(state.comments) ? state.comments : [];
const delta = isLike ? 1 : -1;
const nextComments = safeComments.map((item) => {
if (!item || typeof item.id !== 'number') {
return item;
@@ -205,9 +206,10 @@ export function createCommentStore(config, fetchComments, submitComment, likeCom
typeof item.likes === 'number' && Number.isFinite(item.likes) && item.likes >= 0
? item.likes
: 0;
const nextLikes = Math.max(0, current + delta);
return {
...item,
likes: current + 1,
likes: nextLikes,
};
}
if (Array.isArray(item.replies) && item.replies.length > 0) {
@@ -220,9 +222,10 @@ export function createCommentStore(config, fetchComments, submitComment, likeCom
typeof reply.likes === 'number' && Number.isFinite(reply.likes) && reply.likes >= 0
? reply.likes
: 0;
const nextLikes = Math.max(0, current + delta);
return {
...reply,
likes: current + 1,
likes: nextLikes,
};
}
return reply;
@@ -237,7 +240,7 @@ export function createCommentStore(config, fetchComments, submitComment, likeCom
store.setState({
comments: nextComments,
});
await likeCommentFn(id);
await likeCommentFn(id, isLike);
} catch (e) {
} finally {
const latest = store.getState();