From cccced6afa1df034296bb2ca8560ffe6ebc4711c Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 11 Dec 2025 18:36:14 +0800 Subject: [PATCH] 1 --- Shared/KBAPI.h | 1 + keyBoard/Class/Base/VC/BaseTabBarController.m | 2 +- keyBoard/Class/Me/VC/MySkinVC.m | 72 +++++++++++++++---- keyBoard/Class/Me/VM/KBMyVM.h | 4 ++ keyBoard/Class/Me/VM/KBMyVM.m | 26 +++++++ 5 files changed, 92 insertions(+), 13 deletions(-) diff --git a/Shared/KBAPI.h b/Shared/KBAPI.h index a6fbf56..b60ff8a 100644 --- a/Shared/KBAPI.h +++ b/Shared/KBAPI.h @@ -49,6 +49,7 @@ #define API_THEME_LIST_ALL_STYLES @"/themes/listAllStyles" // 查询所有主题风格 #define API_THEME_LIST_BY_STYLE @"/themes/listByStyle" // 按风格查询主题列表 #define API_THEME_PURCHASED @"/themes/purchased" // 查询已购买主题 +#define API_THEME_BATCH_DELETE @"/user-themes/batch-delete" // 批量删除用户主题 #define API_WALLET_BALANCE @"/wallet/balance" // 查询钱包余额 #define API_THEME_DETAIL @"/themes/detail" // 查询主题详情 #define API_THEME_PURCHASE @"/themes/purchase" // 购买主题 diff --git a/keyBoard/Class/Base/VC/BaseTabBarController.m b/keyBoard/Class/Base/VC/BaseTabBarController.m index 6dbafac..c243681 100644 --- a/keyBoard/Class/Base/VC/BaseTabBarController.m +++ b/keyBoard/Class/Base/VC/BaseTabBarController.m @@ -10,7 +10,7 @@ #import "HomeMainVC.h" #import "MyVC.h" #import "KBShopVC.h" -#import "KBCommunityVC.h" +//#import "KBCommunityVC.h" #import "BaseNavigationController.h" #import "KBAuthManager.h" diff --git a/keyBoard/Class/Me/VC/MySkinVC.m b/keyBoard/Class/Me/VC/MySkinVC.m index d9883ff..ba9bb7c 100644 --- a/keyBoard/Class/Me/VC/MySkinVC.m +++ b/keyBoard/Class/Me/VC/MySkinVC.m @@ -151,19 +151,67 @@ static NSString * const kMySkinCellId = @"kMySkinCellId"; - (void)onDelete { // 根据选中项删除 - NSArray *selected = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)]; - if (selected.count == 0) return; + NSArray *selectedIndexPaths = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)]; + if (selectedIndexPaths.count == 0) return; - // 批量更新,先改数据,再删 UI - [self.collectionView performBatchUpdates:^{ - NSMutableIndexSet *set = [NSMutableIndexSet indexSet]; - for (NSIndexPath *ip in selected) { [set addIndex:ip.item]; } - [self.data removeObjectsAtIndexes:set]; - [self.collectionView deleteItemsAtIndexPaths:selected]; - } completion:^(BOOL finished) { - [self updateBottomUI]; - // 根据当前数据源显隐空视图(删除到 0 条时应显示空态) - [self.collectionView kb_endLoadingForEmpty]; + NSMutableArray *themeIds = [NSMutableArray arrayWithCapacity:selectedIndexPaths.count]; + for (NSIndexPath *ip in selectedIndexPaths) { + if (ip.item >= self.data.count) { continue; } + KBMyTheme *theme = self.data[ip.item]; + id themeIdValue = theme.themeId; + NSNumber *numberId = nil; + if ([themeIdValue isKindOfClass:[NSNumber class]]) { + numberId = (NSNumber *)themeIdValue; + } else if ([themeIdValue isKindOfClass:[NSString class]]) { + NSString *idString = (NSString *)themeIdValue; + if (idString.length > 0) { + static NSCharacterSet *nonDigitSet; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + nonDigitSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; + }); + if ([idString rangeOfCharacterFromSet:nonDigitSet].location == NSNotFound) { + numberId = @([idString longLongValue]); + } + } + } + if (numberId) { + [themeIds addObject:numberId]; + } + } + + if (themeIds.count == 0) { + [KBHUD showInfo:KBLocalized(@"Invalid parameter")]; + return; + } + + [KBHUD show]; + KBWeakSelf + [self.viewModel deletePurchasedThemesWithThemeIds:themeIds + completion:^(BOOL success, NSError * _Nullable error) { + dispatch_async(dispatch_get_main_queue(), ^{ + [KBHUD dismiss]; + if (!success) { + NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error"); + [KBHUD showInfo:msg]; + return; + } + // 批量更新,先改数据,再删 UI + [weakSelf.collectionView performBatchUpdates:^{ + NSMutableIndexSet *set = [NSMutableIndexSet indexSet]; + for (NSIndexPath *ip in selectedIndexPaths) { + if (ip.item < weakSelf.data.count) { + [set addIndex:ip.item]; + } + } + [weakSelf.data removeObjectsAtIndexes:set]; + [weakSelf.collectionView deleteItemsAtIndexPaths:selectedIndexPaths]; + } completion:^(BOOL finished) { + [weakSelf updateBottomUI]; + // 根据当前数据源显隐空视图(删除到 0 条时应显示空态) + [weakSelf.collectionView kb_endLoadingForEmpty]; + }]; + }); }]; } diff --git a/keyBoard/Class/Me/VM/KBMyVM.h b/keyBoard/Class/Me/VM/KBMyVM.h index 4b94e51..daafd05 100644 --- a/keyBoard/Class/Me/VM/KBMyVM.h +++ b/keyBoard/Class/Me/VM/KBMyVM.h @@ -24,6 +24,7 @@ typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable erro typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBMyPurchasedThemesCompletion)(NSArray *_Nullable themes, NSError *_Nullable error); +typedef void(^KBDeleteThemesCompletion)(BOOL success, NSError *_Nullable error); @interface KBMyVM : NSObject @@ -34,6 +35,9 @@ typedef void(^KBMyPurchasedThemesCompletion)(NSArray *_Nullable the - (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion; /// 已购买主题列表(/themes/purchased) - (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion; +/// 批量删除主题(/user-themes/batch-delete) +- (void)deletePurchasedThemesWithThemeIds:(NSArray *)themeIds + completion:(KBDeleteThemesCompletion)completion; /// 更新用户人设排序 - (void)updateUserCharacterSortWithSortArray:(NSArray *)sortArray completion:(KBUpdateCharacterSortCompletion)completion; diff --git a/keyBoard/Class/Me/VM/KBMyVM.m b/keyBoard/Class/Me/VM/KBMyVM.m index b407ae0..9d5af94 100644 --- a/keyBoard/Class/Me/VM/KBMyVM.m +++ b/keyBoard/Class/Me/VM/KBMyVM.m @@ -114,6 +114,32 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo }]; } +- (void)deletePurchasedThemesWithThemeIds:(NSArray *)themeIds + completion:(KBDeleteThemesCompletion)completion { + if (themeIds.count == 0) { + if (completion) { + NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain + code:KBNetworkErrorInvalidResponse + userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid parameter")}]; + completion(NO, e); + } + return; + } + + NSDictionary *params = @{@"themeIds": themeIds}; + [[KBNetworkManager shared] POST:API_THEME_BATCH_DELETE + jsonBody:params + headers:nil + autoShowBusinessError:YES + completion:^(NSDictionary * _Nullable json, + NSURLResponse * _Nullable response, + NSError * _Nullable error) { + if (completion) { + completion(error == nil, error); + } + }]; +} + /// 更新用户人设排序 - (void)updateUserCharacterSortWithSortArray:(NSArray *)sortArray completion:(KBUpdateCharacterSortCompletion)completion {