This commit is contained in:
2025-12-03 18:49:18 +08:00
parent 6f02bc7cf5
commit 82123fc232
3 changed files with 98 additions and 41 deletions

View File

@@ -8,30 +8,30 @@
NS_ASSUME_NONNULL_BEGIN
/// 排行榜角色/角色卡片模型
/// 对应后端返回字段:
/// 对应后端返回字段示例
/// {
/// "id": 0,
/// "title": "",
/// "characterBackground": "",
/// "avatarUrl": "",
/// "download": "",
/// "tag": 0,
/// "rank": 0
/// "id" : 29,
/// "download" : "0x4AQSfQS0",
/// "characterName" : "Ms.",
/// "avatarUrl" : "https://...",
/// "tag" : 490,
/// "characterBackground" : "d2EWHe1ST5",
/// "rank" : 899
/// }
@interface KBCharacter : NSObject
/// 唯一标识,对应后端的 id
@property (nonatomic, copy, nullable) NSString *characterId;
/// 标题/名称
@property (nonatomic, copy, nullable) NSString *title;
/// 角色背景(颜色值、图片地址或后端定义的 key
@property (nonatomic, copy, nullable) NSString *characterBackground;
/// 名称,对应后端的 characterName
@property (nonatomic, copy, nullable) NSString *characterName;
/// 头像地址
@property (nonatomic, copy, nullable) NSString *avatarUrl;
/// 角色背景(颜色值、图片地址或后端定义的 key
@property (nonatomic, copy, nullable) NSString *characterBackground;
/// 下载量文案或数值(后端返回字符串)
@property (nonatomic, copy, nullable) NSString *download;
@@ -47,4 +47,3 @@ NS_ASSUME_NONNULL_BEGIN
@end
NS_ASSUME_NONNULL_END

View File

@@ -8,11 +8,13 @@
@implementation KBCharacter
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
// id -> characterId
//
return @{
@"characterId": @"id"
// id -> characterId
@"characterId": @"id",
// characterName title
@"characterName": @[@"characterName", @"title"],
};
}
@end

View File

@@ -8,18 +8,26 @@
#import "HomeHotVC.h"
//
#import "KBTopThreeView.h"
#import "KBHomeVM.h"
#import "KBCharacter.h"
#import "HomeHotCell.h"
#import "HomeRankVC.h"
#import "KBSearchVC.h"
#import "HomeRankDetailPopView.h"
#import "LSTPopView.h"
#import <HWPanModal/HWPanModal.h>
@interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate>
//
@property (nonatomic, strong) KBTopThreeView *topThreeView;
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource; //
/// VM
@property (nonatomic, strong) KBHomeVM *homeVM;
///
@property (nonatomic, copy) NSArray<KBCharacter *> *allCharacters;
/// 使 4
@property (nonatomic, copy) NSArray<KBCharacter *> *listCharacters;
@end
@@ -31,13 +39,6 @@
- (void)viewDidLoad {
[super viewDidLoad];
//
self.dataSource = @[
@{@"rank":@4, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@5, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@YES},
@{@"rank":@6, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO},
@{@"rank":@7, @"title":@"Ambiguous", @"sub":@"Be Neither Too Close Nor Too Distant, Want To ...", @"joined":@NO}
];
// UI
[self.view addSubview:self.tableView];
@@ -48,29 +49,84 @@
// tableHeaderViewtableHeaderView
CGFloat headerH = 280.0;
self.topThreeView = [[KBTopThreeView alloc] initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, headerH)];
//
[self.topThreeView configWithItems:@[
@{@"title":@"High EQ", @"rank":@1},
@{@"title":@"Flirt Girls", @"rank":@2},
@{@"title":@"Humorous", @"rank":@3}
]];
self.tableView.tableHeaderView = self.topThreeView;
//
self.homeVM = [KBHomeVM new];
KBWeakSelf
[self.homeVM fetchRankListWithParams:nil
needShow:YES
completion:^(NSArray<KBCharacter *> * _Nullable list, NSError * _Nullable error) {
if (error) {
// VM HUD
return;
}
weakSelf.allCharacters = list ?: @[];
//
NSMutableArray *topItems = [NSMutableArray array];
NSInteger topCount = MIN(3, weakSelf.allCharacters.count);
for (NSInteger i = 0; i < topCount; i++) {
KBCharacter *c = weakSelf.allCharacters[i];
NSInteger rank = (c.rank > 0) ? c.rank : (i + 1);
NSString *title = c.characterName ?: @"";
[topItems addObject:@{ @"title": title, @"rank": @(rank) }];
}
if (topItems.count > 0) {
[weakSelf.topThreeView configWithItems:topItems];
}
// 4
if (weakSelf.allCharacters.count > 3) {
NSRange range = NSMakeRange(3, weakSelf.allCharacters.count - 3);
weakSelf.listCharacters = [weakSelf.allCharacters subarrayWithRange:range];
} else {
weakSelf.listCharacters = @[];
}
[weakSelf.tableView reloadData];
// HomeHotVC PanModal
// 1) HomeHotVC VC HomeSheetVC
// VC hw_panModalSetNeedsLayoutUpdate
UIViewController *parent = weakSelf.parentViewController;
id target = nil;
if ([parent respondsToSelector:@selector(hw_panModalSetNeedsLayoutUpdate)]) {
target = parent;
} else {
// 2) HomeHotVC HWPanModalContentView KBPanModalView
// parentViewController nil view.superview
UIView *v = weakSelf.view;
while (v && ![v respondsToSelector:@selector(hw_panModalSetNeedsLayoutUpdate)]) {
v = v.superview;
}
if (v && [v respondsToSelector:@selector(hw_panModalSetNeedsLayoutUpdate)]) {
target = v;
}
}
if (target) {
[(id)target hw_panModalSetNeedsLayoutUpdate];
}
}];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
return self.listCharacters.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath:indexPath];
NSDictionary *item = self.dataSource[indexPath.row];
KBCharacter *item = self.listCharacters[indexPath.row];
NSInteger rank = (item.rank > 0) ? item.rank : (indexPath.row + 4); // rank 4
NSString *title = item.characterName ?: @"";
NSString *sub = item.download ?: @""; // download
BOOL joined = item.added;
// cell
[cell configWithRank:[item[@"rank"] integerValue]
title:item[@"title"]
subtitle:item[@"sub"]
joined:[item[@"joined"] boolValue]];
[cell configWithRank:rank
title:title
subtitle:sub
joined:joined];
return cell;
}
@@ -87,15 +143,15 @@
// UINavigationController *nav = KB_CURRENT_NAV;
// [nav pushViewController:vc animated:true];
NSLog(@"===");
// ->
NSDictionary *d = self.dataSource[indexPath.item];
KBCharacter *c = self.listCharacters[indexPath.row];
//
CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420);
HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)];
NSString *title = d[@"title"] ?: @"High EQ";
NSString *people = d[@"people"] ?: @"Download: 1 Million";
NSString *title = c.characterName ?: @"High EQ";
NSString *people = c.download ?: @"Download: 1 Million";
NSString *desc = @"Be Neither Too Close\nNor Too Distant"; //
[content configWithAvatar:nil title:title download:people desc:desc];