1
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
// 兼容旧命名(如有使用 API_APPLE_LOGIN 的位置,映射到统一命名)
|
// 兼容旧命名(如有使用 API_APPLE_LOGIN 的位置,映射到统一命名)
|
||||||
#define API_APPLE_LOGIN @"/user/appleLogin" // Apple 登录
|
#define API_APPLE_LOGIN @"/user/appleLogin" // Apple 登录
|
||||||
#define API_LOGOUT @"/user/logout" // 退出登录
|
#define API_LOGOUT @"/user/logout" // 退出登录
|
||||||
|
#define KB_API_USER_DETAIL @"/user/detail" // 用户详情
|
||||||
#define KB_API_CHARACTER_LIST @"/character/list" // 排行榜角色列表(综合)
|
#define KB_API_CHARACTER_LIST @"/character/list" // 排行榜角色列表(综合)
|
||||||
#define KB_API_CHARACTER_LIST_BY_TAG @"/character/listByTag" // 根据 tagId 获取角色列表
|
#define KB_API_CHARACTER_LIST_BY_TAG @"/character/listByTag" // 根据 tagId 获取角色列表
|
||||||
#define KB_API_TAG_LIST @"/tag/list" // 排行榜标签列表
|
#define KB_API_TAG_LIST @"/tag/list" // 排行榜标签列表
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class KBUser;
|
||||||
|
|
||||||
@interface KBMyHeaderView : UIView
|
@interface KBMyHeaderView : UIView
|
||||||
@property (nonatomic, strong, readonly) UILabel *titleLabel; // “Settings” 标题
|
@property (nonatomic, strong, readonly) UILabel *titleLabel; // “Settings” 标题
|
||||||
@property (nonatomic, strong, readonly) UIButton *keyboardBtn; // 右上角“ My Keyboard ”按钮
|
@property (nonatomic, strong, readonly) UIButton *keyboardBtn; // 右上角“ My Keyboard ”按钮
|
||||||
@@ -22,6 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@property (nonatomic, copy) void (^onAvatarTapped)(void);
|
@property (nonatomic, copy) void (^onAvatarTapped)(void);
|
||||||
@property (nonatomic, copy) void (^onLeftCardTapped)(void);
|
@property (nonatomic, copy) void (^onLeftCardTapped)(void);
|
||||||
@property (nonatomic, copy) void (^onRightCardTapped)(void);
|
@property (nonatomic, copy) void (^onRightCardTapped)(void);
|
||||||
|
|
||||||
|
/// 使用用户模型更新头像与昵称
|
||||||
|
- (void)configureWithUser:(KBUser *)user;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#import "KBMyKeyBoardVC.h"
|
#import "KBMyKeyBoardVC.h"
|
||||||
#import "KBJfPay.h"
|
#import "KBJfPay.h"
|
||||||
#import "KBVipPay.h"
|
#import "KBVipPay.h"
|
||||||
|
#import "UIImageView+KBWebImage.h"
|
||||||
|
#import "KBUser.h"
|
||||||
|
|
||||||
@interface KBMyHeaderView ()
|
@interface KBMyHeaderView ()
|
||||||
@property (nonatomic, strong) UILabel *titleLabel;
|
@property (nonatomic, strong) UILabel *titleLabel;
|
||||||
@@ -87,6 +89,18 @@
|
|||||||
self.avatarView.layer.masksToBounds = YES;
|
self.avatarView.layer.masksToBounds = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)configureWithUser:(KBUser *)user {
|
||||||
|
// 名称:优先昵称,兜底展示本地化的“Settings”或固定提示
|
||||||
|
NSString *name = user.nickName;
|
||||||
|
if (name.length == 0) {
|
||||||
|
name = KBLocalized(@"Settings");
|
||||||
|
}
|
||||||
|
self.nameLabel.text = name;
|
||||||
|
|
||||||
|
// 头像:使用通用占位图
|
||||||
|
[self.avatarView kb_setAvatarURL:user.avatarUrl placeholder:KBPlaceholderImage];
|
||||||
|
}
|
||||||
|
|
||||||
+ (void)kb_applyGradientTo:(UIView *)view colors:(NSArray *)colors {
|
+ (void)kb_applyGradientTo:(UIView *)view colors:(NSArray *)colors {
|
||||||
// 删除旧的渐变层,重复 setNeedsLayout 时避免叠加
|
// 删除旧的渐变层,重复 setNeedsLayout 时避免叠加
|
||||||
NSMutableArray<CALayer *> *remove = [NSMutableArray array];
|
NSMutableArray<CALayer *> *remove = [NSMutableArray array];
|
||||||
|
|||||||
@@ -13,12 +13,14 @@
|
|||||||
#import "KBTestVC.h"
|
#import "KBTestVC.h"
|
||||||
#import "KBNoticeVC.h"
|
#import "KBNoticeVC.h"
|
||||||
#import "KBFeedBackVC.h"
|
#import "KBFeedBackVC.h"
|
||||||
|
#import "KBMyVM.h"
|
||||||
|
|
||||||
@interface MyVC () <UITableViewDelegate, UITableViewDataSource>
|
@interface MyVC () <UITableViewDelegate, UITableViewDataSource>
|
||||||
@property (nonatomic, strong) BaseTableView *tableView; // 列表
|
@property (nonatomic, strong) BaseTableView *tableView; // 列表
|
||||||
@property (nonatomic, strong) KBMyHeaderView *header; // 顶部视图
|
@property (nonatomic, strong) KBMyHeaderView *header; // 顶部视图
|
||||||
@property (nonatomic, strong) NSArray<NSArray<NSDictionary *> *> *data; // 分组数据
|
@property (nonatomic, strong) NSArray<NSArray<NSDictionary *> *> *data; // 分组数据
|
||||||
@property (nonatomic, strong) UIImageView *bgImageView; // 全屏背景图
|
@property (nonatomic, strong) UIImageView *bgImageView; // 全屏背景图
|
||||||
|
@property (nonatomic, strong) KBMyVM *viewModel; // 我的页面 VM
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MyVC
|
@implementation MyVC
|
||||||
@@ -59,6 +61,20 @@
|
|||||||
self.tableView.tableHeaderView = self.header;
|
self.tableView.tableHeaderView = self.header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)viewWillAppear:(BOOL)animated {
|
||||||
|
[super viewWillAppear:animated];
|
||||||
|
// 每次进入“我的”页面时请求用户详情
|
||||||
|
if (!self.viewModel) {
|
||||||
|
self.viewModel = [[KBMyVM alloc] init];
|
||||||
|
}
|
||||||
|
__weak typeof(self) weakSelf = self;
|
||||||
|
[self.viewModel fetchUserDetailWithCompletion:^(KBUser * _Nullable user, NSError * _Nullable error) {
|
||||||
|
if (user) {
|
||||||
|
[weakSelf.header configureWithUser:user];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
// 系统导航栏的显隐由 BaseViewController 统一处理(始终隐藏),此处无需再设置。
|
// 系统导航栏的显隐由 BaseViewController 统一处理(始终隐藏),此处无需再设置。
|
||||||
|
|
||||||
#pragma mark - UITableView
|
#pragma mark - UITableView
|
||||||
|
|||||||
@@ -7,9 +7,18 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@class KBUser;
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
typedef void(^KBMyUserDetailCompletion)(KBUser *_Nullable user, NSError *_Nullable error);
|
||||||
|
|
||||||
@interface KBMyVM : NSObject
|
@interface KBMyVM : NSObject
|
||||||
|
|
||||||
|
/// 获取当前用户详情(/user/detail)
|
||||||
|
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion;
|
||||||
|
|
||||||
|
/// 退出登录
|
||||||
- (void)logout;
|
- (void)logout;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,41 @@
|
|||||||
|
|
||||||
#import "KBMyVM.h"
|
#import "KBMyVM.h"
|
||||||
#import "AppDelegate.h"
|
#import "AppDelegate.h"
|
||||||
|
#import "KBNetworkManager.h"
|
||||||
|
#import "KBUser.h"
|
||||||
|
|
||||||
@implementation KBMyVM
|
@implementation KBMyVM
|
||||||
|
|
||||||
|
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion {
|
||||||
|
[KBHUD show];
|
||||||
|
[[KBNetworkManager shared] GET:KB_API_USER_DETAIL
|
||||||
|
parameters:nil
|
||||||
|
headers:nil
|
||||||
|
autoShowBusinessError:NO
|
||||||
|
completion:^(NSDictionary *jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||||
|
[KBHUD dismiss];
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
NSString *msg = KBBizMessageFromJSONObject(jsonOrData) ?: error.localizedDescription ?: KBLocalized(@"Network error");
|
||||||
|
[KBHUD showInfo:msg];
|
||||||
|
if (completion) completion(nil, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
id dataObj = jsonOrData[KBData] ?: jsonOrData[@"data"];
|
||||||
|
if (![dataObj isKindOfClass:[NSDictionary class]]) {
|
||||||
|
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
|
||||||
|
code:KBNetworkErrorInvalidResponse
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid response")}];
|
||||||
|
[KBHUD showInfo:e.localizedDescription];
|
||||||
|
if (completion) completion(nil, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
KBUser *user = [KBUser mj_objectWithKeyValues:(NSDictionary *)dataObj];
|
||||||
|
if (completion) completion(user, nil);
|
||||||
|
}];
|
||||||
|
}
|
||||||
- (void)logout{
|
- (void)logout{
|
||||||
[KBHUD show];
|
[KBHUD show];
|
||||||
[[KBNetworkManager shared] GET:API_LOGOUT
|
[[KBNetworkManager shared] GET:API_LOGOUT
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
|
|||||||
NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish;
|
NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish;
|
||||||
_defaultHeaders = @{
|
_defaultHeaders = @{
|
||||||
@"Accept": @"*/*",
|
@"Accept": @"*/*",
|
||||||
@"Accept-Language": lang
|
@"Accept-Language": lang,
|
||||||
|
@"auth-token" : @""
|
||||||
};
|
};
|
||||||
// 设置基础域名,路径可相对该地址拼接
|
// 设置基础域名,路径可相对该地址拼接
|
||||||
_baseURL = [NSURL URLWithString:KB_BASE_URL];
|
_baseURL = [NSURL URLWithString:KB_BASE_URL];
|
||||||
|
|||||||
Reference in New Issue
Block a user