From 3eaa20c80393aa0a740bcfa15e43cedea35f9b02 Mon Sep 17 00:00:00 2001
From: lee-zt <2960166273@qq.com>
Date: Wed, 4 Jun 2025 10:39:34 +0800
Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=B8=96=E5=AD=90=E5=92=8C?=
=?UTF-8?q?=E8=AF=84=E8=AE=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../vue-frontend/src/components/PostPage.vue | 6 +-
.../vue-frontend/src/stores/postdetail.js | 60 +++++++++++++++++++
.../vue-frontend/src/views/PostDetail.vue | 45 ++++++++++++--
3 files changed, 103 insertions(+), 8 deletions(-)
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 @@