Files
peko-ios/YuMi/Modules/YMLogin/View/NewLogin/XPLoginPhoneViewController.m
2023-08-17 16:10:11 +08:00

446 lines
18 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// YMLoginPhoneViewController.m
// YUMI
//
// Created by XY on 2023/2/13.
//
#import "XPLoginPhoneViewController.h"
#import <Masonry.h>
#import "YUMIMacroUitls.h"
#import <ReactiveObjC.h>
#import "XPLoginInputView.h"
#import "XPLoginPwdViewController.h"
#import "XPLoginAraeViewController.h"
#import "LoginVerifCodePresent.h"
#import "LoginVerifCodeProtocol.h"
#import "XPForgetPwdViewController.h"
@interface XPLoginPhoneViewController ()<XPLoginInputViewDelegate, LoginVerifCodeProtocol, XPLoginAraeViewControllerDelegate>
///背景
@property(nonatomic,strong) UIImageView *bgImageView;
///返回
@property(nonatomic,strong) UIButton *backBnt;
/// 手机号登录
@property (nonatomic, strong) UILabel *titleLabel;
/// 未注册的手机号自动登录
@property (nonatomic, strong) UILabel *despLabel;
///选择类型背景
@property(nonatomic,strong) UIImageView *chooseTypeView;
///选择手机登录
@property(nonatomic,strong) UIButton *choosePhoneBtn;
///选择密码登录
@property(nonatomic,strong) UIButton *choosePsdBtn;
/// 手机号输入框
@property (nonatomic, strong) XPLoginInputView *phoneInputView;
/// 验证码输入框
@property (nonatomic, strong) XPLoginInputView *codeInputView;
///// 账号登录手机号输入框
@property (nonatomic, strong) XPLoginInputView *accountView;
/// 账号登录密码输入框
@property (nonatomic, strong) XPLoginInputView *accountPwdView;
/// 忘记密码
@property (nonatomic, strong) UIButton *forgetBtn;
/// 登录按钮
@property (nonatomic, strong) UIButton *loginBtn;
///区号
@property (nonatomic,copy) NSString *pi_phoneAreaCode;
///类型,0密码1.手机
@property(nonatomic,assign) int selectType;
@end
@implementation XPLoginPhoneViewController
- (BOOL)isHiddenNavBar {
return YES;
}
- (LoginVerifCodePresent *)createPresenter {
return [[LoginVerifCodePresent alloc] init];
}
- (void)viewDidLoad {
self.selectType = 0;
self.pi_phoneAreaCode = @"852";
[super viewDidLoad];
[self createUI];
[self racBind];
}
- (void)createUI {
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.bgImageView];
[self.view addSubview:self.backBnt];
[self.view addSubview:self.titleLabel];
[self.view addSubview:self.chooseTypeView];
[self.chooseTypeView addSubview:self.choosePhoneBtn];
[self.chooseTypeView addSubview:self.choosePsdBtn];
UIView *bgView = [UIView new];
bgView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:bgView];
[self.view addSubview:self.phoneInputView];
[self.view addSubview:self.codeInputView];
[self.view addSubview:self.accountView];
[self.view addSubview:self.accountPwdView];
[self.view addSubview:self.forgetBtn];
[self.view addSubview:self.loginBtn];
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(418));
}];
[self.backBnt mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(kGetScaleWidth(20));
make.width.mas_equalTo(kGetScaleWidth(28));
make.height.mas_equalTo(kGetScaleWidth(28));
make.top.mas_equalTo(kGetScaleWidth(52));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.top.equalTo(self.backBnt.mas_bottom).mas_offset(kGetScaleWidth(48));
make.leading.mas_equalTo(kGetScaleWidth(24));
make.height.mas_equalTo(kGetScaleWidth(40));
}];
[self.chooseTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(kGetScaleWidth(24));
make.left.right.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(65));
}];
[self.choosePsdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(16));
make.height.mas_equalTo(kGetScaleWidth(22));
make.width.mas_equalTo(KScreenWidth/2);
make.left.mas_equalTo(0);
}];
[self.choosePhoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(16));
make.height.mas_equalTo(kGetScaleWidth(22));
make.width.mas_equalTo(KScreenWidth/2);
make.right.mas_equalTo(0);
}];
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self.view);
make.top.equalTo(self.chooseTypeView.mas_bottom);
}];
[self.phoneInputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.chooseTypeView.mas_bottom).offset(kGetScaleWidth(39));
make.height.mas_equalTo(kGetScaleWidth(52));
}];
[self.codeInputView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.mas_equalTo(kGetScaleWidth(303));
make.top.mas_equalTo(self.phoneInputView.mas_bottom).offset(kGetScaleWidth(20));
make.height.mas_equalTo(kGetScaleWidth(52));
}];
[self.accountView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.phoneInputView);
}];
[self.accountPwdView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.codeInputView);
}];
[self.forgetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-kGetScaleWidth(52));
make.height.mas_equalTo(kGetScaleWidth(17));
make.top.equalTo(self.accountPwdView.mas_bottom).mas_offset(kGetScaleWidth(8));
}];
[self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.codeInputView.mas_bottom).offset(kGetScaleWidth(48));
make.centerX.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(48));
make.width.mas_equalTo(kGetScaleWidth(303));
}];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
- (void)racBind {
@weakify(self);
RAC(self.loginBtn, enabled) = [[RACSignal combineLatest:@[self.phoneInputView.inputTextField.rac_textSignal, self.codeInputView.inputTextField.rac_textSignal,self.accountView.inputTextField.rac_textSignal,self.accountPwdView.inputTextField.rac_textSignal] reduce:^id _Nonnull(NSString *phone, NSString* smsCode,NSString *account,NSString *accountPwd){
@strongify(self);
if(self.selectType == 0){
return @((account.length > 0) && accountPwd.length >= 6);
}
return @((phone.length > 0) && smsCode.length >= 5);
}] takeUntil:self.rac_willDeallocSignal];
}
/// 登录
- (void)loginBtnClicked {
[XNDJTDDLoadingTool showOnlyView:self.view];
if(self.selectType == 0){
NSString *phone = self.accountView.inputTextField.text;
NSString *password = self.accountPwdView.inputTextField.text;
[self.presenter loginWithPhone:phone password:password];
return;
}
NSString *phone = self.phoneInputView.inputTextField.text;
NSString *smsCode = self.codeInputView.inputTextField.text;
NSString * phoneStr = [NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode, phone];
[self.presenter loginWithPhone:phoneStr code:smsCode phoneAreaCode:self.pi_phoneAreaCode];
}
- (void)forgetBtnClicked {
XPForgetPwdViewController *forgetVC = [[XPForgetPwdViewController alloc] init];
[self.navigationController pushViewController:forgetVC animated:YES];
}
#pragma mark - XPLoginInputViewDelegate
- (void)smsCodeAction {
NSString *phone = self.phoneInputView.inputTextField.text;
if (phone.length == 0 ) {
[self showErrorToast:YMLocalizedString(@"XPLoginPhoneViewController0")];
return;
}
[self.presenter phoneSmsCode:[NSString stringWithFormat:@"%@%@",self.pi_phoneAreaCode,phone] type:GetSmsType_Regist phoneAreaCode:self.pi_phoneAreaCode];
}
- (void)areaListAction {
XPLoginAraeViewController *codeVC = [XPLoginAraeViewController new];
codeVC.delegate = self;
[self.navigationController pushViewController:codeVC animated:YES];
}
- (void)chooseAreaCodeSuccess:(NSString *)code {
if (code.length > 0) {
self.pi_phoneAreaCode = code;
[self.phoneInputView.areaCodeBtn setTitle:[NSString stringWithFormat:@"+%@", code] forState:UIControlStateNormal];
}
}
#pragma mark - LoginVerifCodeProtocol
- (void)loginWithPhoenSuccess{
[XNDJTDDLoadingTool hideOnlyView:self.view];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"kLoginSuccessType"];
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController1")];
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
}
- (void)loginSuccess {
[XNDJTDDLoadingTool hideOnlyView:self.view];
[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"kLoginSuccessType"];
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController1")];
UIViewController *vc = self.presentingViewController;
while (vc.presentingViewController) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popToRootViewControllerAnimated:NO];
}
- (void)loginFail{
[XNDJTDDLoadingTool hideOnlyView:self.view];
}
-(void)backViewAction{
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - LoginProtocol
- (void)phoneSmsCodeSuccess {
[self showSuccessToast:YMLocalizedString(@"XPLoginPhoneViewController2")];
[self.codeInputView fireTimer];
}
-(void)setSelectType:(int)selectType{
_selectType = selectType;
_chooseTypeView.image = _selectType == 0 ? kImage(@"login_choose_phone_bg"): kImage(@"login_choose_pwd_bg");
_choosePhoneBtn.selected = _selectType != 0;
_choosePsdBtn.selected = _selectType == 0;
_forgetBtn.hidden = _selectType != 0;
_phoneInputView.hidden = _selectType == 0;
_codeInputView.hidden = _selectType == 0;
_accountView.hidden = _selectType != 0;
_accountPwdView.hidden = _selectType != 0;
}
-(void)choosePhoneAction{
self.selectType = 1;
}
-(void)choosePwdAction{
self.selectType = 0;
}
#pragma mark - 懒加载
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = @"Welcome to Piko";
_titleLabel.font = kFontBold(28);
_titleLabel.textColor = UIColorFromRGB(0x1F1B4F);
}
return _titleLabel;
}
- (UILabel *)despLabel {
if (!_despLabel) {
_despLabel = [[UILabel alloc] init];
_despLabel.text = YMLocalizedString(@"XPLoginPhoneViewController4");
_despLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
_despLabel.textColor = [UIColor.whiteColor colorWithAlphaComponent:0.6];
}
return _despLabel;
}
- (XPLoginInputView *)phoneInputView {
if (!_phoneInputView) {
_phoneInputView = [[XPLoginInputView alloc] init];
_phoneInputView.areaStackView.hidden = NO;
_phoneInputView.delegate = self;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPhoneViewController5")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_phoneInputView.inputTextField.attributedPlaceholder = placeholder;
_phoneInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
_phoneInputView.hidden = YES;
}
return _phoneInputView;
}
- (XPLoginInputView *)codeInputView {
if (!_codeInputView) {
_codeInputView = [[XPLoginInputView alloc] init];
_codeInputView.smsCodeBtn.hidden = NO;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPhoneViewController6")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_codeInputView.inputTextField.attributedPlaceholder = placeholder;
_codeInputView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
_codeInputView.delegate = self;
_codeInputView.hidden = YES;
}
return _codeInputView;
}
- (UIButton *)loginBtn {
if (!_loginBtn) {
_loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *nextImage = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(303), kGetScaleWidth(48))];
UIImage *disableImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xD1F9FF),UIColorFromRGB(0xDEE4FF),UIColorFromRGB(0xEEDCFF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(303), kGetScaleWidth(48))];
[_loginBtn setImage:nextImage forState:UIControlStateNormal];
[_loginBtn setImage:disableImage forState:UIControlStateDisabled];
_loginBtn.layer.cornerRadius = kGetScaleWidth(48)/2;
_loginBtn.layer.masksToBounds = YES;
UILabel *titleView = [UILabel labelInitWithText:YMLocalizedString(@"XPLoginPhoneViewController8") font:kFontMedium(16) textColor:[UIColor whiteColor]];
titleView.textAlignment = NSTextAlignmentCenter;
[_loginBtn addSubview:titleView];
[titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.loginBtn);
}];
[_loginBtn addTarget:self action:@selector(loginBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _loginBtn;
}
- (UIImageView *)bgImageView{
if(!_bgImageView){
_bgImageView = [[UIImageView alloc]init];
_bgImageView.image = kImage(@"login_phone_pwd_bg");
_bgImageView.contentMode = 2;
}
return _bgImageView;
}
- (UIButton *)backBnt{
if(!_backBnt){
_backBnt = [UIButton new];
[_backBnt setImage:kImage(@"common_nav_back") forState:UIControlStateNormal];
[_backBnt addTarget:self action:@selector(backViewAction) forControlEvents:UIControlEventTouchUpInside];
[_backBnt setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _backBnt;
}
- (UIImageView *)chooseTypeView{
if(!_chooseTypeView){
_chooseTypeView = [UIImageView new];
_chooseTypeView.userInteractionEnabled = YES;
[_chooseTypeView setImage:kImage(@"login_choose_phone_bg")];
}
return _chooseTypeView;
}
- (UIButton *)choosePhoneBtn{
if(!_choosePhoneBtn){
_choosePhoneBtn = [UIButton new];
[_choosePhoneBtn setTitle:YMLocalizedString(@"XPLoginPhoneViewController10" ) forState:UIControlStateNormal];
[_choosePhoneBtn setTitleColor:UIColorFromRGB(0x6D6B89) forState:UIControlStateNormal];
[_choosePhoneBtn setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
_choosePhoneBtn.titleLabel.font = kFontSemibold(16);
[ _choosePhoneBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_choosePhoneBtn addTarget:self action:@selector(choosePhoneAction) forControlEvents:UIControlEventTouchUpInside];
}
return _choosePhoneBtn;
}
- (UIButton *)choosePsdBtn{
if(!_choosePsdBtn){
_choosePsdBtn = [UIButton new];
[_choosePsdBtn setTitle:YMLocalizedString(@"XPLoginPhoneViewController9") forState:UIControlStateNormal];
[_choosePsdBtn setTitleColor:UIColorFromRGB(0x6D6B89) forState:UIControlStateNormal];
[_choosePsdBtn setTitleColor:UIColorFromRGB(0x1F1B4F) forState:UIControlStateSelected];
_choosePsdBtn.titleLabel.font = kFontSemibold(16);
[_choosePsdBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_choosePsdBtn addTarget:self action:@selector(choosePwdAction) forControlEvents:UIControlEventTouchUpInside];
_choosePsdBtn.selected = YES;
}
return _choosePsdBtn;
}
- (XPLoginInputView *)accountView {
if (!_accountView) {
_accountView = [[XPLoginInputView alloc] init];
_accountView.areaStackView.hidden = YES;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController2")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_accountView.inputTextField.attributedPlaceholder = placeholder;
_accountView.inputTextField.keyboardType = UIKeyboardTypeNumberPad;
}
return _accountView;
}
- (XPLoginInputView *)accountPwdView {
if (!_accountPwdView) {
_accountPwdView = [[XPLoginInputView alloc] init];
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginPwdViewController3")];
[placeholder addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xB3B3C3) range:NSMakeRange(0, placeholder.length)];
_accountPwdView.inputTextField.attributedPlaceholder = placeholder;
_accountPwdView.inputTextField.keyboardType = UIKeyboardTypeAlphabet;
_accountPwdView.inputTextField.secureTextEntry = YES;
}
return _accountPwdView;
}
- (UIButton *)forgetBtn {
if (!_forgetBtn) {
_forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_forgetBtn setTitle:YMLocalizedString(@"XPRoomRedPacketPwdView1") forState:UIControlStateNormal];
[_forgetBtn setTitleColor:UIColorFromRGB(0xB3B3C3) forState:UIControlStateNormal];
_forgetBtn.titleLabel.font = kFontRegular(12);
[_forgetBtn addTarget:self action:@selector(forgetBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
return _forgetBtn;
}
@end