This commit is contained in:
2025-12-11 18:36:14 +08:00
parent 14637a21ad
commit cccced6afa
5 changed files with 92 additions and 13 deletions

View File

@@ -49,6 +49,7 @@
#define API_THEME_LIST_ALL_STYLES @"/themes/listAllStyles" // 查询所有主题风格 #define API_THEME_LIST_ALL_STYLES @"/themes/listAllStyles" // 查询所有主题风格
#define API_THEME_LIST_BY_STYLE @"/themes/listByStyle" // 按风格查询主题列表 #define API_THEME_LIST_BY_STYLE @"/themes/listByStyle" // 按风格查询主题列表
#define API_THEME_PURCHASED @"/themes/purchased" // 查询已购买主题 #define API_THEME_PURCHASED @"/themes/purchased" // 查询已购买主题
#define API_THEME_BATCH_DELETE @"/user-themes/batch-delete" // 批量删除用户主题
#define API_WALLET_BALANCE @"/wallet/balance" // 查询钱包余额 #define API_WALLET_BALANCE @"/wallet/balance" // 查询钱包余额
#define API_THEME_DETAIL @"/themes/detail" // 查询主题详情 #define API_THEME_DETAIL @"/themes/detail" // 查询主题详情
#define API_THEME_PURCHASE @"/themes/purchase" // 购买主题 #define API_THEME_PURCHASE @"/themes/purchase" // 购买主题

View File

@@ -10,7 +10,7 @@
#import "HomeMainVC.h" #import "HomeMainVC.h"
#import "MyVC.h" #import "MyVC.h"
#import "KBShopVC.h" #import "KBShopVC.h"
#import "KBCommunityVC.h" //#import "KBCommunityVC.h"
#import "BaseNavigationController.h" #import "BaseNavigationController.h"
#import "KBAuthManager.h" #import "KBAuthManager.h"

View File

@@ -151,19 +151,67 @@ static NSString * const kMySkinCellId = @"kMySkinCellId";
- (void)onDelete { - (void)onDelete {
// //
NSArray<NSIndexPath *> *selected = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)]; NSArray<NSIndexPath *> *selectedIndexPaths = [[self.collectionView indexPathsForSelectedItems] sortedArrayUsingSelector:@selector(compare:)];
if (selected.count == 0) return; if (selectedIndexPaths.count == 0) return;
NSMutableArray<NSNumber *> *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 // UI
[self.collectionView performBatchUpdates:^{ [weakSelf.collectionView performBatchUpdates:^{
NSMutableIndexSet *set = [NSMutableIndexSet indexSet]; NSMutableIndexSet *set = [NSMutableIndexSet indexSet];
for (NSIndexPath *ip in selected) { [set addIndex:ip.item]; } for (NSIndexPath *ip in selectedIndexPaths) {
[self.data removeObjectsAtIndexes:set]; if (ip.item < weakSelf.data.count) {
[self.collectionView deleteItemsAtIndexPaths:selected]; [set addIndex:ip.item];
}
}
[weakSelf.data removeObjectsAtIndexes:set];
[weakSelf.collectionView deleteItemsAtIndexPaths:selectedIndexPaths];
} completion:^(BOOL finished) { } completion:^(BOOL finished) {
[self updateBottomUI]; [weakSelf updateBottomUI];
// 0 // 0
[self.collectionView kb_endLoadingForEmpty]; [weakSelf.collectionView kb_endLoadingForEmpty];
}];
});
}]; }];
} }

View File

@@ -24,6 +24,7 @@ typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable erro
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_Nullable themes, NSError *_Nullable error); typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_Nullable themes, NSError *_Nullable error);
typedef void(^KBDeleteThemesCompletion)(BOOL success, NSError *_Nullable error);
@interface KBMyVM : NSObject @interface KBMyVM : NSObject
@@ -34,6 +35,9 @@ typedef void(^KBMyPurchasedThemesCompletion)(NSArray<KBMyTheme *> *_Nullable the
- (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion; - (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion;
/// 已购买主题列表(/themes/purchased /// 已购买主题列表(/themes/purchased
- (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion; - (void)fetchPurchasedThemesWithCompletion:(KBMyPurchasedThemesCompletion)completion;
/// 批量删除主题(/user-themes/batch-delete
- (void)deletePurchasedThemesWithThemeIds:(NSArray<NSNumber *> *)themeIds
completion:(KBDeleteThemesCompletion)completion;
/// 更新用户人设排序 /// 更新用户人设排序
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray - (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
completion:(KBUpdateCharacterSortCompletion)completion; completion:(KBUpdateCharacterSortCompletion)completion;

View File

@@ -114,6 +114,32 @@ NSString * const KBUserCharacterDeletedNotification = @"KBUserCharacterDeletedNo
}]; }];
} }
- (void)deletePurchasedThemesWithThemeIds:(NSArray<NSNumber *> *)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<NSNumber *> *)sortArray - (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
completion:(KBUpdateCharacterSortCompletion)completion { completion:(KBUpdateCharacterSortCompletion)completion {