Files
real-e-party-iOS/YuMi/Structure/MVP/Presenter/BaseMvpPresenter.m
2025-10-17 14:03:50 +08:00

138 lines
4.2 KiB
Objective-C

//
// BaseMvpPresenter.m
// YUMI
//
// Created by admin on 2023/3/9.
//
#import "BaseMvpPresenter.h"
#import "AccountInfoStorage.h"
#import "BaseNavigationController.h"
@interface BaseMvpPresenter()
@property (nonatomic, weak) id view;
@end
@implementation BaseMvpPresenter
- (void)attatchView:(id)view {
self.view = view;
}
- (id)getView {
return self.view;
}
- (void)logout {
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success {
return [self createHttpCompletion:success fail:nil];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success showLoading:(BOOL)loading {
return [self createHttpCompletion:success fail:nil showLoading:loading];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success errorToast:(BOOL)toast {
return [self createHttpCompletion:success fail:nil errorToast:toast];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success showLoading:(BOOL)loading errorToast:(BOOL)toast {
return [self createHttpCompletion:success fail:nil showLoading:loading errorToast:toast];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail {
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:YES];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading {
return [self createHttpCompletion:success fail:fail showLoading:loading errorToast:YES];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail errorToast:(BOOL)toast {
return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:toast];
}
- (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading errorToast:(BOOL)toast {
if (loading) {
[self.view showAnchorLoading];
}
return ^(BaseModel *data, NSInteger code, NSString * _Nullable msg) {
if (loading) {
[self.view hideHUD];
}
if (code == 200) {
success(data);
return;
}
switch (code) {
case 401: // 登录过期
[self logout];
return;
case 407:
case 408:
[self accountBanned:data];
return;
case 1415: // 未完善用户信息
[[self getView] completeUserInfo];
return;
case 3009: // 账号已注销
// [[self getView] accountCanceled:data.model2dictionary];
// return;
case 31005: {//余额不足
}
break;
case 30000: {// 青少年模式进房错误,进行弹窗处理,同时不显示 toast。
}
break;
case 10111: // 金额过大,需要先实名认证
[self.view hideHUD];
[[self getView] showRealNameAuthenticationTipsAlertView];
return;
case 10108: // 未实名认证
[self.view hideHUD];
[[self getView] showRealNameAuthenticationTipsAlertView];
return;
case 25000: {// 在青少年模式下,充值已达上限
}
}
if (toast && [self.view respondsToSelector:@selector(showErrorToast:)]) {
[self.view showErrorToast:msg];
}
if (fail) {
fail(code, msg);
}
};
}
- (void)detatchView {
}
- (void)accountBanned:(BaseModel *)data {
TTAlertConfig * config = [[TTAlertConfig alloc] init];
config.title = YMLocalizedString(@"MvpViewController6");
NSString *dateDes = [PLTimeUtil getDateWithYYMMDD:data.date];
NSString * title = [NSString stringWithFormat:YMLocalizedString(@"MvpViewController7"), data.reason,dateDes];
TTAlertMessageAttributedConfig * inviteAlertConfig = [[TTAlertMessageAttributedConfig alloc] init];
inviteAlertConfig.text = dateDes;
inviteAlertConfig.color = [DJDKMIMOMColor appMainColor];
inviteAlertConfig.font = [UIFont systemFontOfSize:15];
config.message = title;
config.messageAttributedConfig = @[inviteAlertConfig];
[TTPopup alertWithConfig:config confirmHandler:^{ } cancelHandler:^{ }];
}
- (void)tokenInvalid {
}
@end