This commit is contained in:
2025-12-03 20:14:14 +08:00
parent eca168957d
commit 9651ae7ad7
7 changed files with 80 additions and 1 deletions

View File

@@ -9,6 +9,8 @@
NS_ASSUME_NONNULL_BEGIN
@class KBUser;
@interface KBMyHeaderView : UIView
@property (nonatomic, strong, readonly) UILabel *titleLabel; // “Settings” 标题
@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 (^onLeftCardTapped)(void);
@property (nonatomic, copy) void (^onRightCardTapped)(void);
/// 使用用户模型更新头像与昵称
- (void)configureWithUser:(KBUser *)user;
@end
NS_ASSUME_NONNULL_END

View File

@@ -10,6 +10,8 @@
#import "KBMyKeyBoardVC.h"
#import "KBJfPay.h"
#import "KBVipPay.h"
#import "UIImageView+KBWebImage.h"
#import "KBUser.h"
@interface KBMyHeaderView ()
@property (nonatomic, strong) UILabel *titleLabel;
@@ -87,6 +89,18 @@
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 {
// setNeedsLayout
NSMutableArray<CALayer *> *remove = [NSMutableArray array];

View File

@@ -13,12 +13,14 @@
#import "KBTestVC.h"
#import "KBNoticeVC.h"
#import "KBFeedBackVC.h"
#import "KBMyVM.h"
@interface MyVC () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) BaseTableView *tableView; //
@property (nonatomic, strong) KBMyHeaderView *header; //
@property (nonatomic, strong) NSArray<NSArray<NSDictionary *> *> *data; //
@property (nonatomic, strong) UIImageView *bgImageView; //
@property (nonatomic, strong) KBMyVM *viewModel; // VM
@end
@implementation MyVC
@@ -59,6 +61,20 @@
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
#pragma mark - UITableView

View File

@@ -7,9 +7,18 @@
#import <Foundation/Foundation.h>
@class KBUser;
NS_ASSUME_NONNULL_BEGIN
typedef void(^KBMyUserDetailCompletion)(KBUser *_Nullable user, NSError *_Nullable error);
@interface KBMyVM : NSObject
/// 获取当前用户详情(/user/detail
- (void)fetchUserDetailWithCompletion:(KBMyUserDetailCompletion)completion;
/// 退出登录
- (void)logout;
@end

View File

@@ -7,8 +7,41 @@
#import "KBMyVM.h"
#import "AppDelegate.h"
#import "KBNetworkManager.h"
#import "KBUser.h"
@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{
[KBHUD show];
[[KBNetworkManager shared] GET:API_LOGOUT

View File

@@ -45,7 +45,8 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network";
NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish;
_defaultHeaders = @{
@"Accept": @"*/*",
@"Accept-Language": lang
@"Accept-Language": lang,
@"auth-token" : @""
};
//
_baseURL = [NSURL URLWithString:KB_BASE_URL];