From f60a0eef142f329eb544ebe90d037666c44230a2 Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Tue, 14 Oct 2025 19:01:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20EPMomentCell=20?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E5=9B=BE=E7=89=87=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=92=8C=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要变更: 1. 引入 SDPhotoBrowser 类,支持点击图片查看大图功能。 2. 更新点赞逻辑,优化点赞状态和数量的显示,移除评论功能。 3. 调整 UI 组件约束,确保点赞按钮的显示效果。 4. 增加图片点击手势识别,提升用户交互体验。 此更新旨在增强动态展示的互动性,简化用户操作流程。 --- YuMi/E-P/NewMoments/Views/EPMomentCell.h | 1 + YuMi/E-P/NewMoments/Views/EPMomentCell.m | 129 ++++++++++++------ YuMi/Modules/YMMonents/Api/Api+Moments.m | 3 +- .../YMMonents/Model/MomentsInfoModel.h | 2 + 4 files changed, 93 insertions(+), 42 deletions(-) diff --git a/YuMi/E-P/NewMoments/Views/EPMomentCell.h b/YuMi/E-P/NewMoments/Views/EPMomentCell.h index 9f43603..4fac4bb 100644 --- a/YuMi/E-P/NewMoments/Views/EPMomentCell.h +++ b/YuMi/E-P/NewMoments/Views/EPMomentCell.h @@ -9,6 +9,7 @@ #import @class MomentsInfoModel; +@class SDPhotoBrowser; NS_ASSUME_NONNULL_BEGIN diff --git a/YuMi/E-P/NewMoments/Views/EPMomentCell.m b/YuMi/E-P/NewMoments/Views/EPMomentCell.m index eb836b4..4c811be 100644 --- a/YuMi/E-P/NewMoments/Views/EPMomentCell.m +++ b/YuMi/E-P/NewMoments/Views/EPMomentCell.m @@ -12,8 +12,9 @@ #import "Api+Moments.h" #import "NetImageView.h" #import "EPEmotionColorStorage.h" +#import "SDPhotoBrowser.h" -@interface EPMomentCell () +@interface EPMomentCell () // MARK: - UI Components @@ -125,23 +126,13 @@ make.bottom.equalTo(self.cardView).offset(-8).priority(UILayoutPriorityDefaultHigh); }]; - // 点赞按钮 + // 点赞按钮(居左显示,评论功能已隐藏) [self.actionBar addSubview:self.likeButton]; [self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.actionBar).offset(15); make.centerY.equalTo(self.actionBar); - make.width.mas_greaterThanOrEqualTo(60); + make.width.mas_greaterThanOrEqualTo(80); }]; - - // 评论按钮 - [self.actionBar addSubview:self.commentButton]; - [self.commentButton mas_makeConstraints:^(MASConstraintMaker *make) { - make.centerX.equalTo(self.actionBar); - make.centerY.equalTo(self.actionBar); - make.width.mas_greaterThanOrEqualTo(60); - }]; - - // 右侧占位(去掉分享按钮后,右边保持留白) } // MARK: - Public Methods @@ -161,11 +152,11 @@ // 配置图片九宫格 [self renderImages:model.dynamicResList]; - // 配置点赞/评论数(安全整型,避免负数和溢出) + // 配置点赞按钮状态和数字 NSInteger likeCnt = MAX(0, model.likeCount.integerValue); - NSInteger cmtCnt = MAX(0, model.commentCount.integerValue); - [self.likeButton setTitle:[NSString stringWithFormat:@"👍 %ld", (long)likeCnt] forState:UIControlStateNormal]; - [self.commentButton setTitle:[NSString stringWithFormat:@"💬 %ld", (long)cmtCnt] forState:UIControlStateNormal]; + self.likeButton.selected = model.isLike; + [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCnt] forState:UIControlStateNormal]; + [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCnt] forState:UIControlStateSelected]; self.avatarImageView.imageUrl = model.avatar; @@ -234,6 +225,13 @@ iv.layer.cornerRadius = 6; iv.layer.masksToBounds = YES; iv.contentMode = UIViewContentModeScaleAspectFill; + iv.userInteractionEnabled = YES; + iv.tag = i; // 用于识别点击的图片索引 + + // 添加点击手势 + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onImageTapped:)]; + [iv addGestureRecognizer:tap]; + [self.imagesContainer addSubview:iv]; [self.imageViews addObject:iv]; NSInteger row = i / columns; @@ -289,40 +287,92 @@ - (void)onLikeButtonTapped { if (!self.currentModel) return; - NSLog(@"[NewMomentCell] 点赞动态: %@", self.currentModel.dynamicId); + // 如果已点赞,执行取消点赞 + if (self.currentModel.isLike) { + [self performLikeAction:NO]; + return; + } + + // 审核中的动态不可点赞 + if (self.currentModel.status == 0) { + NSLog(@"[EPMomentCell] 动态审核中,无法点赞"); + // TODO: 可选择显示提示 Toast + return; + } + + // 执行点赞 + [self performLikeAction:YES]; +} + +- (void)performLikeAction:(BOOL)isLike { + NSLog(@"[EPMomentCell] %@ 动态: %@", isLike ? @"点赞" : @"取消点赞", self.currentModel.dynamicId); NSString *uid = [[AccountInfoStorage instance] getUid]; NSString *dynamicId = self.currentModel.dynamicId; - NSString *status = self.currentModel.isLike ? @"0" : @"1"; // 0=取消,1=点赞 + NSString *status = isLike ? @"1" : @"0"; // 0=取消,1=点赞 NSString *likedUid = self.currentModel.uid; - NSString *worldId = self.currentModel.worldId > 0 ? @(self.currentModel.worldId).stringValue : @""; + NSString *worldId = [NSString stringWithFormat:@"%ld", self.currentModel.worldId]; [Api momentsLike:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if (code == 200) { // 更新点赞状态 - self.currentModel.isLike = !self.currentModel.isLike; + self.currentModel.isLike = isLike; NSInteger likeCount = [self.currentModel.likeCount integerValue]; - likeCount += self.currentModel.isLike ? 1 : -1; + likeCount += isLike ? 1 : -1; + likeCount = MAX(0, likeCount); // 防止负数 self.currentModel.likeCount = @(likeCount).stringValue; // 更新 UI - [self.likeButton setTitle:[NSString stringWithFormat:@"👍 %ld", (long)self.currentModel.likeCount] forState:UIControlStateNormal]; + self.likeButton.selected = self.currentModel.isLike; + [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateNormal]; + [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateSelected]; - NSLog(@"[NewMomentCell] 点赞成功"); + NSLog(@"[EPMomentCell] %@ 成功", isLike ? @"点赞" : @"取消点赞"); } else { - NSLog(@"[NewMomentCell] 点赞失败: %@", msg); + NSLog(@"[EPMomentCell] %@ 失败: %@", isLike ? @"点赞" : @"取消点赞", msg); } } dynamicId:dynamicId uid:uid status:status likedUid:likedUid worldId:worldId]; } -- (void)onCommentButtonTapped { - NSLog(@"[NewMomentCell] 评论"); - // TODO: 实现评论逻辑 +// 评论功能已隐藏 +// - (void)onCommentButtonTapped { +// NSLog(@"[EPMomentCell] 评论"); +// } + +- (void)onImageTapped:(UITapGestureRecognizer *)gesture { + if (!self.currentModel || !self.currentModel.dynamicResList.count) return; + + NSInteger index = gesture.view.tag; + NSLog(@"[EPMomentCell] 点击图片索引: %ld", (long)index); + + SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init]; + browser.sourceImagesContainerView = self.imagesContainer; + browser.delegate = self; + browser.imageCount = self.currentModel.dynamicResList.count; + browser.currentImageIndex = index; + [browser show]; } -- (void)onShareButtonTapped { - NSLog(@"[NewMomentCell] 分享"); - // TODO: 实现分享逻辑 +#pragma mark - SDPhotoBrowserDelegate + +- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index { + if (index >= 0 && index < self.currentModel.dynamicResList.count) { + id item = self.currentModel.dynamicResList[index]; + NSString *url = nil; + if ([item isKindOfClass:[NSDictionary class]]) { + url = [item valueForKey:@"resUrl"] ?: [item valueForKey:@"url"]; + } else if ([item respondsToSelector:@selector(resUrl)]) { + url = [item valueForKey:@"resUrl"]; + } + if (url) { + return [NSURL URLWithString:url]; + } + } + return nil; +} + +- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index { + return [UIImageConstant defaultBannerPlaceholder]; } // MARK: - Lazy Loading @@ -391,21 +441,20 @@ - (UIButton *)likeButton { if (!_likeButton) { - _likeButton = [self createActionButtonWithTitle:@"👍 0"]; + _likeButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_normal"] forState:UIControlStateNormal]; + [_likeButton setImage:[UIImage imageNamed:@"monents_info_like_count_select"] forState:UIControlStateSelected]; + [_likeButton setTitle:@" 0" forState:UIControlStateNormal]; + _likeButton.titleLabel.font = [UIFont systemFontOfSize:13]; + [_likeButton setTitleColor:[UIColor colorWithWhite:0.5 alpha:1.0] forState:UIControlStateNormal]; + [_likeButton setTitleColor:[UIColor colorWithWhite:0.5 alpha:1.0] forState:UIControlStateSelected]; [_likeButton addTarget:self action:@selector(onLikeButtonTapped) forControlEvents:UIControlEventTouchUpInside]; } return _likeButton; } +// 评论按钮已移除 - (UIButton *)commentButton { - if (!_commentButton) { - _commentButton = [self createActionButtonWithTitle:@"💬 0"]; - [_commentButton addTarget:self action:@selector(onCommentButtonTapped) forControlEvents:UIControlEventTouchUpInside]; - } - return _commentButton; -} - -- (UIButton *)shareButton { return nil; } diff --git a/YuMi/Modules/YMMonents/Api/Api+Moments.m b/YuMi/Modules/YMMonents/Api/Api+Moments.m index 4b1165c..2a1927c 100644 --- a/YuMi/Modules/YMMonents/Api/Api+Moments.m +++ b/YuMi/Modules/YMMonents/Api/Api+Moments.m @@ -91,8 +91,7 @@ /// @param likedUid 点赞人的uid /// @param worldId 世界的id + (void)momentsLike:(HttpRequestHelperCompletion)completion dynamicId:(NSString *)dynamicId uid:(NSString *)uid status:(NSString *)status likedUid:(NSString *)likedUid worldId:(NSString *)worldId { - NSString * fang = [NSString stringFromBase64String:@"ZHluYW1pYy9saWtl"];///dynamic/like - [self makeRequest:fang method:HttpRequestHelperMethodPOST completion:completion, __FUNCTION__, dynamicId, uid, status, likedUid, worldId, nil]; + [self makeRequest:@"dynamic/like" method:HttpRequestHelperMethodPOST completion:completion, __FUNCTION__, dynamicId, uid, status, likedUid, worldId, nil]; } /// 动态详情 diff --git a/YuMi/Modules/YMMonents/Model/MomentsInfoModel.h b/YuMi/Modules/YMMonents/Model/MomentsInfoModel.h index 3ee8f9b..c48ae3a 100644 --- a/YuMi/Modules/YMMonents/Model/MomentsInfoModel.h +++ b/YuMi/Modules/YMMonents/Model/MomentsInfoModel.h @@ -77,6 +77,8 @@ typedef NS_ENUM(NSInteger, MonentsContentType) { @property (nonatomic, copy) NSString *worldName; ///动态的id @property (nonatomic,copy) NSString *dynamicId; +///审核状态(0=审核中,1=通过,2=拒绝) +@property (nonatomic, assign) NSInteger status; ///情绪颜色(本地标注,Hex格式如 #FF0000) @property (nonatomic, copy) NSString *emotionColor; ///是否是折叠起来的