3
This commit is contained in:
@@ -67,6 +67,63 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchRankListByTagId:(nullable NSString *)tagId
|
||||
needShow:(BOOL)needShow
|
||||
completion:(KBHomeRankCompletion)completion {
|
||||
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
||||
if (tagId.length) {
|
||||
params[@"tagId"] = tagId;
|
||||
}
|
||||
[self fetchRankListByTagParams:params
|
||||
needShow:needShow
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
// 内部辅助方法:调用 /character/listByTag
|
||||
- (void)fetchRankListByTagParams:(NSDictionary *)params
|
||||
needShow:(BOOL)needShow
|
||||
completion:(KBHomeRankCompletion)completion {
|
||||
if (needShow) {
|
||||
[KBHUD show];
|
||||
}
|
||||
|
||||
[[KBNetworkManager shared] GET:KB_API_CHARACTER_LIST_BY_TAG
|
||||
parameters:params
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary * _Nullable json, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (needShow) {
|
||||
[KBHUD dismiss];
|
||||
}
|
||||
|
||||
if (error) {
|
||||
NSString *msg = KBBizMessageFromJSONObject(json) ?: error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showInfo:msg];
|
||||
if (completion) {
|
||||
completion(nil, error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
id dataObj = json[KBData] ?: json[@"data"];
|
||||
if (![dataObj isKindOfClass:[NSArray class]]) {
|
||||
NSError *e = [NSError errorWithDomain:KBNetworkErrorDomain
|
||||
code:KBNetworkErrorInvalidResponse
|
||||
userInfo:@{NSLocalizedDescriptionKey: KBLocalized(@"Invalid response")}];
|
||||
[KBHUD showInfo:e.localizedDescription];
|
||||
if (completion) {
|
||||
completion(nil, e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSArray<KBCharacter *> *list = [KBCharacter mj_objectArrayWithKeyValuesArray:(NSArray *)dataObj];
|
||||
if (completion) {
|
||||
completion(list, nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchTagListWithParams:(nullable NSDictionary *)params
|
||||
needShow:(BOOL)needShow
|
||||
completion:(KBHomeTagCompletion)completion {
|
||||
|
||||
Reference in New Issue
Block a user