diff --git a/Shared/KBAPI.h b/Shared/KBAPI.h index e75fc61..5dd57cc 100644 --- a/Shared/KBAPI.h +++ b/Shared/KBAPI.h @@ -32,6 +32,7 @@ #define KB_API_FILE_UPLOAD @"/file/upload" // 上传头像 #define KB_API_CHARACTER_DETAIL @"/character/detail" // 人设详情 #define KB_API_CHARACTER_LISTBYUSER @"/character/listByUser" // 用户人设列表 +#define API_CHARACTER_UPDATE_USER_CHARTSORT @"/character/updateUserCharacterSort" // 更新用户人设排序 diff --git a/keyBoard/Class/Me/VC/KBMyKeyBoardVC.m b/keyBoard/Class/Me/VC/KBMyKeyBoardVC.m index 5e58501..67f8189 100644 --- a/keyBoard/Class/Me/VC/KBMyKeyBoardVC.m +++ b/keyBoard/Class/Me/VC/KBMyKeyBoardVC.m @@ -72,14 +72,34 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId"; make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-12); make.height.mas_equalTo(50); }]; - - // 初始数据 -// [self buildDefaultData]; + + // 使用后端真实数据初始化列表 __weak typeof(self) weakSelf = self; [self.viewModel fetchCharacterListByUserWithCompletion:^(NSArray * _Nonnull characterArray, NSError * _Nullable error) { - if (characterArray.count > 0) { - + // 请求失败或无数据时,不再使用本地测试数据,直接清空展示 + if (error || characterArray.count == 0) { + weakSelf.dataSourceArray = [NSMutableArray array]; + [weakSelf.collectionView reloadData]; + return; } + + // 将 KBCharacter 模型转换为当前列表使用的 {emoji, title} 结构 + NSMutableArray *section = [NSMutableArray arrayWithCapacity:characterArray.count]; + for (KBCharacter *c in characterArray) { + NSString *emoji = c.emoji ?: @""; + NSString *title = c.characterName ?: @""; + // 如果某条数据既没有 emoji 也没有标题,则忽略 + if (emoji.length == 0 && title.length == 0) { + continue; + } + [section addObject:@{@"emoji": emoji, @"title": title}]; + } + + weakSelf.dataSourceArray = [NSMutableArray array]; + if (section.count > 0) { + [weakSelf.dataSourceArray addObject:section]; + } + [weakSelf.collectionView reloadData]; }]; } @@ -100,59 +120,6 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId"; #pragma mark - Data -/// 构造示例数据(二维数组,仅 1 个 section) -- (void)buildDefaultData { - NSArray *arr = @[ - @{@"emoji":@"😊", @"title":@"Humor"}, - @{@"emoji":@"😄", @"title":@"Jokes"}, - @{@"emoji":@"🥰", @"title":@"Love"}, - @{@"emoji":@"🤔", @"title":@"Thinking"}, - @{@"emoji":@"🔥", @"title":@"Hot"}, - @{@"emoji":@"🎉", @"title":@"Celebrate"}, - @{@"emoji":@"🧠", @"title":@"Brainstorm"}, - @{@"emoji":@"🐱", @"title":@"Cats"}, - @{@"emoji":@"😂", @"title":@"LOL"}, - @{@"emoji":@"📸", @"title":@"Photography"}, - @{@"emoji":@"🌟", @"title":@"Star"}, - @{@"emoji":@"🍀", @"title":@"Lucky"}, - @{@"emoji":@"📚", @"title":@"Knowledge"}, - @{@"emoji":@"🎵", @"title":@"Music"}, - @{@"emoji":@"🚀", @"title":@"Launch"}, - @{@"emoji":@"😊", @"title":@"Humor"}, - @{@"emoji":@"😄", @"title":@"Jokes"}, - @{@"emoji":@"🥰", @"title":@"Love"}, - @{@"emoji":@"🤔", @"title":@"Thinking"}, - @{@"emoji":@"🔥", @"title":@"Hot"}, - @{@"emoji":@"🎉", @"title":@"Celebrate"}, - @{@"emoji":@"🧠", @"title":@"Brainstorm"}, - @{@"emoji":@"🐱", @"title":@"Cats"}, - @{@"emoji":@"😂", @"title":@"LOL"}, - @{@"emoji":@"📸", @"title":@"Photography"}, - @{@"emoji":@"🌟", @"title":@"Star"}, - @{@"emoji":@"🍀", @"title":@"Lucky"}, - @{@"emoji":@"📚", @"title":@"Knowledge"}, - @{@"emoji":@"🎵", @"title":@"Music"}, - @{@"emoji":@"🚀", @"title":@"Launch"}, - @{@"emoji":@"😊", @"title":@"Humor"}, - @{@"emoji":@"😄", @"title":@"Jokes"}, - @{@"emoji":@"🥰", @"title":@"Love"}, - @{@"emoji":@"🤔", @"title":@"Thinking"}, - @{@"emoji":@"🔥", @"title":@"Hot"}, - @{@"emoji":@"🎉", @"title":@"Celebrate"}, - @{@"emoji":@"🧠", @"title":@"Brainstorm"}, - @{@"emoji":@"🐱", @"title":@"Cats"}, - @{@"emoji":@"😂", @"title":@"LOL"}, - @{@"emoji":@"📸", @"title":@"Photography"}, - @{@"emoji":@"🌟", @"title":@"Star"}, - @{@"emoji":@"🍀", @"title":@"Lucky"}, - @{@"emoji":@"📚", @"title":@"Knowledge"}, - @{@"emoji":@"🎵", @"title":@"Music"}, - @{@"emoji":@"🚀", @"title":@"Launch"}, - ]; - self.dataSourceArray = [@[[arr mutableCopy]] mutableCopy]; - [self.collectionView reloadData]; -} - #pragma mark - BMLongPressDragCellCollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return self.dataSourceArray.count; } diff --git a/keyBoard/Class/Me/VM/KBMyVM.h b/keyBoard/Class/Me/VM/KBMyVM.h index 18b0a41..f8ad3da 100644 --- a/keyBoard/Class/Me/VM/KBMyVM.h +++ b/keyBoard/Class/Me/VM/KBMyVM.h @@ -23,6 +23,9 @@ typedef void(^KBUpdateUserInfoCompletion)(BOOL success, NSError * _Nullable erro /// 用户人设列表(/character/listByUser) - (void)fetchCharacterListByUserWithCompletion:(KBCharacterListCompletion)completion; +/// 更新用户人设排序 + + /// 上传头像 - (void)upLoadAvatarWithData:(NSData *)avatarData completion:(KBUpLoadAvatarCompletion)completion;