Files
yinmeng-ios/xplan-ios/Main/Login/View/LoginPasswordViewController.m

219 lines
7.6 KiB
Mathematica
Raw Normal View History

//
// 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"
///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;
@end
@implementation LoginPasswordViewController
- (LoginPasswordPresent *)createPresenter {
return [[LoginPasswordPresent alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initSubViews];
[self initSubViewConstraints];
[self initEvents];
}
2021-09-10 17:34:55 +08:00
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:NO];
}
#pragma mark - Private Method
- (void)initSubViews {
[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.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);
}];
[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 {
@weakify(self);
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 ==11 && password.length >= 6);
}] takeUntil:self.rac_willDeallocSignal];
[[self.forgetPasswordButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
2021-09-10 17:34:55 +08:00
@strongify(self);
LoginForgetPasswordViewController * forgetPasswordVC = [[LoginForgetPasswordViewController alloc] init];
[self.navigationController pushViewController:forgetPasswordVC animated:YES];
}];
///
[[self.nextButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
@strongify(self);
[self.presenter loginWithPhone:self.phoneView.textField.text password:self.codeView.textField.text];
}];
///
[[self.codeLoginButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
2021-09-10 17:34:55 +08:00
@strongify(self);
[self.navigationController popViewControllerAnimated:YES];
}];
}
#pragma mark - LoginPasswordProtocol
- (void)phoneAndPasswordLoginSuccess {
2021-09-14 15:43:18 +08:00
[self showSuccessToast:@"登录成功"];
[self.navigationController popToRootViewControllerAnimated: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:@"" size:18];
_nextButton.enabled = NO;
UIImage *disableImage = [UIImage gradientColorImageFromColors:@[[ThemeColor disableButtonBackColor],[ThemeColor disableButtonBackColor]] 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];
}
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];;
}
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];;
}
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";
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.textField.keyboardType = UIKeyboardTypeASCIICapable;
_codeView.textField.secureTextEntry = YES;
_codeView.textField.clearButtonMode = UITextFieldViewModeAlways;
}
return _codeView;
}
@end