252 lines
8.7 KiB
Objective-C
252 lines
8.7 KiB
Objective-C
//
|
|
// LoginPasswordViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/9/9.
|
|
//
|
|
|
|
#import "LoginPasswordViewController.h"
|
|
///第三方
|
|
#import <Masonry/Masonry.h>
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
///Tool
|
|
#import "UIImage+Utils.h"
|
|
#import "ThemeColor.h"
|
|
#import "XPMacro.h"
|
|
///Presenter
|
|
#import "LoginPasswordPresent.h"
|
|
#import "LoginPasswordProtocol.h"
|
|
///View
|
|
#import "LoginInputView.h"
|
|
///VC
|
|
#import "LoginForgetPasswordViewController.h"
|
|
|
|
@interface LoginPasswordViewController ()<LoginPasswordProtocol>
|
|
///验证码登录
|
|
@property (nonatomic,strong) UIButton *codeLoginButton;
|
|
///手机号是多少
|
|
@property (nonatomic,strong) UILabel *phoneLable;
|
|
///手机号
|
|
@property (nonatomic,strong) LoginInputView *phoneView;
|
|
///密码
|
|
@property (nonatomic,strong) LoginInputView *codeView;
|
|
///忘记密码
|
|
@property (nonatomic,strong) UIButton *forgetPasswordButton;
|
|
///下一步
|
|
@property (nonatomic,strong) UIButton *nextButton;
|
|
///返回按钮
|
|
@property (nonatomic,strong) UIButton *backButton;
|
|
@end
|
|
|
|
@implementation LoginPasswordViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (LoginPasswordPresent *)createPresenter {
|
|
return [[LoginPasswordPresent alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self initEvents];
|
|
}
|
|
|
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
|
[self.view endEditing:NO];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.backButton];
|
|
[self.view addSubview:self.codeLoginButton];
|
|
[self.view addSubview:self.phoneLable];
|
|
[self.view addSubview:self.phoneView];
|
|
[self.view addSubview:self.codeView];
|
|
[self.view addSubview:self.forgetPasswordButton];
|
|
[self.view addSubview:self.nextButton];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.view).mas_offset(10);
|
|
make.top.mas_equalTo(statusbarHeight);
|
|
make.height.width.mas_equalTo(44);
|
|
}];
|
|
|
|
[self.codeLoginButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.view).offset(-15);
|
|
make.bottom.mas_equalTo(self.phoneLable.mas_top).offset(-30);
|
|
}];
|
|
|
|
[self.phoneLable mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.view).offset(75 + kNavigationHeight);
|
|
}];
|
|
|
|
[self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.phoneLable.mas_bottom).offset(50);
|
|
make.left.right.mas_equalTo(self.view).inset(47);
|
|
make.height.mas_equalTo(45);
|
|
}];
|
|
|
|
[self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.height.mas_equalTo(self.phoneView);
|
|
make.top.mas_equalTo(self.phoneView.mas_bottom).offset(15);
|
|
}];
|
|
|
|
[self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(self.phoneView);
|
|
}];
|
|
|
|
//登录按钮
|
|
[self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.forgetPasswordButton.mas_bottom).offset(30);
|
|
make.left.right.mas_equalTo(self.codeView);
|
|
make.height.mas_equalTo(45);
|
|
}];
|
|
|
|
[self.forgetPasswordButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self.codeView.mas_bottom).offset(8);
|
|
make.right.mas_equalTo(self.codeView);
|
|
}];
|
|
}
|
|
|
|
- (void)initEvents {
|
|
RAC(self.nextButton, enabled) = [[RACSignal combineLatest:@[self.phoneView.textField.rac_textSignal, self.codeView.textField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* password){
|
|
return @((phone.length > 0) && password.length >= 6);
|
|
}] takeUntil:self.rac_willDeallocSignal];
|
|
}
|
|
|
|
- (void)disMissVC {
|
|
UIViewController *vc = self.presentingViewController;
|
|
while (vc.presentingViewController) {
|
|
vc = vc.presentingViewController;
|
|
}
|
|
[vc dismissViewControllerAnimated:YES completion:nil];
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
|
}
|
|
#pragma mark - LoginPasswordProtocol
|
|
- (void)phoneAndPasswordLoginSuccess {
|
|
[self showSuccessToast:@"登录成功"];
|
|
[self disMissVC];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)forgetPasswordButtonAction:(UIButton *)sender {
|
|
LoginForgetPasswordViewController * forgetPasswordVC = [[LoginForgetPasswordViewController alloc] init];
|
|
[self.navigationController pushViewController:forgetPasswordVC animated:YES];
|
|
}
|
|
|
|
- (void)nextButtonAction:(UIButton *)sender {
|
|
[self.presenter loginWithPhone:self.phoneView.textField.text password:self.codeView.textField.text];
|
|
}
|
|
|
|
- (void)codeLoginButtonAction:(UIButton *)sender {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
- (void)backButtonClick {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (UIButton *)nextButton {
|
|
if (!_nextButton) {
|
|
_nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
_nextButton.layer.masksToBounds = YES;
|
|
_nextButton.layer.cornerRadius = 45/2.f;
|
|
[_nextButton setTitle:@"下一步" forState:UIControlStateNormal];
|
|
_nextButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
|
|
_nextButton.enabled = NO;
|
|
UIImage *disableImage = [UIImage gradientColorImageFromColors:@[[ThemeColor disableButtonColor],[ThemeColor disableButtonColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
|
|
[_nextButton setBackgroundImage:disableImage forState:UIControlStateDisabled];
|
|
[_nextButton setTitleColor:[ThemeColor disableButtonTextColor] forState:UIControlStateDisabled];
|
|
UIImage *image = [UIImage gradientColorImageFromColors:@[[ThemeColor confirmButtonGradientStartColor],[ThemeColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
|
|
[_nextButton setBackgroundImage:image forState:UIControlStateNormal];
|
|
[_nextButton setTitleColor:[ThemeColor confirmButtonTextColor] forState:UIControlStateDisabled];
|
|
[_nextButton addTarget:self action:@selector(nextButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _nextButton;
|
|
}
|
|
|
|
- (UIButton *)codeLoginButton {
|
|
if (!_codeLoginButton) {
|
|
_codeLoginButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_codeLoginButton setTitle:@"验证码登录" forState:UIControlStateNormal];
|
|
[_codeLoginButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
|
|
_codeLoginButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:15];
|
|
[_codeLoginButton addTarget:self action:@selector(codeLoginButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _codeLoginButton;
|
|
}
|
|
|
|
|
|
- (UIButton *)forgetPasswordButton {
|
|
if (!_forgetPasswordButton) {
|
|
_forgetPasswordButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_forgetPasswordButton setTitle:@"忘记密码?" forState:UIControlStateNormal];
|
|
[_forgetPasswordButton setTitleColor:[ThemeColor mainTextColor] forState:UIControlStateNormal];
|
|
_forgetPasswordButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:11];
|
|
[_forgetPasswordButton addTarget:self action:@selector(forgetPasswordButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _forgetPasswordButton;
|
|
}
|
|
|
|
- (UILabel *)phoneLable{
|
|
if (!_phoneLable) {
|
|
_phoneLable = [[UILabel alloc] init];
|
|
_phoneLable.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
|
|
_phoneLable.text = @"你的手机号是多少";
|
|
_phoneLable.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _phoneLable;
|
|
}
|
|
|
|
- (LoginInputView *)phoneView {
|
|
if (!_phoneView) {
|
|
_phoneView = [[LoginInputView alloc] init];
|
|
_phoneView.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
_phoneView.layer.masksToBounds = YES;
|
|
_phoneView.layer.cornerRadius = 45/2;
|
|
_phoneView.title = @"+86";
|
|
_phoneView.maxLength = 11;
|
|
if (@available(iOS 10.0, *)) {
|
|
_phoneView.textField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
|
|
} else {
|
|
// Fallback on earlier versions
|
|
_phoneView.textField.keyboardType = UIKeyboardTypePhonePad;
|
|
}
|
|
}
|
|
return _phoneView;
|
|
}
|
|
|
|
- (LoginInputView *)codeView {
|
|
if (!_codeView) {
|
|
_codeView = [[LoginInputView alloc] init];
|
|
_codeView.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
_codeView.layer.masksToBounds = YES;
|
|
_codeView.layer.cornerRadius = 45/2;
|
|
_codeView.title = @"密码";
|
|
_codeView.maxLength = 16;
|
|
_codeView.textField.keyboardType = UIKeyboardTypeASCIICapable;
|
|
_codeView.textField.secureTextEntry = YES;
|
|
_codeView.textField.clearButtonMode = UITextFieldViewModeAlways;
|
|
}
|
|
return _codeView;
|
|
}
|
|
|
|
- (UIButton *)backButton {
|
|
if (!_backButton) {
|
|
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_backButton setImage:[UIImage imageNamed:@"common_nav_back"] forState:UIControlStateNormal];
|
|
[_backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _backButton;
|
|
}
|
|
|
|
@end
|