This commit is contained in:
2025-12-04 16:41:33 +08:00
parent 231f7f8c13
commit f593ef0b4a
4 changed files with 103 additions and 28 deletions

View File

@@ -33,6 +33,7 @@
#define KB_API_CHARACTER_DETAIL @"/character/detail" // 人设详情 #define KB_API_CHARACTER_DETAIL @"/character/detail" // 人设详情
#define KB_API_CHARACTER_LISTBYUSER @"/character/listByUser" // 用户人设列表 #define KB_API_CHARACTER_LISTBYUSER @"/character/listByUser" // 用户人设列表
#define API_CHARACTER_UPDATE_USER_CHARTSORT @"/character/updateUserCharacterSort" // 更新用户人设排序 #define API_CHARACTER_UPDATE_USER_CHARTSORT @"/character/updateUserCharacterSort" // 更新用户人设排序
#define API_CHARACTER_DEL_USER_CHARACTER @"/character/delUserCharacter" // 删除用户人设

View File

@@ -74,6 +74,27 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
}]; }];
// 使 // 使
[self kb_reloadUserCharacters];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//
// [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// if (self.isMovingFromParentViewController || self.isBeingDismissed) {
// [self.navigationController setNavigationBarHidden:NO animated:animated];
// }
}
#pragma mark - Data
- (void)kb_reloadUserCharacters {
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
[self.viewModel fetchCharacterListByUserWithCompletion:^(NSArray<KBCharacter *> * _Nonnull characterArray, NSError * _Nullable error) { [self.viewModel fetchCharacterListByUserWithCompletion:^(NSArray<KBCharacter *> * _Nonnull characterArray, NSError * _Nullable error) {
// 使 // 使
@@ -112,23 +133,6 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
}]; }];
} }
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//
// [self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// if (self.isMovingFromParentViewController || self.isBeingDismissed) {
// [self.navigationController setNavigationBarHidden:NO animated:animated];
// }
}
#pragma mark - Data
#pragma mark - BMLongPressDragCellCollectionViewDataSource #pragma mark - BMLongPressDragCellCollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; }
@@ -148,6 +152,25 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
if (!self) { return; } if (!self) { return; }
NSIndexPath *tapIndexPath = [weakCV indexPathForCell:tappedCell]; NSIndexPath *tapIndexPath = [weakCV indexPathForCell:tappedCell];
if (!tapIndexPath) { return; } if (!tapIndexPath) { return; }
// id
NSNumber *characterId = nil;
if (tapIndexPath.section < self.dataSourceArray.count) {
NSArray *section = self.dataSourceArray[tapIndexPath.section];
if (tapIndexPath.item < section.count) {
NSDictionary *item = section[tapIndexPath.item];
id cid = item[@"id"];
if ([cid isKindOfClass:[NSNumber class]]) {
characterId = (NSNumber *)cid;
} else if ([cid isKindOfClass:[NSString class]]) {
NSString *cidStr = (NSString *)cid;
if (cidStr.length > 0) {
characterId = @([cidStr integerValue]);
}
}
}
}
[KBAlert confirmTitle:KBLocalized(@"Delete this tag?") [KBAlert confirmTitle:KBLocalized(@"Delete this tag?")
message:KBLocalized(@"This action cannot be undone") message:KBLocalized(@"This action cannot be undone")
ok:KBLocalized(@"Confirm") ok:KBLocalized(@"Confirm")
@@ -156,19 +179,37 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
cancelColor:[UIColor blackColor] cancelColor:[UIColor blackColor]
completion:^(BOOL ok) { completion:^(BOOL ok) {
if (!ok) { return; } if (!ok) { return; }
// item
// id UI
if (!characterId) {
if (tapIndexPath.section < self.dataSourceArray.count) { if (tapIndexPath.section < self.dataSourceArray.count) {
NSMutableArray *section = self.dataSourceArray[tapIndexPath.section]; NSMutableArray *section = self.dataSourceArray[tapIndexPath.section];
if (tapIndexPath.item < section.count) { if (tapIndexPath.item < section.count) {
[section removeObjectAtIndex:tapIndexPath.item]; [section removeObjectAtIndex:tapIndexPath.item];
[self.collectionView performBatchUpdates:^{ [self.collectionView performBatchUpdates:^{
[self.collectionView deleteItemsAtIndexPaths:@[tapIndexPath]]; [self.collectionView deleteItemsAtIndexPaths:@[tapIndexPath]];
} completion:^(BOOL finished) { } completion:nil];
// }
[self kb_updateUserCharacterSortWithShowHUD:NO]; }
return;
}
//
__weak typeof(self) weakSelf2 = self;
[self.viewModel deleteUserCharacterWithId:characterId
completion:^(BOOL success, NSError * _Nullable error) {
__strong typeof(weakSelf2) strongSelf = weakSelf2;
if (!strongSelf) { return; }
if (!success) {
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
[KBHUD showInfo:msg];
return;
}
// UI
[strongSelf kb_reloadUserCharacters];
}]; }];
}
}
}]; }];
}; };
return cell; return cell;

View File

@@ -16,6 +16,7 @@ typedef void(^KBCharacterListCompletion)(NSArray<KBCharacter *> *characterArray,
typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBUpLoadAvatarCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error); typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable error);
typedef void(^KBDeleteUserCharacterCompletion)(BOOL success, NSError * _Nullable error);
@interface KBMyVM : NSObject @interface KBMyVM : NSObject
@@ -27,6 +28,9 @@ typedef void(^KBUpdateCharacterSortCompletion)(BOOL success, NSError * _Nullable
/// 更新用户人设排序 /// 更新用户人设排序
- (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray - (void)updateUserCharacterSortWithSortArray:(NSArray<NSNumber *> *)sortArray
completion:(KBUpdateCharacterSortCompletion)completion; completion:(KBUpdateCharacterSortCompletion)completion;
/// 删除用户人设(/character/delUserCharacter
- (void)deleteUserCharacterWithId:(NSNumber *)characterId
completion:(KBDeleteUserCharacterCompletion)completion;
/// 上传头像 /// 上传头像

View File

@@ -97,6 +97,35 @@
}]; }];
} }
///
- (void)deleteUserCharacterWithId:(NSNumber *)characterId
completion:(KBDeleteUserCharacterCompletion)completion {
if (!characterId) {
if (completion) {
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
code:KBNetworkErrorInvalidResponse
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid parameter")}];
completion(NO, e);
}
return;
}
NSDictionary *params = @{@"id": characterId};
[KBHUD show];
[[KBNetworkManager shared] GET:API_CHARACTER_DEL_USER_CHARACTER
parameters:params
headers:nil
autoShowBusinessError:YES
completion:^(NSDictionary *jsonOrData,
NSURLResponse * _Nullable response,
NSError * _Nullable error) {
[KBHUD dismiss];
if (completion) {
completion(error == nil, error);
}
}];
}
/// ///
- (void)upLoadAvatarWithData:(NSData *)avatarData completion:(KBUpLoadAvatarCompletion)completion{ - (void)upLoadAvatarWithData:(NSData *)avatarData completion:(KBUpLoadAvatarCompletion)completion{
KBWeakSelf; KBWeakSelf;