// // YMLoginPwdViewController.m // YUMI // // Created by XY on 2023/2/14. // #import "XPLoginPwdViewController.h" #import #import "YUMIMacroUitls.h" #import #import "XPLoginInputView.h" #import "XPLoginPwdViewController.h" #import "XPForgetPwdViewController.h" #import "LoginPasswordPresent.h" #import "LoginPasswordProtocol.h" @interface XPLoginPwdViewController () /// 密码登录 @property (nonatomic, strong) UILabel *titleLabel; /// 手机号输入框 @property (nonatomic, strong) XPLoginInputView *phoneInputView; /// 密码输入框 @property (nonatomic, strong) XPLoginInputView *pwdInputView; /// 忘记密码 @property (nonatomic, strong) UIButton *forgetBtn; /// 登录按钮 @property (nonatomic, strong) UIButton *loginBtn; /// 密码登录 @property (nonatomic, strong) UIButton *phoneLoginBtn; @end @implementation XPLoginPwdViewController - (LoginPasswordPresent *)createPresenter { return [[LoginPasswordPresent alloc] init]; } - (void)viewDidLoad { [super viewDidLoad]; [self createUI]; [self racBind]; } - (void)createUI { [self.view addSubview:self.titleLabel]; [self.view addSubview:self.phoneInputView]; [self.view addSubview:self.pwdInputView]; [self.view addSubview:self.loginBtn]; [self.view addSubview:self.phoneLoginBtn]; [self.view addSubview:self.forgetBtn]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.top.mas_equalTo(146.0/812.0*KScreenHeight); }]; [self.phoneInputView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(38); make.right.mas_equalTo(-38); make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(41); make.height.mas_equalTo(66); }]; [self.pwdInputView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.phoneInputView); make.right.mas_equalTo(self.phoneInputView); make.top.mas_equalTo(self.phoneInputView.mas_bottom).offset(16); make.height.mas_equalTo(self.phoneInputView); }]; [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.pwdInputView.mas_bottom).offset(51); make.centerX.mas_equalTo(self.view); make.width.height.mas_equalTo(96); }]; [self.phoneLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.loginBtn.mas_bottom).offset(24); make.centerX.mas_equalTo(self.view); }]; [self.forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.pwdInputView); make.top.mas_equalTo(self.pwdInputView.mas_bottom).offset(10); }]; } - (void)racBind { RAC(self.loginBtn, enabled) = [[RACSignal combineLatest:@[self.phoneInputView.inputTextField.rac_textSignal, self.pwdInputView.inputTextField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* password){ return @((phone.length > 0) && password.length >= 6); }] takeUntil:self.rac_willDeallocSignal]; } - (void)loginBtnClicked { NSString *phone = self.phoneInputView.inputTextField.text; NSString *password = self.pwdInputView.inputTextField.text; [self.presenter loginWithPhone:phone password:password]; } - (void)phoneLoginBtnClicked { [self.navigationController popViewControllerAnimated:YES]; } - (void)forgetBtnClicked { XPForgetPwdViewController *forgetVC = [[XPForgetPwdViewController alloc] init]; [self.navigationController pushViewController:forgetVC animated:YES]; } #pragma mark - LoginPasswordProtocol - (void)phoneAndPasswordLoginSuccess { [self showSuccessToast:YMLocalizedString(@"XPLoginPwdViewController0")]; UIViewController *vc = self.presentingViewController; while (vc.presentingViewController) { vc = vc.presentingViewController; } [XPAdjustEvent loginEvent]; [vc dismissViewControllerAnimated:YES completion:nil]; [self.navigationController popToRootViewControllerAnimated:NO]; } #pragma mark - 懒加载 - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.text = YMLocalizedString(@"XPLoginPwdViewController1"); _titleLabel.font = [UIFont systemFontOfSize:24 weight:UIFontWeightMedium]; _titleLabel.textColor = UIColor.whiteColor; } return _titleLabel; } - (XPLoginInputView *)phoneInputView { if (!_phoneInputView) { _phoneInputView = [[XPLoginInputView alloc] init]; _phoneInputView.areaStackView.hidden = YES; NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController2")]; [placeholder addAttribute:NSForegroundColorAttributeName value:UIColor.whiteColor range:NSMakeRange(0, placeholder.length)]; _phoneInputView.inputTextField.attributedPlaceholder = placeholder; _phoneInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad; } return _phoneInputView; } - (XPLoginInputView *)pwdInputView { if (!_pwdInputView) { _pwdInputView = [[XPLoginInputView alloc] init]; NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController3")]; [placeholder addAttribute:NSForegroundColorAttributeName value:UIColor.whiteColor range:NSMakeRange(0, placeholder.length)]; _pwdInputView.inputTextField.attributedPlaceholder = placeholder; _pwdInputView.inputTextField.keyboardType = UIKeyboardTypeAlphabet; _pwdInputView.inputTextField.secureTextEntry = YES; } return _pwdInputView; } - (UIButton *)forgetBtn { if (!_forgetBtn) { _forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_forgetBtn setTitle:YMLocalizedString(@"XPRoomRedPacketPwdView1") forState:UIControlStateNormal]; [_forgetBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _forgetBtn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular]; [_forgetBtn addTarget:self action:@selector(forgetBtnClicked) forControlEvents:UIControlEventTouchUpInside]; } return _forgetBtn; } - (UIButton *)loginBtn { if (!_loginBtn) { _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_loginBtn setImage:[UIImage imageNamed:@"login_next"] forState:UIControlStateNormal]; [_loginBtn setImage:[UIImage imageNamed:@"login_next_disable"] forState:UIControlStateDisabled]; [_loginBtn addTarget:self action:@selector(loginBtnClicked) forControlEvents:UIControlEventTouchUpInside]; } return _loginBtn; } - (UIButton *)phoneLoginBtn { if (!_phoneLoginBtn) { _phoneLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController4")]; [title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, title.length)]; [_phoneLoginBtn setAttributedTitle:title forState:UIControlStateNormal]; [_phoneLoginBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; _phoneLoginBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular]; [_phoneLoginBtn addTarget:self action:@selector(phoneLoginBtnClicked) forControlEvents:UIControlEventTouchUpInside]; } return _phoneLoginBtn; } @end