New file |
| | |
| | | // |
| | | // LoginViewController.m |
| | | // screendisplay |
| | | // |
| | | // Created by 单军华 on 2018/7/3. |
| | | // Copyright © 2018年 单军华. All rights reserved. |
| | | // |
| | | |
| | | #import "LoginViewController.h" |
| | | #import "LoginSevice.h" |
| | | #import "CommonReqModel.h" |
| | | #import "LMJTabBarController.h" |
| | | #import "MonitoringMapViewController.h" |
| | | |
| | | @interface LoginViewController () |
| | | { |
| | | UIButton * nomalLoginBtn; |
| | | |
| | | UITextField * userPhoneTextField; |
| | | UITextField * userPwdTextFeild; |
| | | |
| | | //UIButton * forgetBtn; |
| | | } |
| | | |
| | | /** digest */ |
| | | @property (nonatomic, strong) LoginSevice *loginSevice; |
| | | |
| | | |
| | | @end |
| | | |
| | | @implementation LoginViewController |
| | | |
| | | - (void)viewDidLoad { |
| | | [super viewDidLoad]; |
| | | // Do any additional setup after loading the view. |
| | | [self setUIView]; |
| | | } |
| | | |
| | | -(void)setUIView |
| | | { |
| | | UIImageView * loginBk = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; |
| | | loginBk.image = [UIImage imageNamed:@"login_background"]; |
| | | [self.view addSubview:loginBk]; |
| | | |
| | | |
| | | UIImageView * logoPic = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(335))/2, NavBar_Height+AdaptedHeight(27), AdaptedWidth(335), AdaptedHeight(149))]; |
| | | logoPic.image = [UIImage imageNamed:@"login_app_logo"]; |
| | | [self.view addSubview:logoPic]; |
| | | |
| | | UIImageView * edit_bkimg = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2, NavBar_Height+AdaptedHeight(27+149+33), AdaptedWidth(304), AdaptedHeight(50))]; |
| | | edit_bkimg.image = [UIImage imageNamed:@"login_account_pwd_bk"]; |
| | | [self.view addSubview:edit_bkimg]; |
| | | |
| | | userPhoneTextField = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2+AdaptedWidth(40), NavBar_Height+AdaptedHeight(27+149+33), AdaptedWidth(304-40), AdaptedHeight(50))]; |
| | | userPhoneTextField.font = [UIFont fontWithName:@"Arial" size:16]; |
| | | userPhoneTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入用户名"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}]; |
| | | userPhoneTextField.delegate = self; |
| | | [userPhoneTextField setValue:RgbColor(255, 255, 255) forKeyPath:@"_placeholderLabel.textColor"]; |
| | | //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; |
| | | userPhoneTextField.textColor = RgbColor(255, 255, 255); |
| | | userPhoneTextField.keyboardType = UIKeyboardTypeDefault; |
| | | userPhoneTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; |
| | | // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 |
| | | UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(userPhoneTextField.frame.origin.x,userPhoneTextField.frame.origin.y,10.0, userPhoneTextField.frame.size.height)]; |
| | | |
| | | userPhoneTextField.leftView = blankView; |
| | | userPhoneTextField.leftViewMode =UITextFieldViewModeAlways; |
| | | [self.view addSubview:userPhoneTextField]; |
| | | |
| | | UIImageView * edit_bkimg2 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2, NavBar_Height+AdaptedHeight(27+149+33+50+33), AdaptedWidth(304), AdaptedHeight(50))]; |
| | | edit_bkimg2.image = [UIImage imageNamed:@"login_account_pwd_bk"]; |
| | | [self.view addSubview:edit_bkimg2]; |
| | | |
| | | |
| | | userPwdTextFeild = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2+AdaptedWidth(40), NavBar_Height+AdaptedHeight(27+149+33+50+33), AdaptedWidth(304-40), AdaptedHeight(50))]; |
| | | userPwdTextFeild.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入密码"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}]; |
| | | userPwdTextFeild.secureTextEntry = YES; |
| | | userPwdTextFeild.font = [UIFont fontWithName:@"Arial" size:16]; |
| | | userPwdTextFeild.delegate = self; |
| | | [userPwdTextFeild setValue:RgbColor(255, 255, 255) forKeyPath:@"_placeholderLabel.textColor"]; |
| | | //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor]; |
| | | userPwdTextFeild.textColor = RgbColor(255, 255, 255); |
| | | userPwdTextFeild.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; |
| | | // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小 |
| | | UIView *blankView2 = [[UIView alloc] initWithFrame:CGRectMake(userPwdTextFeild.frame.origin.x,userPwdTextFeild.frame.origin.y,10.0, userPwdTextFeild.frame.size.height)]; |
| | | userPwdTextFeild.leftView = blankView2; |
| | | userPwdTextFeild.leftViewMode =UITextFieldViewModeAlways; |
| | | [self.view addSubview:userPwdTextFeild]; |
| | | |
| | | nomalLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom]; |
| | | nomalLoginBtn.frame = CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2, NavBar_Height+AdaptedHeight(27+149+33+50+33+50+33), AdaptedWidth(304), AdaptedHeight(50)); |
| | | [nomalLoginBtn setBackgroundImage:[UIImage imageNamed:@"login_user_login_btnbk" ] forState:UIControlStateNormal]; |
| | | [nomalLoginBtn setTitle:@"登 录" forState:UIControlStateNormal]; |
| | | nomalLoginBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0]; |
| | | [nomalLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| | | nomalLoginBtn.layer.masksToBounds=YES; |
| | | nomalLoginBtn.layer.cornerRadius=8.0f; |
| | | [nomalLoginBtn addTarget:self action:@selector(userLogin) forControlEvents:UIControlEventTouchUpInside]; |
| | | [self.view addSubview:nomalLoginBtn]; |
| | | |
| | | // forgetBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
| | | // forgetBtn.frame = CGRectMake((SCREEN_WIDTH-120)/2, SCREEN_HEIGHT/2+225, 120, 40); |
| | | // [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal]; |
| | | // forgetBtn.titleLabel.font = [UIFont systemFontOfSize: 16.0]; |
| | | // [forgetBtn setTitleColor:kUIColorFromRGB(0x009dff) forState:UIControlStateNormal]; |
| | | // [forgetBtn addTarget:self action:@selector(registAction) forControlEvents:UIControlEventTouchUpInside]; |
| | | // [self.view addSubview:forgetBtn]; |
| | | } |
| | | |
| | | -(void)viewWillAppear:(BOOL)animated |
| | | { |
| | | [super viewWillAppear:YES]; |
| | | |
| | | self.navigationController.navigationBarHidden = YES; |
| | | |
| | | if([UserDefault stringForKey:@"isLogin"] != nil && [[UserDefault stringForKey:@"isLogin"] intValue] == 1 ) |
| | | { |
| | | // 跳转主界面 |
| | | [self getUserInfo]; |
| | | } |
| | | |
| | | } |
| | | -(void)viewDidDisappear:(BOOL)animated |
| | | { |
| | | [super viewDidDisappear:YES]; |
| | | //self.navigationController.navigationBarHidden = NO; |
| | | } |
| | | |
| | | |
| | | - (void)didReceiveMemoryWarning { |
| | | [super didReceiveMemoryWarning]; |
| | | // Dispose of any resources that can be recreated. |
| | | } |
| | | |
| | | - (LoginSevice *)loginSevice |
| | | { |
| | | if(_loginSevice == nil) { |
| | | _loginSevice = [LoginSevice new]; |
| | | } |
| | | return _loginSevice; |
| | | } |
| | | |
| | | -(void)registAction |
| | | { |
| | | |
| | | } |
| | | |
| | | -(void) userLogin |
| | | { |
| | | // 重置密码操作 |
| | | if(userPhoneTextField.text.length == 0) |
| | | { |
| | | [Global alertMessageEx:@"请输入账号." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | } |
| | | else if(userPwdTextFeild.text.length == 0) |
| | | { |
| | | [Global alertMessageEx:@"请输入登录密码." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | } |
| | | else |
| | | { |
| | | // 执行登录操作 |
| | | MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; |
| | | HUD.labelText = @"登录中..."; |
| | | // 隐藏时候从父控件中移除 |
| | | HUD.removeFromSuperViewOnHide = YES; |
| | | // YES代表需要蒙版效果 |
| | | HUD.dimBackground = YES; |
| | | |
| | | CommonReqModel * model = [[CommonReqModel alloc] init]; |
| | | [model setAccount:userPhoneTextField.text]; |
| | | [model setPassword:userPwdTextFeild.text]; |
| | | |
| | | TWWeak(self); |
| | | [self.loginSevice getLoginWithParameters:model.toDic completion:^(NSString *desc, int code) { |
| | | HUD.hidden = YES; |
| | | if(code == 1) |
| | | { |
| | | MonitoringMapViewController * page = [[MonitoringMapViewController alloc] init]; |
| | | [weakself.navigationController pushViewController:page animated:YES]; |
| | | } |
| | | else |
| | | { |
| | | [Global alertMessageEx:desc title:@"登录失败" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | } |
| | | |
| | | -(void)getUserInfo |
| | | { |
| | | CommonReqModel * model = [[CommonReqModel alloc] init]; |
| | | [model setAccount:[UserDefault stringForKey:@"accountName"]]; |
| | | [model setPassword:[UserDefault stringForKey:@"password"]]; |
| | | |
| | | TWWeak(self); |
| | | [self.loginSevice getLoginWithParameters:model.toDic completion:^(NSString *desc, int code) { |
| | | if(code == 1) |
| | | { |
| | | // 跳转主界面 |
| | | MonitoringMapViewController * page = [[MonitoringMapViewController alloc] init]; |
| | | [weakself.navigationController pushViewController:page animated:YES]; |
| | | } |
| | | else |
| | | { |
| | | [Global alertMessageEx:desc title:@"登录失败" okTtitle:nil cancelTitle:@"OK" delegate:self]; |
| | | } |
| | | }]; |
| | | } |
| | | /* |
| | | #pragma mark - Navigation |
| | | |
| | | // In a storyboard-based application, you will often want to do a little preparation before navigation |
| | | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { |
| | | // Get the new view controller using [segue destinationViewController]. |
| | | // Pass the selected object to the new view controller. |
| | | } |
| | | */ |
| | | |
| | | #pragma mark - LMJNavUIBaseViewControllerDataSource |
| | | |
| | | - (UIStatusBarStyle)navUIBaseViewControllerPreferStatusBarStyle:(LMJNavUIBaseViewController *)navUIBaseViewController |
| | | { |
| | | return UIStatusBarStyleDefault; |
| | | } |
| | | |
| | | /**头部标题*/ |
| | | - (NSMutableAttributedString*)lmjNavigationBarTitle:(LMJNavigationBar *)navigationBar |
| | | { |
| | | return nil; |
| | | } |
| | | |
| | | |
| | | /** 背景色 */ |
| | | - (UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar |
| | | { |
| | | return [UIColor clearColor]; |
| | | } |
| | | |
| | | /** 是否隐藏底部黑线 */ |
| | | - (BOOL)lmjNavigationIsHideBottomLine:(LMJNavigationBar *)navigationBar |
| | | { |
| | | return YES; |
| | | } |
| | | |
| | | /** 导航条左边的按钮 */ |
| | | - (UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar |
| | | { |
| | | |
| | | return [UIImage imageNamed:@"login_close_icon"]; |
| | | } |
| | | /** 导航条右边的按钮 */ |
| | | - (UIImage *)lmjNavigationBarRightButtonImage:(UIButton *)rightButton navigationBar:(LMJNavigationBar *)navigationBar |
| | | { |
| | | |
| | | [rightButton setEnabled:NO]; |
| | | // [rightButton setTitle:@"立即注册" forState: UIControlStateNormal]; |
| | | // [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| | | // [rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted]; |
| | | // rightButton.titleLabel.font = [UIFont systemFontOfSize:15]; |
| | | // |
| | | // rightButton.lmj_width = 80; |
| | | |
| | | return nil; |
| | | } |
| | | |
| | | |
| | | |
| | | #pragma mark - LMJNavUIBaseViewControllerDelegate |
| | | /** 左边的按钮的点击 */ |
| | | -(void)leftButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar |
| | | { |
| | | [self dismissViewControllerAnimated:YES completion:nil]; |
| | | } |
| | | |
| | | |
| | | /** 右边的按钮的点击 */ |
| | | -(void)rightButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar |
| | | { |
| | | |
| | | } |
| | | |
| | | @end |