Files
real-e-party-iOS/YuMi/Modules/NewMine/Controllers/EPMineViewController.m
edwinQQQ 12a8ef9a62 重构 Mine 模块为个人主页模式
 完成功能:
1. EPMineViewController 重构
   - 从菜单列表模式改为个人主页模式
   - 渐变背景(深紫到蓝)
   - 顶部个人信息卡片 + 底部用户动态列表
   - 复用 EPMomentCell 显示动态

2. EPMineHeaderView 新建
   - 大圆形头像(120x120,白色边框)
   - 昵称 + ID 显示
   - 关注/粉丝按钮
   - 右上角设置按钮
   - 渐变背景适配

3. 数据加载优化
   - 用户信息加载(真实 API)
   - 用户动态列表(分页加载)
   - 下拉刷新功能
   - 自动加载更多

4. 文件重命名
   - EPMomentCell(原 NewMomentCell)
   - EPMineHeaderView(新建)
   - 更新 Bridging Header

技术亮点:
- 个人主页模式完全不同于原版菜单模式
- 渐变背景 + 毛玻璃效果
- 复用 EPMomentCell 减少开发量
- 真实 API 集成

下一步:
- 修复编译错误(文件未添加到 Xcode 项目)
- 继续 v0.2 版本准备
2025-10-10 15:05:07 +08:00

246 lines
7.6 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.

//
// EPMineViewController.m
// YuMi
//
// Created by AI on 2025-10-09.
// Copyright © 2025 YuMi. All rights reserved.
//
#import "EPMineViewController.h"
#import "EPMineHeaderView.h"
#import "EPMomentCell.h"
#import <Masonry/Masonry.h>
#import "Api+Moments.h"
#import "AccountInfoStorage.h"
#import "UserInfoModel.h"
#import "MomentsInfoModel.h"
#import <MJExtension/MJExtension.h>
@interface EPMineViewController () <UITableViewDelegate, UITableViewDataSource>
// MARK: - UI Components
/// 主列表(显示用户动态)
@property (nonatomic, strong) UITableView *tableView;
/// 顶部个人信息卡片
@property (nonatomic, strong) EPMineHeaderView *headerView;
// MARK: - Data
/// 用户动态数据源
@property (nonatomic, strong) NSMutableArray<MomentsInfoModel *> *momentsData;
/// 当前页码
@property (nonatomic, assign) NSInteger currentPage;
/// 是否正在加载
@property (nonatomic, assign) BOOL isLoading;
/// 用户信息模型
@property (nonatomic, strong) UserInfoModel *userInfo;
@end
@implementation EPMineViewController
// MARK: - Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
// 设置渐变背景(深紫到蓝)
[self setupGradientBackground];
self.momentsData = [NSMutableArray array];
self.currentPage = 1;
self.isLoading = NO;
[self setupUI];
[self loadUserInfo];
[self loadUserMoments];
NSLog(@"[EPMineViewController] 个人主页加载完成");
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// 刷新用户信息
[self refreshUserInfo];
}
// MARK: - Setup
- (void)setupGradientBackground {
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.view.bounds;
gradientLayer.colors = @[
(id)[UIColor colorWithRed:0.3 green:0.2 blue:0.6 alpha:1.0].CGColor, // 深紫 #4C3399
(id)[UIColor colorWithRed:0.2 green:0.3 blue:0.8 alpha:1.0].CGColor // 蓝 #3366CC
];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 1);
[self.view.layer insertSublayer:gradientLayer atIndex:0];
}
- (void)setupUI {
[self setupHeaderView];
[self setupTableView];
NSLog(@"[EPMineViewController] UI 设置完成");
}
- (void)setupHeaderView {
self.headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
[self.view addSubview:self.headerView];
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(20);
make.left.right.equalTo(self.view);
make.height.equalTo(@300);
}];
}
- (void)setupTableView {
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
// 注册动态 cell复用 EPMomentCell
[self.tableView registerClass:[EPMomentCell class] forCellReuseIdentifier:@"EPMomentCell"];
[self.view addSubview:self.tableView];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.headerView.mas_bottom).offset(10);
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
}];
// 添加下拉刷新
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refreshData) forControlEvents:UIControlEventValueChanged];
self.tableView.refreshControl = refreshControl;
}
// MARK: - Data Loading
- (void)loadUserInfo {
NSString *uid = [[AccountInfoStorage instance] getUid];
if (!uid.length) {
NSLog(@"[EPMineViewController] 未登录,无法获取用户信息");
return;
}
// 调用真实 API 获取用户信息
[Api getUserInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
if (code == 200 && data.data) {
self.userInfo = [UserInfoModel mj_objectWithKeyValues:data.data];
// 更新头部视图
NSDictionary *userInfoDict = @{
@"nickname": self.userInfo.nick ?: @"未设置昵称",
@"avatar": self.userInfo.avatar ?: @"",
@"uid": self.userInfo.uid ?: @"",
@"followers": @(self.userInfo.fansNum),
@"following": @(self.userInfo.followNum),
};
[self.headerView updateWithUserInfo:userInfoDict];
NSLog(@"[EPMineViewController] 用户信息加载成功: %@", self.userInfo.nick);
} else {
NSLog(@"[EPMineViewController] 用户信息加载失败: %@", msg);
}
} uid:uid];
}
- (void)refreshUserInfo {
[self loadUserInfo];
}
- (void)loadUserMoments {
if (self.isLoading) return;
NSString *uid = [[AccountInfoStorage instance] getUid];
if (!uid.length) {
NSLog(@"[EPMineViewController] 未登录,无法获取用户动态");
return;
}
self.isLoading = YES;
NSString *page = [NSString stringWithFormat:@"%ld", (long)self.currentPage];
// 调用获取用户动态的 API这里先用通用的动态列表 API
[Api momentsRecommendList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
self.isLoading = NO;
[self.refreshControl endRefreshing];
if (code == 200 && data.data) {
NSArray *list = [MomentsInfoModel mj_objectArrayWithKeyValuesArray:data.data];
if (list.count > 0) {
[self.momentsData addObjectsFromArray:list];
self.currentPage++;
[self.tableView reloadData];
NSLog(@"[EPMineViewController] 用户动态加载成功,新增 %lu 条", (unsigned long)list.count);
}
} else {
NSLog(@"[EPMineViewController] 用户动态加载失败: %@", msg);
}
} page:page pageSize:@"10" types:@"0,2"];
}
- (void)refreshData {
self.currentPage = 1;
[self.momentsData removeAllObjects];
[self loadUserMoments];
}
// MARK: - UITableView DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.momentsData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
EPMomentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"EPMomentCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor clearColor];
if (indexPath.row < self.momentsData.count) {
[cell configureWithModel:self.momentsData[indexPath.row]];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 200; // 根据实际内容调整
}
// MARK: - UITableView Delegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// 滚动到底部自动加载更多
if (indexPath.row == self.momentsData.count - 1 && !self.isLoading) {
[self loadUserMoments];
}
}
// MARK: - Lazy Loading
- (EPMineHeaderView *)headerView {
if (!_headerView) {
_headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
}
return _headerView;
}
- (UIRefreshControl *)refreshControl {
return self.tableView.refreshControl;
}
@end