|  |  |  | @ -59,7 +59,7 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |         this.commentsLoading = false; | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
		
			
				
					|  |  |  |  |     }, | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取某条评论的子评论(多级结构,分页)
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 获取某条评论的子评论
 | 
			
		
	
		
			
				
					|  |  |  |  |     async fetchReplies(parentCommentId, commentObj) { | 
			
		
	
		
			
				
					|  |  |  |  |       if (commentObj.repliesLoading || commentObj.repliesFinished) return; | 
			
		
	
		
			
				
					|  |  |  |  |       commentObj.repliesLoading = true; | 
			
		
	
	
		
			
				
					|  |  |  | @ -76,12 +76,7 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |         if (res.code === 200) { | 
			
		
	
		
			
				
					|  |  |  |  |           const records = (res.data.records || []).map(item => ({ | 
			
		
	
		
			
				
					|  |  |  |  |             ...item, | 
			
		
	
		
			
				
					|  |  |  |  |             replies: [], | 
			
		
	
		
			
				
					|  |  |  |  |             repliesLastVal: 0, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesOffset: 0, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesSize: 5, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesFinished: false, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesLoading: false, | 
			
		
	
		
			
				
					|  |  |  |  |             replyUserName: item.replyUserName,  | 
			
		
	
		
			
				
					|  |  |  |  |           })); | 
			
		
	
		
			
				
					|  |  |  |  |           commentObj.replies.push(...records); | 
			
		
	
		
			
				
					|  |  |  |  |           commentObj.repliesLastVal = res.data.lastVal; | 
			
		
	
	
		
			
				
					|  |  |  | @ -138,7 +133,7 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |             likeCount, | 
			
		
	
		
			
				
					|  |  |  |  |             favoriteCount, | 
			
		
	
		
			
				
					|  |  |  |  |             viewCount, | 
			
		
	
		
			
				
					|  |  |  |  |             author: { // 新增 author 字段
 | 
			
		
	
		
			
				
					|  |  |  |  |             author: {  | 
			
		
	
		
			
				
					|  |  |  |  |               userId, | 
			
		
	
		
			
				
					|  |  |  |  |               userName, | 
			
		
	
		
			
				
					|  |  |  |  |               userAvatar, | 
			
		
	
	
		
			
				
					|  |  |  | @ -173,7 +168,7 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |         id: null, | 
			
		
	
		
			
				
					|  |  |  |  |         postId: newCommentData.postId, // 帖子ID
 | 
			
		
	
		
			
				
					|  |  |  |  |         content: newCommentData.content, // 评论内容
 | 
			
		
	
		
			
				
					|  |  |  |  |         parentCommentId: newCommentData.parentCommentId, // 如果是一级评论则为0
 | 
			
		
	
		
			
				
					|  |  |  |  |         parentCommentId: newCommentData.parentCommentId,  | 
			
		
	
		
			
				
					|  |  |  |  |       }; | 
			
		
	
		
			
				
					|  |  |  |  |       try { | 
			
		
	
		
			
				
					|  |  |  |  |         const res = await request.post('/comment', RequestData); | 
			
		
	
	
		
			
				
					|  |  |  | @ -189,28 +184,25 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |             replyCount: 0, | 
			
		
	
		
			
				
					|  |  |  |  |             postId: this.post.postId, | 
			
		
	
		
			
				
					|  |  |  |  |             parentCommentId: newCommentData.parentCommentId, | 
			
		
	
		
			
				
					|  |  |  |  |             replyUserName: newCommentData.replyUserName, | 
			
		
	
		
			
				
					|  |  |  |  |             topId: newCommentData.topId, | 
			
		
	
		
			
				
					|  |  |  |  |             isLike: 0, | 
			
		
	
		
			
				
					|  |  |  |  |             replies: [], | 
			
		
	
		
			
				
					|  |  |  |  |             repliesLastVal: 0, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesOffset: 0, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesSize: 5, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesFinished: false, | 
			
		
	
		
			
				
					|  |  |  |  |             repliesLoading: false, | 
			
		
	
		
			
				
					|  |  |  |  |           }; | 
			
		
	
		
			
				
					|  |  |  |  |           // 新增评论后刷新评论列表或插入到对应位置
 | 
			
		
	
		
			
				
					|  |  |  |  |           if (!newCommentData.parentCommentId) { | 
			
		
	
		
			
				
					|  |  |  |  |             // 一级评论,插入到最前面
 | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.topId = commentObj.id; // 一级评论的顶级ID就是自己的ID
 | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.replies = []; | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.repliesLastVal = Date.now(); | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.repliesOffset = 0; | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.repliesSize = 5; | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.repliesLoading = false; | 
			
		
	
		
			
				
					|  |  |  |  |             commentObj.repliesFinished = false; | 
			
		
	
		
			
				
					|  |  |  |  |             this.comments.unshift(commentObj); | 
			
		
	
		
			
				
					|  |  |  |  |             this.post.commentCount = (this.post.commentCount || 0) + 1; // 更新帖子评论数
 | 
			
		
	
		
			
				
					|  |  |  |  |           } else { | 
			
		
	
		
			
				
					|  |  |  |  |             // 回复评论,插入到对应父评论的 replies
 | 
			
		
	
		
			
				
					|  |  |  |  |             // 先找顶级父评论
 | 
			
		
	
		
			
				
					|  |  |  |  |             let parent = this.comments.find(c => c.id === commentObj.parentCommentId || c.id === commentObj.topId); | 
			
		
	
		
			
				
					|  |  |  |  |             // 如果是二级及以上回复,需递归查找
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (!parent && commentObj.topId) { | 
			
		
	
		
			
				
					|  |  |  |  |               parent = this.comments.find(c => c.id === commentObj.topId); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             // 回复,只插入到一级评论的 replies
 | 
			
		
	
		
			
				
					|  |  |  |  |             let parent = this.comments.find(c => c.id === newCommentData.parentCommentId); | 
			
		
	
		
			
				
					|  |  |  |  |             if (parent) { | 
			
		
	
		
			
				
					|  |  |  |  |               parent.replies.unshift(commentObj); | 
			
		
	
		
			
				
					|  |  |  |  |               parent.replyCount = (parent.replyCount || 0) + 1; | 
			
		
	
	
		
			
				
					|  |  |  | 
 |