| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //
- // YRLoginVC.m
- // UU_Ent
- //
- // Created by huangyp-pc on 2019/4/29.
- // Copyright © 2019 UAS. All rights reserved.
- //
- #import "YRLoginVC.h"
- #import "YRUserInfo.h"
- #import <GRPCClient/GRPCCall+Tests.h>
- #import <UU_Ent/Account.pbrpc.h>
- #import <MBProgressHUD/MBProgressHUD.h>
- @interface YRLoginVC ()<UITextFieldDelegate>
- @property (nonatomic,strong) UIScrollView *scrollView;
- @property (nonatomic,strong) UITextField *passwordTF;
- @property (nonatomic,strong) UITextField *phoneTF;
- @property (nonatomic,strong) YRButton *loginBtn;
- @property (nonatomic,strong) UIImageView *headImageV;
- @end
- @implementation YRLoginVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- }
- #pragma mark --- 登录操作
- -(void)loginAction
- {
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
-
- [GRPCCall useInsecureConnectionsForHost:kHostAddress];
-
- AccountService *client = [[AccountService alloc]initWithHost:kHostAddress];
-
- AccountSigninRequest *request = [AccountSigninRequest message];
-
- DeviceInfo *model = [DeviceInfo new];
-
- model.os = DeviceInfo_OS_Ios;
-
- request.deviceInfo = model;
-
- request.mobile = _phoneTF.text;
-
- request.password = _passwordTF.text;
-
- [client signinWithRequest:request handler:^(AccountSigninResponse * _Nullable response, NSError * _Nullable error) {
-
- [MBProgressHUD hideHUDForView:self.view animated:YES];
-
- if (!error) {
-
- NSDictionary *resDic = response.mj_keyValues;
-
- [YRUserInfo shareManager].token = response.authedToken.token;
- [YRUserInfo shareManager].userInfo = resDic;
-
- self.completed(YES);
-
- }else{
-
-
- }
-
-
- }];
- }
- #pragma mark --- UITextField Delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [self.view endEditing:YES];
- return YES;
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
- {
- if ([string isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
- //在这里做你响应return键的代码
- [textField resignFirstResponder];
- return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
- }
-
- NSString *allText = [textField.text stringByReplacingCharactersInRange:range withString:string];
-
- [self changeRegisterBtn:allText and:textField];
-
-
- return YES;
- }
- -(BOOL)textFieldShouldClear:(UITextField *)textField
- {
- _loginBtn.enabled = NO;
- return YES;
- }
- - (void)changeRegisterBtn:(NSString *)text and:(UITextField *)textField
- {
- if (textField == _phoneTF) {
- if (_passwordTF.text.length!=0 && text.length!=0) {
- _loginBtn.enabled = YES;
- }else
- _loginBtn.enabled = NO;
- }
- if (textField == _passwordTF) {
- if (_phoneTF.text.length!=0 && text.length!=0) {
- _loginBtn.enabled = YES;
- }else
- _loginBtn.enabled = NO;
- }
-
- }
- #pragma mark --- 注意:事件类型是:`UIControlEventEditingChanged`
- -(void)passConTextChange:(id)sender{
- // UITextField* target = (UITextField*)sender;
- // if (target.text.length == 11) {
- // if ([target.text isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_LoginName]]) {
- // [g_server getHeadImageSmall:g_server.myself.userId imageView:_headImage];
- // }else{
- // _headImage.image = [UIImage imageNamed:@"UU_newPublicPic"];
- // }
- // }else{
- // _headImage.image = [UIImage imageNamed:@"UU_newPublicPic"];
- // }
- }
- -(void)pwdTextChanged:(id)sender {
- UITextField* target = (UITextField*)sender;
-
- [self changeRegisterBtn:target.text and:target];
- }
- #pragma mark --- 设置UI
- -(void)setUpUI
- {
- [self.view addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.view);
- make.width.mas_equalTo(self_width);
- make.height.mas_equalTo(self_height);
- }];
-
- UIImageView *bgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
- bgView.image = [UIImage imageNamed:@"UU_newpg5-log in"];
- [self.scrollView addSubview:bgView];
-
- [self.scrollView addSubview:self.headImageV];
-
- UIView *firstView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.headImageV.frame)+50, self_width, 50)];
- firstView.backgroundColor = [UIColor clearColor];
- [self.scrollView addSubview:firstView];
-
- UIView *secondView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(firstView.frame)+2, self_width, 50)];
- secondView.backgroundColor = [UIColor clearColor];
- [self.scrollView addSubview:secondView];
-
- UIImageView *account = [[UIImageView alloc]initWithFrame:CGRectMake(31, 15, 20, 20)];
- account.image = [UIImage imageNamed:@"UU_newLoginAccount"];
- [firstView addSubview:account];
-
- UIImageView *password = [[UIImageView alloc]initWithFrame:CGRectMake(31, 15, 20, 20)];
- password.image = [UIImage imageNamed:@"UU_newLoginPassword"];
- [secondView addSubview:password];
-
- UIImageView *line1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 48, self_width-40, 2)];
- line1.backgroundColor = HexColor(@"#939393");
- [firstView addSubview:line1];
-
- UIImageView *line2 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 48, self_width-40, 2)];
- line2.backgroundColor = HexColor(@"#939393");
- [secondView addSubview:line2];
-
- _phoneTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(account.frame)+14, 0, self_width-90, 50)];
- _phoneTF.delegate = self;
- _phoneTF.autocorrectionType = UITextAutocorrectionTypeNo;
- _phoneTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _phoneTF.enablesReturnKeyAutomatically = YES;
- _phoneTF.returnKeyType = UIReturnKeyDone;
- UIButton *button1 = [_phoneTF valueForKey:@"_clearButton"];
- [button1 setImage:[UIImage imageNamed:@"UU_newDELETE"] forState:UIControlStateNormal];
- _phoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- _phoneTF.placeholder = @"登录";
- _phoneTF.userInteractionEnabled = YES;
- _phoneTF.backgroundColor = [UIColor clearColor];
- _phoneTF.textColor = HexColor(@"#FFFFFF");
- _phoneTF.keyboardType = UIKeyboardTypeNumberPad;
- _phoneTF.font = [UIFont systemFontOfSize:18];
- [_phoneTF setValue:HexColor(@"#FFFFFF") forKeyPath:@"_placeholderLabel.textColor"];
- [firstView addSubview:_phoneTF];
- [_phoneTF addTarget:self action:@selector(passConTextChange:) forControlEvents:UIControlEventEditingChanged];
- _phoneTF.text = @"15018524229";
-
- _passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(password.frame)+14, 0, self_width-90, 50)];
- _passwordTF.delegate = self;
- _passwordTF.autocorrectionType = UITextAutocorrectionTypeNo;
- _passwordTF.autocapitalizationType = UITextAutocapitalizationTypeNone;
- _passwordTF.enablesReturnKeyAutomatically = YES;
- _passwordTF.returnKeyType = UIReturnKeyDone;
- UIButton *button2 = [_passwordTF valueForKey:@"_clearButton"];
- [button2 setImage:[UIImage imageNamed:@"UU_newDELETE"] forState:UIControlStateNormal];
- _passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
- _passwordTF.placeholder = @"密码";
- _passwordTF.secureTextEntry = YES;
- _passwordTF.userInteractionEnabled = YES;
- _passwordTF.backgroundColor = [UIColor clearColor];
- _passwordTF.textColor = HexColor(@"#FFFFFF");
- _passwordTF.font = [UIFont systemFontOfSize:18];
- [_passwordTF setValue:HexColor(@"#FFFFFF") forKeyPath:@"_placeholderLabel.textColor"];
- [secondView addSubview:_passwordTF];
- [_passwordTF addTarget:self action:@selector(pwdTextChanged:) forControlEvents:UIControlEventAllEditingEvents|UIControlEventValueChanged];
- _passwordTF.text = @"111111";
-
- self.loginBtn = [[YRButton alloc]initWithTitle:@"登录" titleColor:nil titleFont:18 buttonNormalColor:nil buttonSelectColor:nil buttonDiabledColor:nil];
- self.loginBtn.frame = CGRectMake(20, CGRectGetMaxY(secondView.frame)+25, self_width-40, 40);
- [self.scrollView addSubview:self.loginBtn];
- [self.loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
- }
- #pragma mark --- lazy
- -(UIScrollView *)scrollView{
- if (!_scrollView) {
- _scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
- _scrollView.backgroundColor = [UIColor redColor];
- }
- return _scrollView;
- }
- -(UIImageView *)headImageV
- {
- if (!_headImageV) {
- _headImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 70, 70)];
- _headImageV.layer.masksToBounds = YES;
- _headImageV.layer.cornerRadius = 35;
- _headImageV.layer.borderColor = [UIColor whiteColor].CGColor;
- _headImageV.layer.borderWidth = 3;
- _headImageV.center = CGPointMake(self_width/2, 81);
- }
- return _headImageV;
- }
- @end
|