From 04c7d19c37539b4129d3e11cd2764fdd6d05cabc Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 11 Dec 2025 15:00:58 +0800 Subject: [PATCH] 1 --- Shared/KBAPI.h | 1 + keyBoard/Class/Me/VC/MySkinVC.m | 2 ++ keyBoard/Class/Shop/VC/KBShopItemVC.m | 2 ++ keyBoard/Class/Shop/VC/KBShopVC.m | 8 ++--- keyBoard/Class/Shop/VC/KBSkinDetailVC.h | 1 + keyBoard/Class/Shop/VC/KBSkinDetailVC.m | 30 +++++++++++++++++++ keyBoard/Class/Shop/VM/KBShopVM.h | 8 ++++- keyBoard/Class/Shop/VM/KBShopVM.m | 40 ++++++++++++++++++------- 8 files changed, 77 insertions(+), 15 deletions(-) diff --git a/Shared/KBAPI.h b/Shared/KBAPI.h index 8f2eb79..70b747e 100644 --- a/Shared/KBAPI.h +++ b/Shared/KBAPI.h @@ -50,6 +50,7 @@ #define API_THEME_LIST_BY_STYLE @"/themes/listByStyle" // 按风格查询主题列表 #define API_THEME_PURCHASED @"/themes/purchased" // 查询已购买主题 #define API_WALLET_BALANCE @"/wallet/balance" // 查询钱包余额 +#define API_THEME_DETAIL @"/themes/detail" // 查询主题详情 /// pay #define API_VALIDATE_RECEIPT @"/api/apple/validate-receipt" // 排行榜标签列表 diff --git a/keyBoard/Class/Me/VC/MySkinVC.m b/keyBoard/Class/Me/VC/MySkinVC.m index 49f20ba..d9883ff 100644 --- a/keyBoard/Class/Me/VC/MySkinVC.m +++ b/keyBoard/Class/Me/VC/MySkinVC.m @@ -205,8 +205,10 @@ static NSString * const kMySkinCellId = @"kMySkinCellId"; - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (!self.isEditingMode) { // 非编辑态:可在此进入详情,当前示例不处理 + KBMyTheme *theme = self.data[indexPath.item]; [collectionView deselectItemAtIndexPath:indexPath animated:YES]; KBSkinDetailVC *vc = [[KBSkinDetailVC alloc] init]; + vc.themeId = theme.themeId; [self.navigationController pushViewController:vc animated:true]; return; } diff --git a/keyBoard/Class/Shop/VC/KBShopItemVC.m b/keyBoard/Class/Shop/VC/KBShopItemVC.m index be6b783..e2d0fbc 100644 --- a/keyBoard/Class/Shop/VC/KBShopItemVC.m +++ b/keyBoard/Class/Shop/VC/KBShopItemVC.m @@ -172,7 +172,9 @@ } - (void)kb_handleShopTapAtIndexPath:(NSIndexPath *)indexPath { + KBShopThemeModel *selTheme = (indexPath.item < self.dataSource.count) ? self.dataSource[indexPath.item] : nil; KBSkinDetailVC *vc = [[KBSkinDetailVC alloc] init]; + vc.themeId = selTheme.themeId; [self.navigationController pushViewController:vc animated:true]; return; KBShopThemeModel *theme = (indexPath.item < self.dataSource.count) ? self.dataSource[indexPath.item] : nil; diff --git a/keyBoard/Class/Shop/VC/KBShopVC.m b/keyBoard/Class/Shop/VC/KBShopVC.m index d7ecb42..b9ff82e 100644 --- a/keyBoard/Class/Shop/VC/KBShopVC.m +++ b/keyBoard/Class/Shop/VC/KBShopVC.m @@ -279,7 +279,7 @@ static const CGFloat JXheightForHeaderInSection = 50; [KBHUD show]; } __weak typeof(self) weakSelf = self; - [self.shopVM fetchWalletBalanceWithCompletion:^(NSNumber * _Nullable balance, NSError * _Nullable error) { + [self.shopVM fetchWalletBalanceWithCompletion:^(NSString * _Nullable balance, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ if (showHUD) { [KBHUD dismiss]; @@ -289,9 +289,9 @@ static const CGFloat JXheightForHeaderInSection = 50; [KBHUD showInfo:msg]; return; } - double amountValue = balance.doubleValue; - NSString *amountString = [NSString stringWithFormat:@"%.2f", amountValue]; - [weakSelf.userHeaderView updatePoints:amountString]; +// double amountValue = balance.doubleValue; +// NSString *amountString = [NSString stringWithFormat:@"%.2f", amountValue]; + [weakSelf.userHeaderView updatePoints:balance]; }); }]; } diff --git a/keyBoard/Class/Shop/VC/KBSkinDetailVC.h b/keyBoard/Class/Shop/VC/KBSkinDetailVC.h index 177960b..3679e0f 100644 --- a/keyBoard/Class/Shop/VC/KBSkinDetailVC.h +++ b/keyBoard/Class/Shop/VC/KBSkinDetailVC.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @interface KBSkinDetailVC : BaseViewController +@property (nonatomic, copy, nullable) NSString *themeId; @end diff --git a/keyBoard/Class/Shop/VC/KBSkinDetailVC.m b/keyBoard/Class/Shop/VC/KBSkinDetailVC.m index 8d77406..c142fba 100644 --- a/keyBoard/Class/Shop/VC/KBSkinDetailVC.m +++ b/keyBoard/Class/Shop/VC/KBSkinDetailVC.m @@ -11,6 +11,7 @@ #import "KBSkinCardCell.h" #import "KBSkinSectionTitleCell.h" #import "KBSkinBottomActionView.h" +#import "KBShopVM.h" static NSString * const kHeaderCellId = @"kHeaderCellId"; static NSString * const kTagsContainerCellId = @"kTagsContainerCellId"; @@ -30,6 +31,7 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) { @property (nonatomic, strong) KBSkinBottomActionView *bottomBar; // 底部操作条 @property (nonatomic, copy) NSArray *tags; // 标签数据 @property (nonatomic, copy) NSArray *gridData; // 底部网格数据 +@property (nonatomic, strong) KBShopVM *shopVM; @end @implementation KBSkinDetailVC @@ -65,6 +67,8 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) { make.top.equalTo(self.view).offset(KB_NAV_TOTAL_HEIGHT); make.bottom.equalTo(self.bottomBar.mas_top).offset(-10); }]; + + [self fetchThemeDetailIfNeeded]; } #pragma mark - UICollectionView DataSource @@ -206,4 +210,30 @@ typedef NS_ENUM(NSInteger, KBSkinDetailSection) { // 预留:下载/购买动作 } +- (void)fetchThemeDetailIfNeeded { + if (self.themeId.length == 0) { + NSLog(@"[KBSkinDetailVC] themeId is empty, skip detail request"); + return; + } + __weak typeof(self) weakSelf = self; + [self.shopVM fetchThemeDetailWithId:self.themeId completion:^(NSDictionary * _Nullable json, NSError * _Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (error) { + NSLog(@"[KBSkinDetailVC] fetch detail failed: %@", error); + return; + } + NSLog(@"[KBSkinDetailVC] theme detail json: %@", json); + // TODO: parse json into models once the structure is finalized. + [weakSelf.collectionView reloadData]; + }); + }]; +} + +- (KBShopVM *)shopVM { + if (!_shopVM) { + _shopVM = [[KBShopVM alloc] init]; + } + return _shopVM; +} + @end diff --git a/keyBoard/Class/Shop/VM/KBShopVM.h b/keyBoard/Class/Shop/VM/KBShopVM.h index d7e74b0..0e24f68 100644 --- a/keyBoard/Class/Shop/VM/KBShopVM.h +++ b/keyBoard/Class/Shop/VM/KBShopVM.h @@ -18,8 +18,10 @@ typedef void(^KBShopStylesCompletion)(NSArray *_Nullable sty NSError *_Nullable error); typedef void(^KBShopThemesCompletion)(NSArray *_Nullable themes, NSError *_Nullable error); -typedef void(^KBShopBalanceCompletion)(NSNumber *_Nullable balance, +typedef void(^KBShopBalanceCompletion)(NSString *_Nullable balance, NSError *_Nullable error); +typedef void(^KBShopDetailCompletion)(NSDictionary *_Nullable json, + NSError *_Nullable error); @interface KBShopVM : NSObject @property (nonatomic, copy, readonly, nullable) NSArray *styles; @@ -34,6 +36,10 @@ typedef void(^KBShopBalanceCompletion)(NSNumber *_Nullable balance, /// 查询钱包余额 - (void)fetchWalletBalanceWithCompletion:(KBShopBalanceCompletion)completion; +/// 查询主题详情 +- (void)fetchThemeDetailWithId:(nullable NSString *)themeId + completion:(KBShopDetailCompletion)completion; + @end NS_ASSUME_NONNULL_END diff --git a/keyBoard/Class/Shop/VM/KBShopVM.m b/keyBoard/Class/Shop/VM/KBShopVM.m index 39af791..3e00cdb 100644 --- a/keyBoard/Class/Shop/VM/KBShopVM.m +++ b/keyBoard/Class/Shop/VM/KBShopVM.m @@ -99,17 +99,37 @@ if (completion) completion(nil, [self kb_invalidResponseError]); return; } - id balanceValue = dataObj[@"balance"]; - NSNumber *balanceNumber = nil; - if ([balanceValue isKindOfClass:[NSNumber class]]) { - balanceNumber = balanceValue; - } else if ([balanceValue isKindOfClass:[NSString class]]) { - balanceNumber = @([(NSString *)balanceValue doubleValue]); + NSString *balanceValue = dataObj[@"balanceDisplay"]; +// NSNumber *balanceNumber = nil; +// if ([balanceValue isKindOfClass:[NSNumber class]]) { +// balanceNumber = balanceValue; +// } else if ([balanceValue isKindOfClass:[NSString class]]) { +// balanceNumber = @([(NSString *)balanceValue doubleValue]); +// } +// if (!balanceNumber) { +// balanceNumber = @(0); +// } + if (completion) completion(balanceValue, nil); + }]; +} + +- (void)fetchThemeDetailWithId:(nullable NSString *)themeId + completion:(KBShopDetailCompletion)completion { + if (themeId.length == 0) { + if (completion) completion(nil, [self kb_invalidParameterError]); + return; + } + NSDictionary *params = @{@"themeId": themeId}; + [[KBNetworkManager shared] GET:API_THEME_DETAIL + parameters:params + headers:nil + autoShowBusinessError:NO + completion:^(NSDictionary * _Nullable json, + NSURLResponse * _Nullable response, + NSError * _Nullable error) { + if (completion) { + completion(json, error); } - if (!balanceNumber) { - balanceNumber = @(0); - } - if (completion) completion(balanceNumber, nil); }]; }