363 lines
11 KiB
Objective-C
363 lines
11 KiB
Objective-C
//
|
|
// LoginVerifCodeViewController.m
|
|
// YuMi
|
|
//
|
|
// Created by YuMi on 2021/9/8.
|
|
//
|
|
|
|
#import "LoginVerifCodeViewController.h"
|
|
///第三方
|
|
#import <Masonry/Masonry.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "CountDownHelper.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import "YUMIConstant.h"
|
|
#import "XNDJTDDLoadingTool.h"
|
|
#import "UIView+Corner.h"
|
|
#import "UIButton+EnlargeTouchArea.h"
|
|
///Presenter
|
|
#import "LoginVerifCodePresent.h"
|
|
///Protocole
|
|
#import "LoginVerifCodeProtocol.h"
|
|
///View
|
|
#import "LoginVerifCodeView.h"
|
|
#import "LoginFullInfoViewController.h"
|
|
#import "XPLoginPwdViewController.h"
|
|
|
|
@interface LoginVerifCodeViewController ()<LoginVerifCodeProtocol, CountDownHelperDelegate>
|
|
///顶部背景
|
|
@property (nonatomic,strong) UIImageView *topBackImgView;
|
|
///内容
|
|
@property (nonatomic,strong) UIView *contentView;
|
|
///标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
//背景
|
|
@property (nonatomic,strong) UIView *bgCodeView;
|
|
///容器
|
|
@property (nonatomic,strong) UIStackView *codeStackView;
|
|
///显示倒计时
|
|
@property (nonatomic,strong) UILabel *cutdownLabel;
|
|
///重新获得验证码
|
|
@property (nonatomic,strong) UIButton *retryCodeButton;
|
|
///输入密码
|
|
@property (nonatomic,strong) MSBaseTextField *textField;
|
|
///登录
|
|
@property (nonatomic,strong) UIButton *loginButton;
|
|
///返回按钮
|
|
@property (nonatomic,strong) UIButton *backBtn;
|
|
///是否验证码登录成功,登录成功后,不能再用验证码登录了,直接走下面的登录流程就可
|
|
@property (nonatomic,assign) BOOL isLoginSuccess;
|
|
///成功后登录验证码
|
|
@property (nonatomic,copy) NSString *code;
|
|
@end
|
|
|
|
@implementation LoginVerifCodeViewController
|
|
|
|
- (void)dealloc {
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (LoginVerifCodePresent *)createPresenter {
|
|
return [[LoginVerifCodePresent alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
if(self.type != VerifCodeType_AreaCode){
|
|
self.retryCodeButton.hidden = YES;
|
|
self.cutdownLabel.hidden = NO;
|
|
[[CountDownHelper shareHelper] openCountdownWithTime:60];
|
|
}else{
|
|
self.textField.keyboardType = UIKeyboardTypeDefault;
|
|
}
|
|
|
|
}
|
|
|
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
[self.view endEditing:NO];
|
|
}
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated {
|
|
[super viewDidDisappear:animated];
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
|
|
[self.view addSubview:self.topBackImgView];
|
|
[self.view addSubview:self.contentView];
|
|
|
|
|
|
if(self.type == VerifCodeType_AreaCode){
|
|
self.titleLabel.text = YMLocalizedString(@"LoginVerifCodeViewController5");
|
|
|
|
}else{
|
|
[self.topBackImgView addSubview:self.backBtn];
|
|
[CountDownHelper shareHelper].delegate = self;
|
|
}
|
|
|
|
[self.topBackImgView addSubview:self.titleLabel];
|
|
|
|
[self.contentView addSubview:self.bgCodeView];
|
|
[self.bgCodeView addSubview:self.codeStackView];
|
|
[self.codeStackView addArrangedSubview:self.textField];
|
|
[self.codeStackView addArrangedSubview:self.cutdownLabel];
|
|
[self.codeStackView addArrangedSubview:self.retryCodeButton];
|
|
[self.contentView addSubview:self.loginButton];
|
|
|
|
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.topBackImgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.top.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kGetScaleWidth(333));
|
|
}];
|
|
|
|
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.bottom.mas_equalTo(self.view);
|
|
make.top.equalTo(self.topBackImgView.mas_bottom).mas_offset(-kGetScaleWidth(30));
|
|
}];
|
|
if(self.type != VerifCodeType_AreaCode){
|
|
[self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.topBackImgView.mas_top).offset(kSafeAreaTopHeight + kGetScaleWidth(52));
|
|
make.width.height.mas_equalTo(kGetScaleWidth(20));
|
|
make.leading.mas_equalTo(kGetScaleWidth(15));
|
|
}];
|
|
}
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(self.topBackImgView).offset(kGetScaleWidth(30));
|
|
make.top.mas_equalTo(self.topBackImgView.mas_top).offset(kSafeAreaTopHeight + kGetScaleWidth(96));
|
|
}];
|
|
|
|
|
|
[self.bgCodeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(30));
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(33));
|
|
make.leading.mas_equalTo(kGetScaleWidth(33));
|
|
make.height.mas_equalTo(kGetScaleWidth(63));
|
|
}];
|
|
|
|
[self.codeStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(kGetScaleWidth(20));
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(20));
|
|
make.top.bottom.equalTo(self.bgCodeView);
|
|
}];
|
|
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_greaterThanOrEqualTo(kGetScaleWidth(190));
|
|
}];
|
|
[self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(self.contentView);
|
|
make.height.mas_equalTo(kGetScaleWidth(63));
|
|
make.width.mas_equalTo(kGetScaleWidth(165));
|
|
make.top.equalTo(self.bgCodeView.mas_bottom).mas_offset(kGetScaleWidth(50));
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
- (void)httpRequestPhoneSmsCode {
|
|
[self.presenter phoneSmsCode:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,self.phone] type:GetSmsType_Regist phoneAreaCode:self.pi_phoneAreaCode];
|
|
}
|
|
|
|
|
|
|
|
-(void)loginButtonAction{
|
|
|
|
[self.view endEditing:YES];
|
|
self.loginButton.enabled = NO;
|
|
// if(self.type == VerifCodeType_AreaCode){
|
|
// [self showLoading];
|
|
//
|
|
// return;
|
|
// }
|
|
|
|
if(self.isLoginSuccess == YES && [self.code isEqualToString:self.textField.text]){
|
|
[XNDJTDDLoadingTool showLoadingInView:self.view];
|
|
[self loginSuccess];
|
|
return;
|
|
}
|
|
self.isLoginSuccess = NO;
|
|
[XNDJTDDLoadingTool showLoadingInView:self.view];
|
|
self.code = self.textField.text;
|
|
[self.presenter loginWithPhone:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,self.phone] code:self.textField.text phoneAreaCode:self.pi_phoneAreaCode];
|
|
}
|
|
|
|
- (void)disMissVC {
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
NSMutableArray *vcList = [NSMutableArray array];
|
|
for (id vc in self.navigationController.viewControllers) {
|
|
if(![vc isKindOfClass:[XPLoginPwdViewController class]]){
|
|
[vcList addObject:vc];
|
|
}
|
|
}
|
|
self.navigationController.viewControllers = vcList;
|
|
UIViewController *vc = self.presentingViewController;
|
|
while (vc.presentingViewController) {
|
|
vc = vc.presentingViewController;
|
|
}
|
|
[vc dismissViewControllerAnimated:YES completion:nil];
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
|
}
|
|
|
|
|
|
#pragma mark - LoginVerifCodeProtocol
|
|
- (void)loginFail:(NSString *)reason{
|
|
self.loginButton.enabled = YES;
|
|
[XNDJTDDLoadingTool showLoadingInView:self.view];
|
|
}
|
|
- (void)loginSuccess {
|
|
self.isLoginSuccess = YES;
|
|
[[CountDownHelper shareHelper] stopCountDown];
|
|
[self disMissVC];
|
|
self.loginButton.enabled = YES;
|
|
}
|
|
|
|
///绑定手机号成功
|
|
- (void)bindPhoneSuccess {
|
|
[self disMissVC];
|
|
}
|
|
#pragma mark - LoginProtocol
|
|
- (void)phoneSmsCodeSuccess {
|
|
[self showSuccessToast:YMLocalizedString(@"PKIDLoginViewController11")];
|
|
self.retryCodeButton.hidden = YES;
|
|
self.cutdownLabel.hidden = NO;
|
|
[[CountDownHelper shareHelper] openCountdownWithTime:60];
|
|
}
|
|
|
|
#pragma mark - CountDownHelperDelegate
|
|
- (void)onCountdownFinish {
|
|
self.retryCodeButton.hidden = NO;
|
|
self.cutdownLabel.hidden = YES;
|
|
}
|
|
|
|
- (void)onCountdownOpen:(int)time {
|
|
self.cutdownLabel.text = [NSString stringWithFormat:@"%dS",time];
|
|
}
|
|
-(void)textFieldDidChange:(UITextField *)textField{
|
|
self.loginButton.enabled = textField.text > 0;
|
|
}
|
|
#pragma mark 重新获取验证吗
|
|
-(void)retryCodeAction{
|
|
[self httpRequestPhoneSmsCode];
|
|
}
|
|
-(void)backAction{
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
|
|
|
|
- (UILabel *)titleLabel{
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.font = [UIFont systemFontOfSize:40];
|
|
_titleLabel.textColor = [DJDKMIMOMColor mainTextColor];
|
|
_titleLabel.text = YMLocalizedString(@"LoginVerifCodeViewController3");
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UILabel *)cutdownLabel {
|
|
if (!_cutdownLabel) {
|
|
_cutdownLabel = [[UILabel alloc] init];
|
|
_cutdownLabel.textAlignment = NSTextAlignmentRight;
|
|
_cutdownLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
|
_cutdownLabel.textColor = UIColorFromRGB(0x9168FA);
|
|
_cutdownLabel.hidden = NO;
|
|
}
|
|
return _cutdownLabel;
|
|
}
|
|
-(UIView *)bgCodeView{
|
|
if (!_bgCodeView){
|
|
_bgCodeView = [UIView new];
|
|
_bgCodeView.backgroundColor = UIColorFromRGB(0xF0F5F6);
|
|
[_bgCodeView setCornerWithLeftTopCorner:kGetScaleWidth(10) rightTopCorner:kGetScaleWidth(10) bottomLeftCorner:kGetScaleWidth(10) bottomRightCorner:kGetScaleWidth(10) size:CGSizeMake(kGetScaleWidth(308), kGetScaleWidth(63))];
|
|
}
|
|
return _bgCodeView;
|
|
}
|
|
- (UIButton *)retryCodeButton {
|
|
if (!_retryCodeButton) {
|
|
_retryCodeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_retryCodeButton setTitle:YMLocalizedString(@"LoginVerifCodeViewController4") forState:UIControlStateNormal];
|
|
[_retryCodeButton setTitleColor:[DJDKMIMOMColor colorWithHexString:@"#1F1A4E"] forState:UIControlStateNormal];
|
|
_retryCodeButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
|
_retryCodeButton.hidden = YES;
|
|
[_retryCodeButton addTarget:self action:@selector(retryCodeAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _retryCodeButton;
|
|
}
|
|
- (UIImageView *)topBackImgView {
|
|
if (!_topBackImgView) {
|
|
_topBackImgView = [[UIImageView alloc] init];
|
|
_topBackImgView.userInteractionEnabled = YES;
|
|
_topBackImgView.image = [UIImage imageNamed:@"login_top_bg"];
|
|
_topBackImgView.layer.masksToBounds = YES;
|
|
_topBackImgView.contentMode = UIViewContentModeScaleAspectFill;
|
|
}
|
|
return _topBackImgView;
|
|
}
|
|
-(MSBaseTextField *)textField{
|
|
if (!_textField){
|
|
_textField = [[MSBaseTextField alloc]init];
|
|
_textField.keyboardType = UIKeyboardTypeNumberPad;
|
|
_textField.textColor = [DJDKMIMOMColor colorWithHexString:@"#1F1A4E"];
|
|
_textField.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
|
[_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
|
|
|
|
}
|
|
return _textField;
|
|
}
|
|
- (UIView *)contentView {
|
|
if (!_contentView) {
|
|
_contentView = [[UIView alloc] init];
|
|
_contentView.backgroundColor = [UIColor whiteColor];
|
|
[_contentView setCornerWithLeftTopCorner:kGetScaleWidth(25) rightTopCorner:kGetScaleWidth(25) bottomLeftCorner:0 bottomRightCorner:0 size:CGSizeMake(KScreenWidth, KScreenHeight - kGetScaleWidth(303))];
|
|
}
|
|
return _contentView;
|
|
}
|
|
- (UIButton *)loginButton {
|
|
if (!_loginButton) {
|
|
_loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_loginButton setImage:[UIImage imageNamed:@"login_finish"] forState:UIControlStateNormal];
|
|
[_loginButton addTarget:self action:@selector(loginButtonAction) forControlEvents:UIControlEventTouchUpInside];
|
|
_loginButton.enabled = NO;
|
|
}
|
|
return _loginButton;
|
|
}
|
|
|
|
- (UIStackView *)codeStackView{
|
|
if (!_codeStackView) {
|
|
_codeStackView = [[UIStackView alloc] init];
|
|
_codeStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_codeStackView.distribution = UIStackViewDistributionFillProportionally;
|
|
_codeStackView.alignment = UIStackViewAlignmentFill;
|
|
_codeStackView.spacing = 10;
|
|
}
|
|
return _codeStackView;
|
|
}
|
|
- (UIButton *)backBtn{
|
|
if (!_backBtn){
|
|
_backBtn = [UIButton new];
|
|
[_backBtn setBackgroundImage:[[UIImage imageNamed:@"common_nav_back"]ms_SetImageForRTL] forState:UIControlStateNormal];
|
|
[_backBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
[_backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _backBtn;
|
|
}
|
|
@end
|