157 lines
5.1 KiB
Objective-C
157 lines
5.1 KiB
Objective-C
//
|
|
// BaseMvpPresenter.m
|
|
// YUMI
|
|
//
|
|
// Created by admin on 2023/3/9.
|
|
//
|
|
|
|
#import "BaseMvpPresenter.h"
|
|
#import "AccountInfoStorage.h"
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import "ClientConfig.h"
|
|
#import "LoginViewController.h"
|
|
#import "BaseNavigationController.h"
|
|
#import "FirstRechargeManager.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 {
|
|
// 1. 停止首充监控
|
|
[[FirstRechargeManager sharedManager] stopMonitoring];
|
|
|
|
// 2. 数据logout
|
|
[[AccountInfoStorage instance] saveAccountInfo:nil];
|
|
[[AccountInfoStorage instance] saveTicket:nil];
|
|
if ([NIMSDK sharedSDK].loginManager.isLogined) {
|
|
[[NIMSDK sharedSDK].loginManager logout:nil];
|
|
}
|
|
// 3. 跳登录页面
|
|
[self tokenInvalid];
|
|
// ///关闭心跳
|
|
// [[ClientConfig shareConfig] resetHeartBratTimer];
|
|
}
|
|
|
|
- (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 {
|
|
LoginViewController *loginVC = [[LoginViewController alloc] init];
|
|
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:loginVC];
|
|
nav.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
kWindow.rootViewController = nav;
|
|
}
|
|
|
|
@end
|