diff --git a/keyBoard/Class/AiTalk/M/KBAICommentModel.h b/keyBoard/Class/AiTalk/M/KBAICommentModel.h index 5b9ed5e..c87c24e 100644 --- a/keyBoard/Class/AiTalk/M/KBAICommentModel.h +++ b/keyBoard/Class/AiTalk/M/KBAICommentModel.h @@ -15,7 +15,8 @@ NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSInteger, KBAIReplyFooterState) { KBAIReplyFooterStateHidden, // 无二级评论,不显示 KBAIReplyFooterStateExpand, // 显示"展开x条回复"(折叠状态) - KBAIReplyFooterStateCollapse // 显示"收起"(展开状态) + KBAIReplyFooterStateLoadMore, // 显示"展开更多回复"(部分展开) + KBAIReplyFooterStateCollapse // 显示"收起"(全部展开) }; /// 一级评论模型 @@ -75,8 +76,9 @@ typedef NS_ENUM(NSInteger, KBAIReplyFooterState) { /// 获取当前 Footer 状态 - (KBAIReplyFooterState)footerState; -/// 展开全部回复 -- (void)expandAllReplies; +/// 加载更多回复(每次加载指定数量) +/// @param count 本次加载的数量 +- (void)loadMoreReplies:(NSInteger)count; /// 收起所有回复 - (void)collapseReplies; diff --git a/keyBoard/Class/AiTalk/M/KBAICommentModel.m b/keyBoard/Class/AiTalk/M/KBAICommentModel.m index 5346cc1..ff61e20 100644 --- a/keyBoard/Class/AiTalk/M/KBAICommentModel.m +++ b/keyBoard/Class/AiTalk/M/KBAICommentModel.m @@ -64,19 +64,29 @@ return KBAIReplyFooterStateHidden; } - // 已展开 - if (self.isRepliesExpanded) { - return KBAIReplyFooterStateCollapse; + // 未展开(初始状态) + if (!self.isRepliesExpanded) { + return KBAIReplyFooterStateExpand; } - // 未展开 - return KBAIReplyFooterStateExpand; + // 已展开但还有更多 + if (self.displayedReplies.count < self.totalReplyCount) { + return KBAIReplyFooterStateLoadMore; + } + + // 全部展开 + return KBAIReplyFooterStateCollapse; } -- (void)expandAllReplies { +- (void)loadMoreReplies:(NSInteger)count { self.isRepliesExpanded = YES; - [self.displayedReplies removeAllObjects]; - [self.displayedReplies addObjectsFromArray:self.replies]; + + NSInteger currentCount = self.displayedReplies.count; + NSInteger endIndex = MIN(currentCount + count, self.replies.count); + + for (NSInteger i = currentCount; i < endIndex; i++) { + [self.displayedReplies addObject:self.replies[i]]; + } } - (void)collapseReplies { diff --git a/keyBoard/Class/AiTalk/M/comments_mock.json b/keyBoard/Class/AiTalk/M/comments_mock.json index 1c73f6e..e3e0051 100644 --- a/keyBoard/Class/AiTalk/M/comments_mock.json +++ b/keyBoard/Class/AiTalk/M/comments_mock.json @@ -15,7 +15,10 @@ {"id": "reply_001_2", "userId": "user_103", "userName": "程序员小李", "avatarUrl": "https://picsum.photos/100/100?random=3", "content": "感谢支持,会继续努力的!", "replyToUserName": "科技达人", "likeCount": 23, "isLiked": true, "createTime": 1737018000}, {"id": "reply_001_3", "userId": "user_104", "userName": "产品经理", "avatarUrl": "https://picsum.photos/100/100?random=4", "content": "下个版本会有更多惊喜", "likeCount": 12, "isLiked": false, "createTime": 1737021600}, {"id": "reply_001_4", "userId": "user_105", "userName": "UI设计师", "avatarUrl": "https://picsum.photos/100/100?random=5", "content": "细节决定品质", "likeCount": 8, "isLiked": false, "createTime": 1737025200}, - {"id": "reply_001_5", "userId": "user_106", "userName": "测试工程师", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 5, "isLiked": false, "createTime": 1737028800} + {"id": "reply_001_5", "userId": "user_106", "userName": "测试工程师", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 5, "isLiked": false, "createTime": 1737028800}, + {"id": "reply_001_6", "userId": "user_106", "userName": "测试工程师2", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 51, "isLiked": false, "createTime": 1737028800}, + {"id": "reply_001_7", "userId": "user_106", "userName": "测试工程师3", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 52, "isLiked": false, "createTime": 1737028800}, + {"id": "reply_001_8", "userId": "user_106", "userName": "测试工程师4", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 53, "isLiked": false, "createTime": 1737028800} ] }, { @@ -43,8 +46,15 @@ "isLiked": false, "createTime": 1736751600, "replies": [ - {"id": "reply_004_1", "userId": "user_402", "userName": "新用户", "avatarUrl": "https://picsum.photos/100/100?random=14", "content": "真的吗?那我也要试试", "likeCount": 18, "isLiked": false, "createTime": 1736755200} - ] + {"id": "reply_004_1", "userId": "user_102", "userName": "科技达人", "avatarUrl": "https://picsum.photos/100/100?random=2", "content": "同意!这个设计真的很用心", "likeCount": 45, "isLiked": false, "createTime": 1737014400}, + {"id": "reply_004_2", "userId": "user_103", "userName": "程序员小李", "avatarUrl": "https://picsum.photos/100/100?random=3", "content": "感谢支持,会继续努力的!", "replyToUserName": "科技达人", "likeCount": 23, "isLiked": true, "createTime": 1737018000}, + {"id": "reply_004_3", "userId": "user_104", "userName": "产品经理", "avatarUrl": "https://picsum.photos/100/100?random=4", "content": "下个版本会有更多惊喜", "likeCount": 12, "isLiked": false, "createTime": 1737021600}, + {"id": "reply_004_4", "userId": "user_105", "userName": "UI设计师", "avatarUrl": "https://picsum.photos/100/100?random=5", "content": "细节决定品质", "likeCount": 8, "isLiked": false, "createTime": 1737025200}, + {"id": "reply_004_5", "userId": "user_106", "userName": "测试工程师", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 5, "isLiked": false, "createTime": 1737028800}, + {"id": "reply_004_6", "userId": "user_106", "userName": "测试工程师2", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 51, "isLiked": false, "createTime": 1737028800}, + {"id": "reply_004_7", "userId": "user_106", "userName": "测试工程师3", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 52, "isLiked": false, "createTime": 1737028800}, + {"id": "reply_004_8", "userId": "user_106", "userName": "测试工程师4", "avatarUrl": "https://picsum.photos/100/100?random=6", "content": "已经测试通过了,稳定性很好", "likeCount": 53, "isLiked": false, "createTime": 1737028800} + ] }, { "id": "comment_005", diff --git a/keyBoard/Class/AiTalk/V/KBAICommentFooterView.m b/keyBoard/Class/AiTalk/V/KBAICommentFooterView.m index 08872ac..4cffbab 100644 --- a/keyBoard/Class/AiTalk/V/KBAICommentFooterView.m +++ b/keyBoard/Class/AiTalk/V/KBAICommentFooterView.m @@ -67,6 +67,14 @@ forState:UIControlStateNormal]; break; } + case KBAIReplyFooterStateLoadMore: { + self.actionButton.hidden = NO; + NSInteger remaining = comment.totalReplyCount - comment.displayedReplies.count; + title = [NSString stringWithFormat:@"展开更多回复(%ld条)", (long)remaining]; + [self.actionButton setImage:[UIImage systemImageNamed:@"chevron.down"] + forState:UIControlStateNormal]; + break; + } case KBAIReplyFooterStateCollapse: { self.actionButton.hidden = NO; title = @"收起"; diff --git a/keyBoard/Class/AiTalk/V/KBAICommentView.m b/keyBoard/Class/AiTalk/V/KBAICommentView.m index 6acdf67..827b7b9 100644 --- a/keyBoard/Class/AiTalk/V/KBAICommentView.m +++ b/keyBoard/Class/AiTalk/V/KBAICommentView.m @@ -319,13 +319,17 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; #pragma mark - Footer Actions +/// 每次加载的回复数量 +static NSInteger const kRepliesLoadCount = 5; + - (void)handleFooterActionForSection:(NSInteger)section { KBAICommentModel *comment = self.comments[section]; KBAIReplyFooterState state = [comment footerState]; switch (state) { - case KBAIReplyFooterStateExpand: { - [self expandRepliesForSection:section]; + case KBAIReplyFooterStateExpand: + case KBAIReplyFooterStateLoadMore: { + [self loadMoreRepliesForSection:section]; break; } case KBAIReplyFooterStateCollapse: { @@ -337,15 +341,17 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; } } -- (void)expandRepliesForSection:(NSInteger)section { +- (void)loadMoreRepliesForSection:(NSInteger)section { KBAICommentModel *comment = self.comments[section]; + NSInteger currentCount = comment.displayedReplies.count; - // 一次性展开全部回复 - [comment expandAllReplies]; + // 加载更多回复 + [comment loadMoreReplies:kRepliesLoadCount]; - // 计算要插入的行 + // 计算新增的行 + NSInteger newCount = comment.displayedReplies.count; NSMutableArray *insertIndexPaths = [NSMutableArray array]; - for (NSInteger i = 0; i < comment.displayedReplies.count; i++) { + for (NSInteger i = currentCount; i < newCount; i++) { [insertIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]]; }