diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue index ef90945..41edd69 100644 --- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue +++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/components/PostPage.vue @@ -27,9 +27,9 @@

{{ post.summary }}

- 浏览量 {{ post.viewCount }} - 评论 {{ post.comments }} - 赞 {{ post.likes }} + 👁 {{ post.viewCount }} + 🗨 {{ post.comments }} + ♥ {{ post.likes }}
diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js index da07d51..53c4fc0 100644 --- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js +++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js @@ -271,5 +271,65 @@ export const usePostDetailStore = defineStore("postDetail", { ElMessage.error(e.response?.message || '删除失败,请稍后重试'); } }, + //帖子点赞和取消 + async PostLike() { + if (!this.post || !this.post.postId) return; + try { + const url = `/post/like/${this.post.postId}`; + if (!this.isLike) { + // 点赞 + const res = await request.put(url); + if (res.code === 200) { + this.isLike = true; + this.post.likeCount = (this.post.likeCount || 0) + 1; + ElMessage.success('点赞成功'); + } else { + ElMessage.error(res.message || '点赞失败'); + } + } else { + // 取消点赞 + const res = await request.put(url); + if (res.code === 200) { + this.isLike = false; + this.post.likeCount = Math.max((this.post.likeCount || 1) - 1, 0); + ElMessage.success('已取消点赞'); + } else { + ElMessage.error(res.message || '取消点赞失败'); + } + } + } catch (e) { + ElMessage.error(e.response?.message || '操作失败,请稍后重试'); + } + }, + // 评论点赞和取消 + async CommentLike(commentObj) { + if (!commentObj || !commentObj.id) return; + try { + const url = `/comment/like/${commentObj.id}`; + if (!commentObj.isLike) { + // 点赞 + const res = await request.put(url); + if (res.code === 200) { + commentObj.isLike = true; + commentObj.likeCount = (commentObj.likeCount || 0) + 1; + ElMessage.success('点赞成功'); + } else { + ElMessage.error(res.message || '点赞失败'); + } + } else { + // 取消点赞 + const res = await request.put(url); + if (res.code === 200) { + commentObj.isLike = false; + commentObj.likeCount = Math.max((commentObj.likeCount || 1) - 1, 0); + ElMessage.success('已取消点赞'); + } else { + ElMessage.error(res.message || '取消点赞失败'); + } + } + } catch (e) { + ElMessage.error(e.response?.message || '操作失败,请稍后重试'); + } + } }, }); \ No newline at end of file diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue index 467e4a0..72d11ed 100644 --- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue +++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue @@ -24,9 +24,19 @@

{{ postDetailStore.post?.title || '' }}

{{ postDetailStore.post?.content || '' }}

- 浏览量 {{ postDetailStore.post?.viewCount ?? 0 }} - 点赞 {{ postDetailStore.post?.likeCount ?? 0 }} - 评论 {{ postDetailStore.post?.commentCount ?? 0 }} + 👁 {{ postDetailStore.post?.viewCount ?? 0 }} + 🗨 {{ postDetailStore.post?.commentCount ?? 0 }} + + +
发布时间:{{ postDetailStore.post?.createTime ? formatTime(postDetailStore.post.createTime) : '' }} @@ -50,7 +60,14 @@

{{ comment.content || '' }}

{{ comment.createTime ? formatTime(comment.createTime) : '' }} - 赞 {{ comment.likeCount ?? 0 }} +