From c445c1ca5cb0b80e1cfce816da9bee55b53292f8 Mon Sep 17 00:00:00 2001 From: lee-zt <2960166273@qq.com> Date: Tue, 3 Jun 2025 17:41:12 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-local.yaml | 54 +++++--- .../vue-frontend/src/router/index.js | 2 +- .../vue-frontend/src/stores/postdetail.js | 125 +++++++++--------- .../vue-frontend/src/views/PostDetail.vue | 50 +++++-- 4 files changed, 141 insertions(+), 90 deletions(-) diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml index 7cae4ed..00a8f8c 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/resources/application-local.yaml @@ -1,21 +1,21 @@ ##本地开发环境 -lj: - db: - host: 192.168.59.129 - password: Forely123! - redis: - host: 192.168.59.129 - port: 6379 - password: Forely123! - rabbitmq: - host: 192.168.59.129 - port: 5672 - username: admin - password: Forely123! - minio: - endpoint: http://192.168.59.129:9000 - accessKey: forely - secretKey: Forely123! +#lj: +# db: +# host: 192.168.59.129 +# password: Forely123! +# redis: +# host: 192.168.59.129 +# port: 6379 +# password: Forely123! +# rabbitmq: +# host: 192.168.59.129 +# port: 5672 +# username: admin +# password: Forely123! +# minio: +# endpoint: http://192.168.59.129:9000 +# accessKey: forely +# secretKey: Forely123! #lj: # db: @@ -33,4 +33,22 @@ lj: # minio: # endpoint: http://192.168.125.128:9000 # accessKey: minio_admin -# secretKey: Minio@1234 \ No newline at end of file +# secretKey: Minio@1234 + +lj: + db: + host: localhost + password: 123456 + redis: + host: localhost + port: 6379 + password: 123456 + rabbitmq: + host: localhost + port: 5672 + username: guest + password: guest + minio: + endpoint: http://localhost:9005 + accessKey: leezt + secretKey: lzt264610 diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js index b036fd9..e65b5ba 100644 --- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js +++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/router/index.js @@ -34,7 +34,7 @@ const routes = [ component: PostDetail }, { - path: '/user', + path: '/user/:userId', name: 'UserPage', component: UserPage, meta: { requiresAuth: true } diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js index 49ed6c4..70b91e6 100644 --- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js +++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/stores/postdetail.js @@ -16,67 +16,67 @@ export const usePostDetailStore = defineStore("postDetail", { commentsFinished: false, // 是否加载完全部评论 }), actions: { - // ...existing code... -async fetchComments() { - if (this.commentsLoading || this.commentsFinished) return; - this.commentsLoading = true; - // 拼接参数到URL - const params = [ - `lastVal=${this.lastVal}`, - `offset=${this.offset}`, - `size=${this.size}`, - `postId=${this.post.postId}` - ].join('&'); - const url = `/comment/list?${params}`; - try { - const response = await request.get(url); - if (response.code === 200) { - // 初始化每条评论的子评论分页状态 - const comments = (response.data.records || []).map(item => ({ - ...item, - replies: [], - repliesLastVal: Date.now(), - repliesOffset: 0, - repliesSize: 5, - repliesLoading: false, - repliesFinished: false, - })); - this.comments.push(...comments); - this.lastVal = response.data.lastVal; - this.offset = response.data.offset; - if (comments.length < this.size) { - this.commentsFinished = true; // 如果评论数少于每页大小,标记为已加载完 + async fetchComments() { + if (this.commentsLoading || this.commentsFinished) return; + this.commentsLoading = true; + // 拼接参数到URL + const params = [ + `lastVal=${this.lastVal}`, + `offset=${this.offset}`, + `size=${this.size}`, + `postId=${this.post.postId}` + ].join('&'); + const url = `/comment/list?${params}`; + try { + const response = await request.get(url); + if (response.code === 200) { + // 初始化每条评论的子评论分页状态 + const comments = (response.data.records || []).map(item => ({ + ...item, + replies: [], + showReplies: false, // 是否显示子评论 + repliesLastVal: Date.now(), + repliesOffset: 0, + repliesSize: 5, + repliesLoading: false, + repliesFinished: false, + })); + this.comments.push(...comments); + this.lastVal = response.data.lastVal; + this.offset = response.data.offset; + if (comments.length < this.size) { + this.commentsFinished = true; // 如果评论数少于每页大小,标记为已加载完 + } + } + else { + ElMessage({ + message: '获取评论失败,请稍后重试', + type: 'error', + duration: 500 + }); + } + } catch (error) { + console.error("获取评论失败:", error); + alert(error.response?.message || '获取评论失败,请稍后重试'); + }finally { + this.commentsLoading = false; } - } - else { - ElMessage({ - message: '获取评论失败,请稍后重试', - type: 'error', - duration: 500 - }); - } - } catch (error) { - console.error("获取评论失败:", error); - alert(error.response?.message || '获取评论失败,请稍后重试'); - }finally { - this.commentsLoading = false; - } -}, -// ...existing code... + }, // 获取某条评论的子评论 async fetchReplies(parentCommentId, commentObj) { if (commentObj.repliesLoading || commentObj.repliesFinished) return; commentObj.repliesLoading = true; - // 请求子评论数据 - const RequestReplyData = { - lastVal: commentObj.repliesLastVal, - offset: commentObj.repliesOffset, - size: commentObj.repliesSize, - postId: this.post?.postId, - parentCommentId: parentCommentId, - }; + /// 拼接参数到URL + const params = [ + `lastVal=${commentObj.repliesLastVal}`, + `offset=${commentObj.repliesOffset}`, + `size=${commentObj.repliesSize}`, + `postId=${this.post?.postId}`, + `parentCommentId=${parentCommentId}` + ].join('&'); + const url = `/comment/list/reply?${params}`; try { - const res = await request.post('/comment/list/reply', RequestReplyData); + const res = await request.get(url); if (res.code === 200) { const records = (res.data.records || []).map(item => ({ ...item, @@ -169,15 +169,17 @@ async fetchComments() { async sendComment(newCommentData) { if (!newCommentData.content || !this.post?.postId) return; const RequestData = { + id:null, postId: newCommentData.postId, // 帖子ID content: newCommentData.content, // 评论内容 parentCommentId: newCommentData.parentCommentId, }; try { const res = await request.post('/comment', RequestData); + console.log("发送评论返回:", res.data); if (res.code === 200) { const commentObj = { - id: res.data.id, + id: res.data, content: newCommentData.content, userId: newCommentData.userId, userName: newCommentData.userName, @@ -191,6 +193,7 @@ async fetchComments() { topId: newCommentData.topId, isLike: 0, }; + console.log("发送评论数据:", commentObj.id); // 新增评论后刷新评论列表或插入到对应位置 if (!newCommentData.parentCommentId) { // 一级评论,插入到最前面 @@ -201,17 +204,17 @@ async fetchComments() { commentObj.repliesSize = 5; commentObj.repliesLoading = false; commentObj.repliesFinished = false; - this.comments.unshift(commentObj); - this.post.commentCount = (this.post.commentCount || 0) + 1; // 更新帖子评论数 + this.comments.unshift(commentObj); } else { // 回复,只插入到一级评论的 replies - let parent = this.comments.find(c => c.id === newCommentData.parentCommentId); + let parent = this.comments.find(c => c.id === newCommentData.topId); if (parent) { - parent.replies.unshift(commentObj); + parent.replies.push(commentObj); parent.replyCount = (parent.replyCount || 0) + 1; } } - console.log("评论成功:", res); + this.post.commentCount = (this.post.commentCount || 0) + 1; // 更新帖子评论数 + console.log("评论成功:", commentObj); }else { console.error("评论失败:", res); ElMessage.error(res.message || '评论失败'); diff --git a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue index 7901987..adfba83 100644 --- a/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue +++ b/珞珈岛-项目相关文件/luojia-island/vue-frontend/src/views/PostDetail.vue @@ -2,7 +2,13 @@
- 头像 + 头像

{{ author.userName || '匿名用户' }}

粉丝数:{{ author.followers ?? 0 }}

@@ -18,7 +24,7 @@

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

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

- 热度 {{ postDetailStore.post?.likeCount ?? 0 }} + 浏览量 {{ postDetailStore.post?.likeCount ?? 0 }} 点赞 {{ postDetailStore.post?.favoriteCount ?? 0 }} 评论 {{ postDetailStore.post?.commentCount ?? 0 }}
@@ -32,7 +38,13 @@

评论

  • - 评论者头像 + 评论者头像

    {{ comment.userName || '匿名用户' }}

    {{ comment.content || '' }}

    @@ -41,15 +53,21 @@ 赞 {{ comment.likeCount ?? 0 }}
    -
      +
      • - 评论者头像 + 评论者头像

        {{ reply.userName || '匿名用户' }} @@ -89,10 +107,11 @@