diff --git a/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/Contents.json b/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/Contents.json new file mode 100644 index 0000000..91aa35a --- /dev/null +++ b/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "comment_close_icon@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "comment_close_icon@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/comment_close_icon@2x.png b/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/comment_close_icon@2x.png new file mode 100644 index 0000000..8f88817 Binary files /dev/null and b/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/comment_close_icon@2x.png differ diff --git a/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/comment_close_icon@3x.png b/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/comment_close_icon@3x.png new file mode 100644 index 0000000..e2f03fe Binary files /dev/null and b/keyBoard/Assets.xcassets/AI/comment_close_icon.imageset/comment_close_icon@3x.png differ diff --git a/keyBoard/Class/AiTalk/V/KBAICommentView.m b/keyBoard/Class/AiTalk/V/KBAICommentView.m index 2e52175..8fc8128 100644 --- a/keyBoard/Class/AiTalk/V/KBAICommentView.m +++ b/keyBoard/Class/AiTalk/V/KBAICommentView.m @@ -99,7 +99,7 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.headerView).offset(-16); make.centerY.equalTo(self.headerView); - make.width.height.mas_equalTo(30); + make.width.height.mas_equalTo(25); }]; [self.inputView mas_makeConstraints:^(MASConstraintMaker *make) { @@ -274,11 +274,49 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; __weak typeof(self) weakSelf = self; cell.onLikeAction = ^{ - // TODO: 处理点赞逻辑 - reply.isLiked = !reply.isLiked; - reply.likeCount += reply.isLiked ? 1 : -1; - [weakSelf.tableView reloadRowsAtIndexPaths:@[ indexPath ] - withRowAnimation:UITableViewRowAnimationNone]; + __strong typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + + // 获取评论 ID(需要转换为 NSInteger) + NSInteger commentId = [reply.replyId integerValue]; + + // 调用点赞接口 + [strongSelf.aiVM likeCommentWithCommentId:commentId completion:^(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (error) { + NSLog(@"[KBAICommentView] 二级评论点赞失败:%@", error.localizedDescription); + // TODO: 显示错误提示 + return; + } + + if (response && response.code == 0) { + // data = true: 点赞成功,data = false: 取消点赞成功 + BOOL isNowLiked = response.data; + + // 更新模型状态 + if (isNowLiked) { + // 点赞成功:喜欢数+1 + reply.isLiked = YES; + reply.likeCount = MAX(0, reply.likeCount + 1); + NSLog(@"[KBAICommentView] 二级评论点赞成功,ID: %ld", (long)commentId); + } else { + // 取消点赞成功:喜欢数-1 + reply.isLiked = NO; + reply.likeCount = MAX(0, reply.likeCount - 1); + NSLog(@"[KBAICommentView] 二级评论取消点赞成功,ID: %ld", (long)commentId); + } + + // 刷新对应的行 + [strongSelf.tableView reloadRowsAtIndexPaths:@[ indexPath ] + withRowAnimation:UITableViewRowAnimationNone]; + } else { + NSLog(@"[KBAICommentView] 二级评论点赞失败:%@", response.message ?: @"未知错误"); + // TODO: 显示错误提示 + } + }); + }]; }; cell.onReplyAction = ^{ @@ -300,11 +338,49 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter"; __weak typeof(self) weakSelf = self; header.onLikeAction = ^{ - // TODO: 处理点赞逻辑 - comment.liked = !comment.liked; - comment.likeCount += comment.liked ? 1 : -1; - [weakSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] - withRowAnimation:UITableViewRowAnimationNone]; + __strong typeof(weakSelf) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + + // 获取评论 ID(需要转换为 NSInteger) + NSInteger commentId = [comment.commentId integerValue]; + + // 调用点赞接口 + [strongSelf.aiVM likeCommentWithCommentId:commentId completion:^(KBCommentLikeResponse * _Nullable response, NSError * _Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (error) { + NSLog(@"[KBAICommentView] 一级评论点赞失败:%@", error.localizedDescription); + // TODO: 显示错误提示 + return; + } + + if (response && response.code == 0) { + // data = true: 点赞成功,data = false: 取消点赞成功 + BOOL isNowLiked = response.data; + + // 更新模型状态 + if (isNowLiked) { + // 点赞成功:喜欢数+1 + comment.liked = YES; + comment.likeCount = MAX(0, comment.likeCount + 1); + NSLog(@"[KBAICommentView] 一级评论点赞成功,ID: %ld", (long)commentId); + } else { + // 取消点赞成功:喜欢数-1 + comment.liked = NO; + comment.likeCount = MAX(0, comment.likeCount - 1); + NSLog(@"[KBAICommentView] 一级评论取消点赞成功,ID: %ld", (long)commentId); + } + + // 刷新对应的 section + [strongSelf.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] + withRowAnimation:UITableViewRowAnimationNone]; + } else { + NSLog(@"[KBAICommentView] 一级评论点赞失败:%@", response.message ?: @"未知错误"); + // TODO: 显示错误提示 + } + }); + }]; }; header.onReplyAction = ^{ @@ -497,9 +573,8 @@ static NSInteger const kRepliesLoadCount = 5; - (UIButton *)closeButton { if (!_closeButton) { _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; - [_closeButton setImage:[UIImage systemImageNamed:@"xmark"] + [_closeButton setImage:[UIImage imageNamed:@"comment_close_icon"] forState:UIControlStateNormal]; - _closeButton.tintColor = [UIColor labelColor]; [_closeButton addTarget:self action:@selector(closeButtonTapped) forControlEvents:UIControlEventTouchUpInside];