feat: 实现文章点赞功能及相关API和UI组件
- 新增点赞功能API接口及数据库表结构 - 添加点赞状态管理及UI交互组件 - 实现点赞统计和列表查询功能 - 优化评论组件布局,将点赞按钮加入头部区域
This commit is contained in:
@@ -126,6 +126,8 @@ export function createCommentStore(config, fetchComments, submitComment) {
|
||||
replyingTo: null,
|
||||
replyContent: '',
|
||||
replyError: null,
|
||||
likeCount: 0,
|
||||
liked: false,
|
||||
});
|
||||
|
||||
// 监听用户信息变化,自动保存到 localStorage
|
||||
@@ -165,6 +167,14 @@ export function createCommentStore(config, fetchComments, submitComment) {
|
||||
}
|
||||
}
|
||||
|
||||
function setLikeState(likeCount, liked) {
|
||||
const safeCount = typeof likeCount === 'number' && Number.isFinite(likeCount) && likeCount >= 0 ? likeCount : 0;
|
||||
store.setState({
|
||||
likeCount: safeCount,
|
||||
liked: !!liked,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交评论
|
||||
*/
|
||||
@@ -362,7 +372,7 @@ export function createCommentStore(config, fetchComments, submitComment) {
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
return {
|
||||
// Store 实例
|
||||
store,
|
||||
|
||||
@@ -384,5 +394,6 @@ export function createCommentStore(config, fetchComments, submitComment) {
|
||||
clearError,
|
||||
clearSuccess,
|
||||
goToPage,
|
||||
setLikeState,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user