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

View File

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

View File

@@ -8,18 +8,26 @@
#import "HomeHotVC.h" #import "HomeHotVC.h"
// //
#import "KBTopThreeView.h" #import "KBTopThreeView.h"
#import "KBHomeVM.h"
#import "KBCharacter.h"
#import "HomeHotCell.h" #import "HomeHotCell.h"
#import "HomeRankVC.h" #import "HomeRankVC.h"
#import "KBSearchVC.h" #import "KBSearchVC.h"
#import "HomeRankDetailPopView.h" #import "HomeRankDetailPopView.h"
#import "LSTPopView.h" #import "LSTPopView.h"
#import <HWPanModal/HWPanModal.h> #import <HWPanModal/HWPanModal.h>
@interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate> @interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate>
// //
@property (nonatomic, strong) KBTopThreeView *topThreeView; @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 @end
@@ -31,13 +39,6 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super 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 // UI
[self.view addSubview:self.tableView]; [self.view addSubview:self.tableView];
@@ -48,29 +49,84 @@
// tableHeaderViewtableHeaderView // tableHeaderViewtableHeaderView
CGFloat headerH = 280.0; CGFloat headerH = 280.0;
self.topThreeView = [[KBTopThreeView alloc] initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, headerH)]; 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.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 #pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count; return self.listCharacters.count;
} }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath: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
[cell configWithRank:[item[@"rank"] integerValue] [cell configWithRank:rank
title:item[@"title"] title:title
subtitle:item[@"sub"] subtitle:sub
joined:[item[@"joined"] boolValue]]; joined:joined];
return cell; return cell;
} }
@@ -89,13 +145,13 @@
NSLog(@"==="); NSLog(@"===");
// -> // ->
NSDictionary *d = self.dataSource[indexPath.item]; KBCharacter *c = self.listCharacters[indexPath.row];
// //
CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420); CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420);
HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)]; HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)];
NSString *title = d[@"title"] ?: @"High EQ"; NSString *title = c.characterName ?: @"High EQ";
NSString *people = d[@"people"] ?: @"Download: 1 Million"; NSString *people = c.download ?: @"Download: 1 Million";
NSString *desc = @"Be Neither Too Close\nNor Too Distant"; // NSString *desc = @"Be Neither Too Close\nNor Too Distant"; //
[content configWithAvatar:nil title:title download:people desc:desc]; [content configWithAvatar:nil title:title download:people desc:desc];