From 8417d34d534351cc74e2266af81a4f3f25d026c8 Mon Sep 17 00:00:00 2001 From: zu Date: Tue, 14 Sep 2021 15:43:18 +0800 Subject: [PATCH] =?UTF-8?q?XCHUDTool=E5=B0=81=E8=A3=85=E5=88=B0BaseViewCon?= =?UTF-8?q?troller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Podfile.lock | 2 +- .../Base/MVP/Presenter/BaseMvpPresenter.h | 2 ++ .../Base/MVP/Presenter/BaseMvpPresenter.m | 15 ++++++----- xplan-ios/Base/UI/BaseViewController.h | 20 ++++++++++++++ xplan-ios/Base/UI/BaseViewController.m | 17 ++++++++++++ .../Presenter/LoginForgetPasswordPresent.m | 2 +- .../Login/Presenter/LoginPasswordPresent.m | 2 +- .../Main/Login/Presenter/LoginPresenter.m | 25 ++++++++--------- .../Login/Presenter/LoginVerifCodePresent.m | 4 +-- xplan-ios/Main/Login/Protocol/LoginProtocol.h | 9 +------ .../View/LoginForgetPasswordViewController.m | 7 +++-- .../Login/View/LoginPasswordViewController.m | 3 +-- .../Login/View/LoginVerifCodeViewController.m | 3 +-- .../Main/Login/View/LoginViewController.m | 27 +++++-------------- xplan-ios/Main/Tabbar/MainPresenter.m | 2 +- 15 files changed, 78 insertions(+), 62 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 9d277c46..4e553d01 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -74,4 +74,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 82677bb54bd8940f2a6cc6f00b6eaefb58c721b7 -COCOAPODS: 1.11.0 +COCOAPODS: 1.10.1 diff --git a/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.h b/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.h index d6d64f71..05e9d40a 100644 --- a/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.h +++ b/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.h @@ -6,6 +6,7 @@ // #import +#import "BaseViewController.h" #import "BaseMvpProtocol.h" #import "HttpRequestHelper.h" @@ -18,6 +19,7 @@ typedef void(^HttpFail)(NSInteger code, NSString * _Nullable msg); - (void)attatchView:(id)view; - (id)getView; +- (BaseViewController *)getBaseVC; - (void)detatchView; - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail; - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading; diff --git a/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.m b/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.m index 65b282ec..626732a6 100644 --- a/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.m +++ b/xplan-ios/Base/MVP/Presenter/BaseMvpPresenter.m @@ -6,7 +6,6 @@ // #import "BaseMvpPresenter.h" -#import "XCHUDTool.h" @interface BaseMvpPresenter() @@ -24,8 +23,12 @@ return self.view; } +- (BaseViewController *)getBaseVC { + return ((BaseViewController *) [self getView]); +} + - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail { - return [self createHttpCompletion:success fail:fail showLoading:YES errorToast:YES]; + return [self createHttpCompletion:success fail:fail showLoading:NO errorToast:YES]; } - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail showLoading:(BOOL)loading { @@ -33,16 +36,16 @@ } - (HttpRequestHelperCompletion)createHttpCompletion:(HttpSuccess)success fail:(HttpFail)fail errorToast:(BOOL)toast { - return [self createHttpCompletion:success fail:fail showLoading:YES errorToast: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) { - [XCHUDTool showLoading]; + [[self getBaseVC] showLoading]; } return ^(BaseModel *data, NSInteger code, NSString * _Nullable msg) { if (loading) { - [XCHUDTool hideHUD]; + [[self getBaseVC] hideHUD]; } if (code == 200) { success(data); @@ -59,7 +62,7 @@ } if (toast) { - [XCHUDTool showErrorWithMessage:msg]; + [[self getBaseVC] showErrorToast:msg]; } fail(code, msg); }; diff --git a/xplan-ios/Base/UI/BaseViewController.h b/xplan-ios/Base/UI/BaseViewController.h index d845c7fd..d218e39b 100644 --- a/xplan-ios/Base/UI/BaseViewController.h +++ b/xplan-ios/Base/UI/BaseViewController.h @@ -33,6 +33,26 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)hideStatusBar; +/** + 成功 toast + */ +- (void)showSuccessToast:(NSString *)msg; + +/** + 失败 toast + */ +- (void)showErrorToast:(NSString *)msg; + +/** + 加载 loading + */ +- (void)showLoading; + +/** + 隐藏 XCHUDTool + */ +- (void)hideHUD; + @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Base/UI/BaseViewController.m b/xplan-ios/Base/UI/BaseViewController.m index 9e901758..1261a227 100644 --- a/xplan-ios/Base/UI/BaseViewController.m +++ b/xplan-ios/Base/UI/BaseViewController.m @@ -7,6 +7,7 @@ #import "BaseViewController.h" ///Tool +#import "XCHUDTool.h" #import "ThemeColor.h" @interface BaseViewController () @@ -54,5 +55,21 @@ [UIApplication sharedApplication].statusBarHidden = YES; } +- (void)showSuccessToast:(NSString *)msg { + [XCHUDTool showSuccessWithMessage:msg]; +} + +- (void)showErrorToast:(NSString *)msg { + [XCHUDTool showErrorWithMessage:msg]; +} + +- (void)showLoading { + [XCHUDTool showLoading]; +} + +- (void)hideHUD { + [XCHUDTool hideHUD]; +} + @end diff --git a/xplan-ios/Main/Login/Presenter/LoginForgetPasswordPresent.m b/xplan-ios/Main/Login/Presenter/LoginForgetPasswordPresent.m index 300f7702..7bdf8476 100644 --- a/xplan-ios/Main/Login/Presenter/LoginForgetPasswordPresent.m +++ b/xplan-ios/Main/Login/Presenter/LoginForgetPasswordPresent.m @@ -35,7 +35,7 @@ [self openCutDownWithTotal:60]; } fail:^(NSInteger code, NSString * _Nullable msg) { - } showLoading:NO errorToast:YES] mobile:phone type:[NSString stringWithFormat:@"%d", type]]; + }] mobile:phone type:[NSString stringWithFormat:@"%d", type]]; } diff --git a/xplan-ios/Main/Login/Presenter/LoginPasswordPresent.m b/xplan-ios/Main/Login/Presenter/LoginPasswordPresent.m index 06217bc7..3f86ce11 100644 --- a/xplan-ios/Main/Login/Presenter/LoginPasswordPresent.m +++ b/xplan-ios/Main/Login/Presenter/LoginPasswordPresent.m @@ -37,7 +37,7 @@ [[self getView] phoneAndPasswordLoginSuccess]; } fail:^(NSInteger code, NSString * _Nullable msg) { - }] phone:phone password:desPassword client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"]; + } showLoading:YES] phone:phone password:desPassword client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"]; } @end diff --git a/xplan-ios/Main/Login/Presenter/LoginPresenter.m b/xplan-ios/Main/Login/Presenter/LoginPresenter.m index 1f726c09..0848e922 100644 --- a/xplan-ios/Main/Login/Presenter/LoginPresenter.m +++ b/xplan-ios/Main/Login/Presenter/LoginPresenter.m @@ -13,7 +13,6 @@ #import "Api+Login.h" ///Tool #import "AccountInfoStorage.h" -#import "XCHUDTool.h" ///P #import "LoginProtocol.h" ///Model @@ -30,10 +29,10 @@ - (void)phoneQuickLogin:(NSString *)accessToken token:(NSString *)token { [Api phoneQuickLogin:[self createHttpCompletion:^(BaseModel *data) { [[AccountInfoStorage instance] saveAccountInfo:[AccountModel modelWithDictionary:data.data]]; - [[self getView] phoneQuickLoginSuccess]; + [[self getView] loginSuccess]; } fail:^(NSInteger code, NSString * _Nullable msg) { // todo fail - }] accessToken:accessToken token:token]; + } showLoading:YES] accessToken:accessToken token:token]; } @@ -81,33 +80,31 @@ NSString * givenName = [user.credential rawData][@"fullName"][@"givenName"]; userInfo.userName = [NSString stringWithFormat:@"%@%@", familyName, givenName]; } - [self thirdLOginWithopenID:openid andUnionID:unionid access_token:access_token andType:type]; + [self thirdLoginWithOpenID:openid andUnionID:unionid access_token:access_token andType:type]; } else if(state == SSDKResponseStateCancel) {///取消 - [XCHUDTool hideHUD]; - [[self getView] thirdLoginCancel]; + [[self getBaseVC] hideHUD]; + [[self getBaseVC] showErrorToast:@"登录取消"]; } else if (state == SSDKResponseStateFail) {///失败 - [XCHUDTool hideHUD]; + [[self getBaseVC] hideHUD]; if (error.description) { - [[self getView] thirdLoginFailth:error.description]; + [[self getBaseVC] showErrorToast:error.description]; } } }]; } -- (void)thirdLOginWithopenID:(NSString *)openId +- (void)thirdLoginWithOpenID:(NSString *)openId andUnionID:(NSString *)unionID access_token:(NSString *)access_token andType:(ThirdLoginType)type { - NSString * typeStr = [NSString stringWithFormat:@"%lu", type]; + NSString * typeStr = [NSString stringWithFormat:@"%lu", (unsigned long)type]; unionID = @""; [Api loginWithThirdPartWithComplction:[self createHttpCompletion:^(BaseModel * _Nonnull data) { - [XCHUDTool hideHUD]; + [[self getBaseVC] hideHUD]; AccountModel * model = [AccountModel modelWithDictionary:data.data]; if (model != nil) { [[AccountInfoStorage instance] saveAccountInfo:model]; - [[self getView] thirdLoginSuccess]; - } else { - [[self getView] thirdLoginFailth:@"登录失败"]; + [[self getView] loginSuccess]; } } fail:^(NSInteger code, NSString * _Nullable msg) { } showLoading:YES] openid:openId unionid:unionID access_token:access_token type:typeStr]; diff --git a/xplan-ios/Main/Login/Presenter/LoginVerifCodePresent.m b/xplan-ios/Main/Login/Presenter/LoginVerifCodePresent.m index 45ee1cae..81bb6786 100644 --- a/xplan-ios/Main/Login/Presenter/LoginVerifCodePresent.m +++ b/xplan-ios/Main/Login/Presenter/LoginVerifCodePresent.m @@ -35,7 +35,7 @@ [self openCutDownWithTotal:60]; } fail:^(NSInteger code, NSString * _Nullable msg) { - } showLoading:NO errorToast:YES] mobile:phone type:[NSString stringWithFormat:@"%d", type]]; + }] mobile:phone type:[NSString stringWithFormat:@"%d", type]]; } /// 使用手机号和验证码登录 @@ -50,7 +50,7 @@ [[self getView] loginSuccess]; } fail:^(NSInteger code, NSString * _Nullable msg) { - }] phone:phone code:code client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"]; + } showLoading:YES] phone:phone code:code client_secret:@"uyzjdhds" version:@"1" client_id:@"erban-client" grant_type:@"password"]; } diff --git a/xplan-ios/Main/Login/Protocol/LoginProtocol.h b/xplan-ios/Main/Login/Protocol/LoginProtocol.h index 489e8968..de411256 100644 --- a/xplan-ios/Main/Login/Protocol/LoginProtocol.h +++ b/xplan-ios/Main/Login/Protocol/LoginProtocol.h @@ -11,14 +11,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol LoginProtocol -- (void)phoneQuickLoginSuccess; - -///第三方登录取消 -- (void)thirdLoginCancel; -///第三方登录失败 -- (void)thirdLoginFailth:(NSString *)message; -///第三方登录成功 -- (void)thirdLoginSuccess; +- (void)loginSuccess; @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Login/View/LoginForgetPasswordViewController.m b/xplan-ios/Main/Login/View/LoginForgetPasswordViewController.m index 6a775aad..8ff0d101 100644 --- a/xplan-ios/Main/Login/View/LoginForgetPasswordViewController.m +++ b/xplan-ios/Main/Login/View/LoginForgetPasswordViewController.m @@ -11,7 +11,6 @@ #import ///Tool #import "ThemeColor.h" -#import "XCHUDTool.h" #import "UIImage+Utils.h" ///Presenter #import "LoginForgetPasswordPresent.h" @@ -96,7 +95,7 @@ [[self.codeView.authCodeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) { @strongify(self); if (self.phoneView.textField.text.length != 11) { - [XCHUDTool showErrorWithMessage:@"请输入正确的手机号码"]; + [self showErrorToast:@"请输入正确的手机号码"]; } else { [self.presenter phoneSmsCode:self.phoneView.textField.text type:3]; } @@ -113,7 +112,7 @@ ///请求手机号的验证码成功 - (void)phoneSmsCodeSuccess { self.codeView.authCodeButton.enabled= NO; - [XCHUDTool showSuccessWithMessage:@"验证码发送成功"]; + [self showSuccessToast:@"验证码发送成功"]; } ///倒计时进行中 - (void)countDownWithCurrent:(int)current { @@ -126,7 +125,7 @@ } ///重置密码成功 - (void)resetPasswrodSuccess { - [XCHUDTool showSuccessWithMessage:@"重置密码成功"]; + [self showSuccessToast:@"重置密码成功"]; [self.navigationController popViewControllerAnimated:YES]; } diff --git a/xplan-ios/Main/Login/View/LoginPasswordViewController.m b/xplan-ios/Main/Login/View/LoginPasswordViewController.m index fc576105..3d2bb085 100644 --- a/xplan-ios/Main/Login/View/LoginPasswordViewController.m +++ b/xplan-ios/Main/Login/View/LoginPasswordViewController.m @@ -10,7 +10,6 @@ #import #import ///Tool -#import "XCHUDTool.h" #import "UIImage+Utils.h" #import "ThemeColor.h" ///Presenter @@ -130,7 +129,7 @@ #pragma mark - LoginPasswordProtocol - (void)phoneAndPasswordLoginSuccess { - [XCHUDTool showSuccessWithMessage:@"登录成功"]; + [self showSuccessToast:@"登录成功"]; [self.navigationController popToRootViewControllerAnimated:YES]; } diff --git a/xplan-ios/Main/Login/View/LoginVerifCodeViewController.m b/xplan-ios/Main/Login/View/LoginVerifCodeViewController.m index f3c86b80..ea3faa1f 100644 --- a/xplan-ios/Main/Login/View/LoginVerifCodeViewController.m +++ b/xplan-ios/Main/Login/View/LoginVerifCodeViewController.m @@ -10,7 +10,6 @@ #import #import ///Tool -#import "XCHUDTool.h" #import "ThemeColor.h" ///Presenter #import "LoginVerifCodePresent.h" @@ -134,7 +133,7 @@ } - (void)loginSuccess { - [XCHUDTool showSuccessWithMessage:@"登录成功"]; + [self showSuccessToast:@"登录成功"]; [self.navigationController popToRootViewControllerAnimated:YES]; } diff --git a/xplan-ios/Main/Login/View/LoginViewController.m b/xplan-ios/Main/Login/View/LoginViewController.m index 4214162d..7b1160f4 100644 --- a/xplan-ios/Main/Login/View/LoginViewController.m +++ b/xplan-ios/Main/Login/View/LoginViewController.m @@ -15,7 +15,6 @@ ///Tool #import "UIImage+Utils.h" #import "GCDHelper.h" -#import "XCHUDTool.h" #import "XPMacro.h" #import "ThemeColor.h" #import "XPConstant.h" @@ -239,7 +238,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) { } - (void)phoneQuickLogin { - [XCHUDTool showLoading]; + [self showLoading]; // 在使用一键登录之前,请先调用shouldQuickLogin方法,判断当前上网卡的网络环境和运营商是否可以一键登录 @weakify(self) NTESQuickLoginManager *qlManager = [NTESQuickLoginManager sharedInstance]; @@ -281,7 +280,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) { //取消一键登录 if ([resultCode isEqualToString:@"200020"] || [resultCode isEqualToString:@"10104"]) { - [XCHUDTool hideHUD]; + [self hideHUD]; } else { [self phoneQuickLoginFail]; } @@ -293,7 +292,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) { @strongify(self) // [TTStatisticsService trackEvent:@"one_click_login_succeed" eventDescribe:@"一键登录成功"]; // // 取号成功,获取acessToken - [XCHUDTool hideHUD]; + [self hideHUD]; [self dismissViewControllerAnimated:YES completion:nil]; [self.presenter phoneQuickLogin:resultDic[@"accessToken"] token:token]; }); @@ -304,7 +303,7 @@ typedef NS_ENUM(NSUInteger, XYLoginType) { } - (void)phoneQuickLoginFail { - [XCHUDTool showErrorWithMessage:@"一键登录失败,请检查手机网络状态。"]; + [self showErrorToast:@"一键登录失败,请检查手机网络状态。"]; LoginPhoneViewController *inputPhoneVC = [[LoginPhoneViewController alloc] init]; [self.navigationController pushViewController:inputPhoneVC animated:YES]; } @@ -360,28 +359,16 @@ typedef NS_ENUM(NSUInteger, XYLoginType) { CMModel.protocolColor = [ThemeColor appMainColor]; CMModel.backActionBlock = ^{ //点击了返回按钮 - [XCHUDTool hideHUD]; + [self hideHUD]; }; dispatch_main_sync_safe(^{ [[NTESQuickLoginManager sharedInstance] setupModel:CMModel]; }); } #pragma mark - LoginProtocol -- (void)phoneQuickLoginSuccess { +- (void)loginSuccess { [self.navigationController popToRootViewControllerAnimated:YES]; -} - -- (void)thirdLoginSuccess { - [self.navigationController popToRootViewControllerAnimated:YES]; - [XCHUDTool showSuccessWithMessage:@"登录成功"]; -} - -- (void)thirdLoginCancel { - [XCHUDTool showSuccessWithMessage:@"取消登录"]; -} - -- (void)thirdLoginFailth:(NSString *)message { - [XCHUDTool showErrorWithMessage:message]; + [self showSuccessToast:@"登录成功"]; } #pragma mark - Getters And Setters diff --git a/xplan-ios/Main/Tabbar/MainPresenter.m b/xplan-ios/Main/Tabbar/MainPresenter.m index 031d7129..88b6f956 100644 --- a/xplan-ios/Main/Tabbar/MainPresenter.m +++ b/xplan-ios/Main/Tabbar/MainPresenter.m @@ -29,7 +29,7 @@ [[self getView] autoLoginSuccess]; } fail:^(NSInteger code, NSString * _Nullable msg) { - } showLoading:NO] access_token:accountModel.access_token issue_type:@"multi"]; + }] access_token:accountModel.access_token issue_type:@"multi"]; } @end