feat: 添加设置编辑页面及相关功能
主要变更: 1. 新增 EPEditSettingViewController,提供用户头像更新、昵称修改和退出登录功能。 2. 在 Bridging Header 中引入 UserInfoModel、XPMineUserInfoEditPresenter 等新模块,以支持设置页面的功能。 3. 更新多语言文件,添加设置页面相关的本地化字符串。 此更新旨在提升用户体验,简化用户信息管理流程。
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#import "EPMineAPIHelper.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "UserInfoModel.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "YuMi-Swift.h" // 导入Swift桥接
|
||||
|
||||
@interface EPMineViewController ()
|
||||
|
||||
@@ -42,7 +44,7 @@
|
||||
|
||||
[self setupUI];
|
||||
|
||||
NSLog(@"[EPMineViewController] 个人主页加载完成");
|
||||
NSLog(@"[EPMineViewController] viewDidLoad 完成");
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
@@ -56,17 +58,10 @@
|
||||
}
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
- (void)setupUI {
|
||||
// 先设置纯色背景作为兜底,避免白色闪烁
|
||||
self.view.backgroundColor = [UIColor clearColor];
|
||||
|
||||
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:kImage(@"vc_bg")];
|
||||
bgImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
bgImageView.clipsToBounds = YES;
|
||||
[self.view addSubview:bgImageView];
|
||||
[bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.view);
|
||||
}];
|
||||
// 背景渐变色
|
||||
self.view.backgroundColor = [UIColor colorWithRed:0.047 green:0.020 blue:0.153 alpha:1.0]; // #0C0527
|
||||
|
||||
[self setupHeaderView];
|
||||
[self setupMomentListView];
|
||||
@@ -75,76 +70,88 @@
|
||||
}
|
||||
|
||||
- (void)setupHeaderView {
|
||||
self.headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
|
||||
|
||||
self.headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectZero];
|
||||
[self.view addSubview:self.headerView];
|
||||
|
||||
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.view).offset(20);
|
||||
make.leading.trailing.equalTo(self.view);
|
||||
make.height.equalTo(@300);
|
||||
}];
|
||||
// 使用约束布局
|
||||
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 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.headerView.mas_bottom).offset(10);
|
||||
make.leading.trailing.bottom.equalTo(self.view);
|
||||
}];
|
||||
// 使用约束布局
|
||||
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.length) {
|
||||
NSLog(@"[EPMineViewController] 未登录,无法获取用户信息");
|
||||
if (!uid || uid.length == 0) {
|
||||
NSLog(@"[EPMineViewController] 用户未登录");
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.apiHelper getUserDetailInfoWithUid:uid completion:^(UserInfoModel * _Nullable userInfo) {
|
||||
[self.apiHelper getUserDetailInfoWithUid:uid
|
||||
completion:^(UserInfoModel * _Nullable userInfo) {
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
if (!userInfo) {
|
||||
NSLog(@"[EPMineViewController] 加载用户信息失败");
|
||||
return;
|
||||
}
|
||||
|
||||
self.userInfo = userInfo;
|
||||
[self updateHeaderWithUserInfo:userInfo];
|
||||
|
||||
// 更新头部视图
|
||||
NSDictionary *userInfoDict = @{
|
||||
@"nickname": userInfo.nick ?: @"未设置昵称",
|
||||
@"avatar": userInfo.avatar ?: @"",
|
||||
@"uid": userInfo.uid > 0 ? @(userInfo.uid).stringValue : @"",
|
||||
@"followers": @(userInfo.fansNum),
|
||||
@"following": @(userInfo.followNum),
|
||||
};
|
||||
[self.headerView updateWithUserInfo:userInfoDict];
|
||||
|
||||
// 使用本地数组模式显示用户动态
|
||||
[self.momentListView loadWithDynamicInfo:userInfo.dynamicInfo refreshCallback:^{
|
||||
[self loadUserDetailInfo];
|
||||
}];
|
||||
|
||||
NSLog(@"[EPMineViewController] 用户详情加载成功: %@ (动态数: %lu)",
|
||||
userInfo.nick, (unsigned long)userInfo.dynamicInfo.count);
|
||||
|
||||
// 如果有动态信息,直接使用
|
||||
if (userInfo.dynamicInfo && userInfo.dynamicInfo.count > 0) {
|
||||
[self.momentListView loadWithDynamicInfo:userInfo.dynamicInfo refreshCallback:^{
|
||||
[self loadUserDetailInfo]; // 刷新时重新加载
|
||||
}];
|
||||
}
|
||||
} failure:^(NSInteger code, NSString * _Nullable msg) {
|
||||
NSLog(@"[EPMineViewController] 用户详情加载失败: code=%ld, msg=%@", (long)code, 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
|
||||
|
||||
- (EPMineHeaderView *)headerView {
|
||||
if (!_headerView) {
|
||||
_headerView = [[EPMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
|
||||
}
|
||||
return _headerView;
|
||||
}
|
||||
|
||||
- (EPMomentListView *)momentListView {
|
||||
if (!_momentListView) {
|
||||
_momentListView = [[EPMomentListView alloc] initWithFrame:CGRectZero];
|
||||
|
||||
_momentListView = [[EPMomentListView alloc] init];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
_momentListView.onSelectMoment = ^(NSInteger index) {
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
@@ -162,4 +169,16 @@
|
||||
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
|
||||
|
Reference in New Issue
Block a user