feat: 添加点赞功能支持及 Swift API Helper 集成

主要变更:
1. 在 EPMomentAPISwiftHelper 中新增点赞/取消点赞功能,支持动态 ID 和用户 UID。
2. 更新 EPMomentCell 以使用新的 Swift API Helper 进行点赞操作,简化点赞逻辑。
3. 优化点赞状态和数量的更新逻辑,确保用户界面及时反映点赞结果。

此更新旨在提升用户互动体验,简化点赞操作流程。
This commit is contained in:
edwinQQQ
2025-10-14 19:06:44 +08:00
parent f60a0eef14
commit 3a12a18687
2 changed files with 67 additions and 23 deletions

View File

@@ -74,5 +74,38 @@ import Foundation
} }
}, uid: uid, type: type, worldId: "", content: content, resList: resList) }, uid: uid, type: type, worldId: "", content: content, resList: resList)
} }
/// /
/// - Parameters:
/// - dynamicId: ID
/// - isLike: true=false=
/// - likedUid: UID
/// - worldId: ID
/// - completion:
/// - failure: (, )
@objc func likeMoment(
dynamicId: String,
isLike: Bool,
likedUid: String,
worldId: Int,
completion: @escaping () -> Void,
failure: @escaping (Int, String) -> Void
) {
guard let uid = AccountInfoStorage.instance().getUid() else {
failure(-1, "用户未登录")
return
}
let status = isLike ? "1" : "0"
let worldIdStr = String(format: "%ld", worldId)
Api.momentsLike({ (data, code, msg) in
if code == 200 {
completion()
} else {
failure(Int(code), msg ?? "点赞操作失败")
}
}, dynamicId: dynamicId, uid: uid, status: status, likedUid: likedUid, worldId: worldIdStr)
}
} }

View File

@@ -9,10 +9,10 @@
#import "EPMomentCell.h" #import "EPMomentCell.h"
#import "MomentsInfoModel.h" #import "MomentsInfoModel.h"
#import "AccountInfoStorage.h" #import "AccountInfoStorage.h"
#import "Api+Moments.h"
#import "NetImageView.h" #import "NetImageView.h"
#import "EPEmotionColorStorage.h" #import "EPEmotionColorStorage.h"
#import "SDPhotoBrowser.h" #import "SDPhotoBrowser.h"
#import "YuMi-Swift.h" // Swift
@interface EPMomentCell () <SDPhotoBrowserDelegate> @interface EPMomentCell () <SDPhotoBrowserDelegate>
@@ -51,6 +51,9 @@
/// ///
@property (nonatomic, strong) MomentsInfoModel *currentModel; @property (nonatomic, strong) MomentsInfoModel *currentModel;
/// API Helper (Swift )
@property (nonatomic, strong) EPMomentAPISwiftHelper *apiHelper;
@end @end
@implementation EPMomentCell @implementation EPMomentCell
@@ -307,14 +310,16 @@
- (void)performLikeAction:(BOOL)isLike { - (void)performLikeAction:(BOOL)isLike {
NSLog(@"[EPMomentCell] %@ 动态: %@", isLike ? @"点赞" : @"取消点赞", self.currentModel.dynamicId); NSLog(@"[EPMomentCell] %@ 动态: %@", isLike ? @"点赞" : @"取消点赞", self.currentModel.dynamicId);
NSString *uid = [[AccountInfoStorage instance] getUid];
NSString *dynamicId = self.currentModel.dynamicId; NSString *dynamicId = self.currentModel.dynamicId;
NSString *status = isLike ? @"1" : @"0"; // 0=1=
NSString *likedUid = self.currentModel.uid; NSString *likedUid = self.currentModel.uid;
NSString *worldId = [NSString stringWithFormat:@"%ld", self.currentModel.worldId]; long worldId = self.currentModel.worldId;
[Api momentsLike:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { // 使 Swift API Helper
if (code == 200) { [self.apiHelper likeMomentWithDynamicId:dynamicId
isLike:isLike
likedUid:likedUid
worldId:worldId
completion:^{
// //
self.currentModel.isLike = isLike; self.currentModel.isLike = isLike;
NSInteger likeCount = [self.currentModel.likeCount integerValue]; NSInteger likeCount = [self.currentModel.likeCount integerValue];
@@ -328,10 +333,9 @@
[self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateSelected]; [self.likeButton setTitle:[NSString stringWithFormat:@" %ld", (long)likeCount] forState:UIControlStateSelected];
NSLog(@"[EPMomentCell] %@ 成功", isLike ? @"点赞" : @"取消点赞"); NSLog(@"[EPMomentCell] %@ 成功", isLike ? @"点赞" : @"取消点赞");
} else { } failure:^(NSInteger code, NSString * _Nonnull msg) {
NSLog(@"[EPMomentCell] %@ 失败: %@", isLike ? @"点赞" : @"取消点赞", msg); NSLog(@"[EPMomentCell] %@ 失败 (code: %ld): %@", isLike ? @"点赞" : @"取消点赞", (long)code, msg);
} }];
} dynamicId:dynamicId uid:uid status:status likedUid:likedUid worldId:worldId];
} }
// //
@@ -481,4 +485,11 @@
return _imageViews; return _imageViews;
} }
- (EPMomentAPISwiftHelper *)apiHelper {
if (!_apiHelper) {
_apiHelper = [[EPMomentAPISwiftHelper alloc] init];
}
return _apiHelper;
}
@end @end