Files
real-e-party-iOS/YuMi/E-P/NewMoments/Services/EPMomentAPIHelper.m
edwinQQQ e8d59495a4 refactor: 重构 EPMomentViewController,替换 UITableView 为 EPMomentListView
主要变更:
1. 移除 UITableView,改为使用 EPMomentListView 以简化数据展示和交互。
2. 添加顶部固定文案 UILabel,提升用户体验。
3. 通过 EPMomentAPIHelper 统一管理 Moments 列表 API 请求,优化数据加载逻辑。
4. 更新 UI 约束,确保布局适配不同屏幕。

此重构旨在提升代码可维护性和用户界面的一致性。
2025-10-10 17:22:39 +08:00

59 lines
2.4 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// EPMomentAPIHelper.m
// YuMi
//
// Created by AI on 2025-10-10.
//
#import <UIKit/UIKit.h>
#import "EPMomentAPIHelper.h"
#import "Api+Moments.h"
#import "AccountInfoStorage.h"
#import "BaseModel.h"
@implementation EPMomentAPIHelper
- (void)fetchMomentsWithType:(EPMomentListSourceType)sourceType
page:(NSInteger)page
pageSize:(NSInteger)pageSize
completion:(void (^)(NSArray <MomentsInfoModel *>* _Nullable list, NSInteger code, NSString * _Nullable msg))completion {
// 兼容后端从 1 开始分页:若收到 0 则转成 1
NSInteger requestPage = page <= 0 ? 1 : page;
NSString *pageStr = [NSString stringWithFormat:@"%ld", (long)requestPage];
NSString *pageSizeStr = [NSString stringWithFormat:@"%ld", (long)pageSize];
NSString *types = @"0,2"; // 图片+文字
if (sourceType == EPMomentListSourceTypeRecommend) {
// [Api momentsRecommendList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
// if (code == 200 && data.data) {
// NSArray *array = [MomentsInfoModel modelsWithArray:data.data];
// if (completion) completion(array ?: @[], 200, @"success");
// } else {
// if (completion) completion(@[], code, msg);
// }
// } page:pageStr pageSize:pageSizeStr types:types];
[Api momentsLatestList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
MomentsListInfoModel *listInfo = [MomentsListInfoModel modelWithDictionary:data.data];
if (completion) completion(listInfo.dynamicList ?: @[], 200, @"success");
} fail:^(NSInteger code, NSString * _Nullable msg) {
if (completion) completion(@[], code, msg);
}] dynamicId:@"" pageSize:pageSizeStr types:types];
} else {
// 预留我的动态列表暂时复用推荐接口后续替换为真正的“我的动态”API
[Api momentsRecommendList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200 && data.data) {
NSArray *array = [MomentsInfoModel modelsWithArray:data.data];
if (completion) completion(array ?: @[], 200, @"success");
} else {
if (completion) completion(@[], code, msg);
}
} page:pageStr pageSize:pageSizeStr types:types];
}
}
@end