
主要变更: 1. 新增 EPEditSettingViewController,提供用户头像更新、昵称修改和退出登录功能。 2. 在 Bridging Header 中引入 UserInfoModel、XPMineUserInfoEditPresenter 等新模块,以支持设置页面的功能。 3. 更新多语言文件,添加设置页面相关的本地化字符串。 此更新旨在提升用户体验,简化用户信息管理流程。
185 lines
5.7 KiB
Objective-C
185 lines
5.7 KiB
Objective-C
//
|
||
// EPMineViewController.m
|
||
// YuMi
|
||
//
|
||
// Created by AI on 2025-10-09.
|
||
// Copyright © 2025 YuMi. All rights reserved.
|
||
//
|
||
|
||
#import "EPMineViewController.h"
|
||
#import "EPMineHeaderView.h"
|
||
#import "EPMomentListView.h"
|
||
#import "EPMineAPIHelper.h"
|
||
#import "AccountInfoStorage.h"
|
||
#import "UserInfoModel.h"
|
||
#import <Masonry/Masonry.h>
|
||
#import "YuMi-Swift.h" // 导入Swift桥接
|
||
|
||
@interface EPMineViewController ()
|
||
|
||
// MARK: - UI Components
|
||
|
||
/// 动态列表视图(复用 EPMomentListView)
|
||
@property (nonatomic, strong) EPMomentListView *momentListView;
|
||
|
||
/// 顶部个人信息卡片
|
||
@property (nonatomic, strong) EPMineHeaderView *headerView;
|
||
|
||
// MARK: - Data
|
||
|
||
/// 用户信息模型
|
||
@property (nonatomic, strong) UserInfoModel *userInfo;
|
||
|
||
/// API Helper
|
||
@property (nonatomic, strong) EPMineAPIHelper *apiHelper;
|
||
|
||
@end
|
||
|
||
@implementation EPMineViewController
|
||
|
||
// MARK: - Lifecycle
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
|
||
[self setupUI];
|
||
|
||
NSLog(@"[EPMineViewController] viewDidLoad 完成");
|
||
}
|
||
|
||
- (void)viewWillAppear:(BOOL)animated {
|
||
[super viewWillAppear:animated];
|
||
|
||
// 隐藏导航栏
|
||
[self.navigationController setNavigationBarHidden:YES animated:animated];
|
||
|
||
// 每次显示时加载最新数据
|
||
[self loadUserDetailInfo];
|
||
}
|
||
|
||
// MARK: - Setup
|
||
|
||
- (void)setupUI {
|
||
// 背景渐变色
|
||
self.view.backgroundColor = [UIColor colorWithRed:0.047 green:0.020 blue:0.153 alpha:1.0]; // #0C0527
|
||
|
||
[self setupHeaderView];
|
||
[self setupMomentListView];
|
||
|
||
NSLog(@"[EPMineViewController] UI 设置完成");
|
||
}
|
||
|
||
- (void)setupHeaderView {
|
||
self.headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectZero];
|
||
[self.view addSubview:self.headerView];
|
||
|
||
// 使用约束布局
|
||
self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
|
||
[NSLayoutConstraint activateConstraints:@[
|
||
[self.headerView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
|
||
[self.headerView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||
[self.headerView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
||
[self.headerView.heightAnchor constraintEqualToConstant:320]
|
||
]];
|
||
|
||
// 监听设置按钮点击事件
|
||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
selector:@selector(openSettings)
|
||
name:@"EPMineHeaderSettingsButtonTapped"
|
||
object:nil];
|
||
}
|
||
|
||
- (void)setupMomentListView {
|
||
self.momentListView = [[EPMomentListView alloc] initWithFrame:CGRectZero];
|
||
[self.view addSubview:self.momentListView];
|
||
|
||
// 使用约束布局
|
||
self.momentListView.translatesAutoresizingMaskIntoConstraints = NO;
|
||
[NSLayoutConstraint activateConstraints:@[
|
||
[self.momentListView.topAnchor constraintEqualToAnchor:self.headerView.bottomAnchor],
|
||
[self.momentListView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
|
||
[self.momentListView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
|
||
[self.momentListView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
|
||
]];
|
||
}
|
||
|
||
// MARK: - Data Loading
|
||
|
||
- (void)loadUserDetailInfo {
|
||
NSString *uid = [[AccountInfoStorage instance] getUid];
|
||
if (!uid || uid.length == 0) {
|
||
NSLog(@"[EPMineViewController] 用户未登录");
|
||
return;
|
||
}
|
||
|
||
__weak typeof(self) weakSelf = self;
|
||
[self.apiHelper getUserDetailInfoWithUid:uid
|
||
completion:^(UserInfoModel * _Nullable userInfo) {
|
||
__strong typeof(weakSelf) self = weakSelf;
|
||
if (!userInfo) {
|
||
NSLog(@"[EPMineViewController] 加载用户信息失败");
|
||
return;
|
||
}
|
||
|
||
self.userInfo = userInfo;
|
||
[self updateHeaderWithUserInfo:userInfo];
|
||
|
||
// 如果有动态信息,直接使用
|
||
if (userInfo.dynamicInfo && userInfo.dynamicInfo.count > 0) {
|
||
[self.momentListView loadWithDynamicInfo:userInfo.dynamicInfo refreshCallback:^{
|
||
[self loadUserDetailInfo]; // 刷新时重新加载
|
||
}];
|
||
}
|
||
} failure:^(NSInteger code, NSString * _Nullable msg) {
|
||
NSLog(@"[EPMineViewController] 加载用户信息失败: %@", msg);
|
||
}];
|
||
}
|
||
|
||
- (void)updateHeaderWithUserInfo:(UserInfoModel *)userInfo {
|
||
NSDictionary *userInfoDict = @{
|
||
@"nickname": userInfo.nick ?: @"未设置昵称",
|
||
@"uid": [NSString stringWithFormat:@"%ld", (long)userInfo.uid],
|
||
@"avatar": userInfo.avatar ?: @"",
|
||
@"following": @(userInfo.followNum),
|
||
@"followers": @(userInfo.fansNum)
|
||
};
|
||
|
||
[self.headerView updateWithUserInfo:userInfoDict];
|
||
}
|
||
|
||
// MARK: - Lazy Loading
|
||
|
||
- (EPMomentListView *)momentListView {
|
||
if (!_momentListView) {
|
||
_momentListView = [[EPMomentListView alloc] init];
|
||
__weak typeof(self) weakSelf = self;
|
||
_momentListView.onSelectMoment = ^(NSInteger index) {
|
||
__strong typeof(weakSelf) self = weakSelf;
|
||
NSLog(@"[EPMineViewController] 点击了第 %ld 条动态", (long)index);
|
||
// TODO: 跳转到动态详情页
|
||
};
|
||
}
|
||
return _momentListView;
|
||
}
|
||
|
||
- (EPMineAPIHelper *)apiHelper {
|
||
if (!_apiHelper) {
|
||
_apiHelper = [[EPMineAPIHelper alloc] init];
|
||
}
|
||
return _apiHelper;
|
||
}
|
||
|
||
// MARK: - Actions
|
||
|
||
- (void)openSettings {
|
||
EPEditSettingViewController *settingsVC = [[EPEditSettingViewController alloc] init];
|
||
[self.navigationController pushViewController:settingsVC animated:YES];
|
||
NSLog(@"[EPMineViewController] 打开设置页面");
|
||
}
|
||
|
||
- (void)dealloc {
|
||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||
}
|
||
|
||
@end
|