2025-11-06 14:02:22 +08:00
|
|
|
|
//
|
|
|
|
|
|
// HomeHotVC.m
|
|
|
|
|
|
// keyBoard
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Mac on 2025/11/6.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "HomeHotVC.h"
|
2025-11-06 14:59:00 +08:00
|
|
|
|
// 视图
|
|
|
|
|
|
#import "KBTopThreeView.h"
|
2025-12-03 18:49:18 +08:00
|
|
|
|
#import "KBHomeVM.h"
|
|
|
|
|
|
#import "KBCharacter.h"
|
2025-11-06 14:59:00 +08:00
|
|
|
|
#import "HomeHotCell.h"
|
2025-11-06 16:05:28 +08:00
|
|
|
|
#import "HomeRankVC.h"
|
2025-11-07 22:22:41 +08:00
|
|
|
|
#import "KBSearchVC.h"
|
2025-11-17 15:39:03 +08:00
|
|
|
|
#import "HomeRankDetailPopView.h"
|
|
|
|
|
|
#import "LSTPopView.h"
|
2025-11-06 14:59:00 +08:00
|
|
|
|
#import <HWPanModal/HWPanModal.h>
|
2025-12-03 18:49:18 +08:00
|
|
|
|
|
2025-11-06 14:59:00 +08:00
|
|
|
|
@interface HomeHotVC () <UITableViewDataSource, UITableViewDelegate>
|
|
|
|
|
|
|
|
|
|
|
|
// 顶部前三名视图
|
|
|
|
|
|
@property (nonatomic, strong) KBTopThreeView *topThreeView;
|
|
|
|
|
|
|
2025-12-03 18:49:18 +08:00
|
|
|
|
/// 首页排行榜 VM
|
|
|
|
|
|
@property (nonatomic, strong) KBHomeVM *homeVM;
|
|
|
|
|
|
/// 完整的排行榜数据(接口返回)
|
|
|
|
|
|
@property (nonatomic, copy) NSArray<KBCharacter *> *allCharacters;
|
|
|
|
|
|
/// 列表区域使用的数据:从第 4 名开始
|
|
|
|
|
|
@property (nonatomic, copy) NSArray<KBCharacter *> *listCharacters;
|
2025-11-06 14:59:00 +08:00
|
|
|
|
|
|
|
|
|
|
@end
|
2025-11-06 14:02:22 +08:00
|
|
|
|
|
|
|
|
|
|
@interface HomeHotVC ()
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation HomeHotVC
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
|
[super viewDidLoad];
|
2025-11-06 14:59:00 +08:00
|
|
|
|
|
|
|
|
|
|
// 搭建 UI
|
|
|
|
|
|
[self.view addSubview:self.tableView];
|
|
|
|
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.edges.equalTo(self.view);
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
// 顶部前三名作为 tableHeaderView(注意:tableHeaderView 需设定明确高度)
|
|
|
|
|
|
CGFloat headerH = 280.0;
|
|
|
|
|
|
self.topThreeView = [[KBTopThreeView alloc] initWithFrame:CGRectMake(0, 0, KB_SCREEN_WIDTH, headerH)];
|
|
|
|
|
|
self.tableView.tableHeaderView = self.topThreeView;
|
2025-12-03 18:49:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 请求排行榜数据
|
|
|
|
|
|
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];
|
|
|
|
|
|
}
|
|
|
|
|
|
}];
|
2025-11-06 14:02:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-06 14:59:00 +08:00
|
|
|
|
#pragma mark - UITableViewDataSource
|
2025-11-06 14:02:22 +08:00
|
|
|
|
|
2025-11-06 14:59:00 +08:00
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2025-12-03 18:49:18 +08:00
|
|
|
|
return self.listCharacters.count;
|
2025-11-06 14:02:22 +08:00
|
|
|
|
}
|
2025-11-06 14:59:00 +08:00
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
HomeHotCell *cell = [tableView dequeueReusableCellWithIdentifier:HomeHotCell.reuseId forIndexPath:indexPath];
|
2025-12-03 18:49:18 +08:00
|
|
|
|
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;
|
2025-11-06 14:59:00 +08:00
|
|
|
|
// 配置 cell
|
2025-12-03 18:49:18 +08:00
|
|
|
|
[cell configWithRank:rank
|
|
|
|
|
|
title:title
|
|
|
|
|
|
subtitle:sub
|
|
|
|
|
|
joined:joined];
|
2025-11-06 14:59:00 +08:00
|
|
|
|
return cell;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
return 84.0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2025-11-17 15:39:03 +08:00
|
|
|
|
// KBSearchVC *vc = [[KBSearchVC alloc] init];
|
2025-11-06 16:57:28 +08:00
|
|
|
|
// [self.navigationController pushViewController:vc animated:true];
|
2025-11-17 15:39:03 +08:00
|
|
|
|
// UINavigationController *nav = KB_CURRENT_NAV;
|
2025-11-10 13:27:26 +08:00
|
|
|
|
// [nav pushViewController:vc animated:true];
|
2025-11-06 16:57:28 +08:00
|
|
|
|
NSLog(@"===");
|
2025-12-03 18:49:18 +08:00
|
|
|
|
|
2025-11-17 15:39:03 +08:00
|
|
|
|
// 点击卡片 -> 展示弹窗
|
2025-12-03 18:49:18 +08:00
|
|
|
|
KBCharacter *c = self.listCharacters[indexPath.row];
|
2025-11-17 15:39:03 +08:00
|
|
|
|
|
|
|
|
|
|
// 自定义内容视图(尺寸可按需调节)
|
|
|
|
|
|
CGFloat width = MIN(KB_SCREEN_WIDTH - 76, 420);
|
|
|
|
|
|
HomeRankDetailPopView *content = [[HomeRankDetailPopView alloc] initWithFrame:CGRectMake(0, 0, width, 460)];
|
2025-12-03 18:49:18 +08:00
|
|
|
|
NSString *title = c.characterName ?: @"High EQ";
|
|
|
|
|
|
NSString *people = c.download ?: @"Download: 1 Million";
|
2025-11-17 15:39:03 +08:00
|
|
|
|
NSString *desc = @"Be Neither Too Close\nNor Too Distant"; // 示例文案
|
|
|
|
|
|
[content configWithAvatar:nil title:title download:people desc:desc];
|
|
|
|
|
|
|
|
|
|
|
|
// 创建并弹出
|
|
|
|
|
|
LSTPopView *pop = [LSTPopView initWithCustomView:content
|
|
|
|
|
|
parentView:nil
|
|
|
|
|
|
popStyle:LSTPopStyleScale
|
|
|
|
|
|
dismissStyle:LSTDismissStyleScale];
|
|
|
|
|
|
pop.hemStyle = LSTHemStyleCenter; // 居中
|
|
|
|
|
|
pop.bgColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
|
|
|
|
|
|
pop.isClickBgDismiss = YES; // 点击背景关闭
|
|
|
|
|
|
pop.cornerRadius = 0; // 自定义 view 自处理圆角
|
|
|
|
|
|
|
|
|
|
|
|
__weak typeof(pop) weakPop = pop;
|
|
|
|
|
|
content.saveHandler = ^{ [weakPop dismiss]; };
|
|
|
|
|
|
content.closeHandler = ^{ [weakPop dismiss]; };
|
|
|
|
|
|
|
|
|
|
|
|
[pop pop];
|
|
|
|
|
|
|
2025-11-06 14:59:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Lazy
|
|
|
|
|
|
|
|
|
|
|
|
- (BaseTableView *)tableView {
|
|
|
|
|
|
if (!_tableView) {
|
|
|
|
|
|
// 使用 BaseTableView,统一默认配置
|
|
|
|
|
|
_tableView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
|
|
|
_tableView.dataSource = self;
|
|
|
|
|
|
_tableView.delegate = self;
|
|
|
|
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 设计为卡片式,去掉系统分割线
|
|
|
|
|
|
_tableView.showsVerticalScrollIndicator = NO;
|
|
|
|
|
|
_tableView.contentInset = UIEdgeInsetsMake(8, 0, KB_SafeAreaBottom(), 0);
|
|
|
|
|
|
[_tableView registerClass:HomeHotCell.class forCellReuseIdentifier:HomeHotCell.reuseId];
|
|
|
|
|
|
}
|
|
|
|
|
|
return _tableView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-06 14:02:22 +08:00
|
|
|
|
|
|
|
|
|
|
@end
|