|  |  |  | @ -16,49 +16,53 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |     commentsFinished: false, // 是否加载完全部评论
 | 
			
		
	
		
			
				
					|  |  |  |  |   }), | 
			
		
	
		
			
				
					|  |  |  |  |   actions: { | 
			
		
	
		
			
				
					|  |  |  |  |     async fetchComments() { | 
			
		
	
		
			
				
					|  |  |  |  |       if (this.commentsLoading || this.commentsFinished) return; | 
			
		
	
		
			
				
					|  |  |  |  |       this.commentsLoading = true; | 
			
		
	
		
			
				
					|  |  |  |  |       const RequestCommentData = { | 
			
		
	
		
			
				
					|  |  |  |  |         lastVal: this.lastVal, | 
			
		
	
		
			
				
					|  |  |  |  |         offset: this.offset, | 
			
		
	
		
			
				
					|  |  |  |  |         size: this.size, | 
			
		
	
		
			
				
					|  |  |  |  |         postId: this.post.postId | 
			
		
	
		
			
				
					|  |  |  |  |       }; | 
			
		
	
		
			
				
					|  |  |  |  |       try { | 
			
		
	
		
			
				
					|  |  |  |  |         const response = await request.post('/comment/list', RequestCommentData); | 
			
		
	
		
			
				
					|  |  |  |  |         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; // 如果评论数少于每页大小,标记为已加载完
 | 
			
		
	
		
			
				
					|  |  |  |  |           } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         else { | 
			
		
	
		
			
				
					|  |  |  |  |           ElMessage({ | 
			
		
	
		
			
				
					|  |  |  |  |             message: '获取评论失败,请稍后重试', | 
			
		
	
		
			
				
					|  |  |  |  |             type: 'error', | 
			
		
	
		
			
				
					|  |  |  |  |             duration: 500 | 
			
		
	
		
			
				
					|  |  |  |  |           }); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |       } catch (error) { | 
			
		
	
		
			
				
					|  |  |  |  |         console.error("获取评论失败:", error); | 
			
		
	
		
			
				
					|  |  |  |  |         alert(error.response?.message || '获取评论失败,请稍后重试'); | 
			
		
	
		
			
				
					|  |  |  |  |       }finally { | 
			
		
	
		
			
				
					|  |  |  |  |         this.commentsLoading = false; | 
			
		
	
		
			
				
					|  |  |  |  |    // ...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; // 如果评论数少于每页大小,标记为已加载完
 | 
			
		
	
		
			
				
					|  |  |  |  |       } | 
			
		
	
		
			
				
					|  |  |  |  |     }, | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     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; | 
			
		
	
	
		
			
				
					|  |  |  | @ -165,7 +169,6 @@ export const usePostDetailStore = defineStore("postDetail", { | 
			
		
	
		
			
				
					|  |  |  |  |     async sendComment(newCommentData) { | 
			
		
	
		
			
				
					|  |  |  |  |       if (!newCommentData.content || !this.post?.postId) return; | 
			
		
	
		
			
				
					|  |  |  |  |       const RequestData = { | 
			
		
	
		
			
				
					|  |  |  |  |         id: null, | 
			
		
	
		
			
				
					|  |  |  |  |         postId: newCommentData.postId, // 帖子ID
 | 
			
		
	
		
			
				
					|  |  |  |  |         content: newCommentData.content, // 评论内容
 | 
			
		
	
		
			
				
					|  |  |  |  |         parentCommentId: newCommentData.parentCommentId,  | 
			
		
	
	
		
			
				
					|  |  |  | 
 |