You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
290 lines
12 KiB
290 lines
12 KiB
![]()
2 years ago
|
//
|
||
|
// LoginViewController.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/10/8.
|
||
|
//
|
||
|
|
||
|
#import "LoginViewController.h"
|
||
|
#import "AppDelegate.h"
|
||
|
#import "EmailLoginViewController.h"
|
||
|
#import "commWebViewController.h"
|
||
|
#import "RegisterViewController.h"
|
||
|
#import <WXApi.h>
|
||
|
|
||
|
@interface LoginViewController ()<UITextViewDelegate,UIScrollViewDelegate>
|
||
|
|
||
|
|
||
|
@property (nonatomic ,strong) UIScrollView *scrollView;
|
||
|
@property (nonatomic ,strong) UIPageControl *pageControl;
|
||
|
|
||
|
/// 其他方式登录
|
||
|
@property (nonatomic ,weak) UIButton *otherBtn;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation LoginViewController
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
// Do any additional setup after loading the view.
|
||
|
self.view.backgroundColor = KKWhiteColorColor;
|
||
|
self.zx_navBarBackgroundColor = KKClearColor;
|
||
|
|
||
|
UIImageView *logoImg = [UICommon ui_imageView:CGRectZero fileName:@"login_logo"];
|
||
|
[self.view addSubview:logoImg];
|
||
|
[logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self.view);
|
||
|
make.top.equalTo(self.view).offset(Adapted(180));
|
||
|
make.height.width.mas_equalTo(Adapted(90));
|
||
|
}];
|
||
|
|
||
|
UILabel *logoName = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(17) textColor:KKTextBlackColor text:GJText(@"智慧校园") Radius:0];
|
||
|
[self.view addSubview:logoName];
|
||
|
[logoName mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.equalTo(logoImg.mas_bottom).offset(Adapted(15));
|
||
|
make.centerX.equalTo(self.view);
|
||
|
}];
|
||
|
|
||
|
|
||
|
UITextView *agreementView = [[UITextView alloc] init];
|
||
|
agreementView.backgroundColor = [UIColor clearColor];
|
||
|
agreementView.delegate = self;
|
||
|
agreementView.editable = NO;
|
||
|
agreementView.contentSize = CGSizeMake(0, 0);
|
||
|
//去除配置 可自定义链接样式
|
||
|
agreementView.linkTextAttributes = @{};
|
||
|
// lable.text = @"点击“注册”即表示你同意《用户服务协议》";
|
||
|
NSString * userAgreement = GJText(@"用户服务协议");
|
||
|
NSString * privacyPolicy = GJText(@"隐私政策");
|
||
|
NSString * allStr = [NSString stringWithFormat:GJText(@"点击登录即表示您同意%@和%@"),userAgreement,privacyPolicy];
|
||
|
NSMutableAttributedString * attributedStr = [[NSMutableAttributedString alloc] initWithString:allStr];
|
||
|
|
||
|
[attributedStr addAttribute:NSForegroundColorAttributeName value:KKMainColor range:[allStr rangeOfString:userAgreement]];
|
||
|
[attributedStr addAttribute:NSLinkAttributeName value:AccoutXieYiURLStr range:[allStr rangeOfString:userAgreement]];
|
||
|
|
||
|
[attributedStr addAttribute:NSForegroundColorAttributeName value:KKMainColor range:[allStr rangeOfString:privacyPolicy]];
|
||
|
[attributedStr addAttribute:NSLinkAttributeName value:PrivacyPolicyURLStr range:[allStr rangeOfString:privacyPolicy]];
|
||
|
|
||
|
[attributedStr addAttribute:NSForegroundColorAttributeName value:KKGrey121 range:[allStr rangeOfString:GJText(@"点击登录即表示您同意")]];
|
||
|
[attributedStr addAttribute:NSForegroundColorAttributeName value:KKGrey121 range:[allStr rangeOfString:GJText(@"和")]];
|
||
|
|
||
|
agreementView.attributedText = attributedStr;
|
||
|
agreementView.textAlignment = NSTextAlignmentCenter;
|
||
|
agreementView.font =FontADA_(10);
|
||
|
[self.view addSubview:agreementView];
|
||
|
[agreementView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self.view.mas_centerX);
|
||
|
make.bottom.equalTo(self.view.mas_bottom).inset(iPhoneX_TabbarSafeBottomMargin > 0 ? iPhoneX_TabbarSafeBottomMargin : 34);
|
||
|
make.height.offset(30);
|
||
|
make.width.offset(SCREEN_WIDTH-28);
|
||
|
}];
|
||
|
|
||
|
|
||
|
/// 邮箱登录
|
||
|
UIButton *weChatBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(15) normalColor:KKWhiteColorColor normalText:[WXApi isWXAppInstalled] ? GJText(@" 微信登录") : GJText(@"手机号登录") click:^(id x) {
|
||
|
if ([WXApi isWXAppInstalled])
|
||
|
{
|
||
|
[self WXAccredit];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
EmailLoginViewController *vc = [EmailLoginViewController new];
|
||
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
|
||
|
}
|
||
|
}];
|
||
|
if ([WXApi isWXAppInstalled])
|
||
|
[weChatBtn setImage:ImageName_(@"login_wechatBtn") forState:0];
|
||
|
weChatBtn.backgroundColor = RGB(255, 173, 1);
|
||
|
weChatBtn.layer.cornerRadius = 5;
|
||
|
weChatBtn.layer.masksToBounds = YES;
|
||
|
[self.view addSubview:weChatBtn];
|
||
|
[weChatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.bottom.equalTo(agreementView.mas_top).inset(Adapted(60));
|
||
|
make.left.right.equalTo(self.view).inset(Adapted(20));
|
||
|
make.height.mas_equalTo(Adapted(44));
|
||
|
}];
|
||
|
|
||
|
|
||
|
UIButton *otherBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKGrey143 normalText:@"其他方式登录" click:^(id x) {
|
||
|
EmailLoginViewController *vc = [EmailLoginViewController new];
|
||
|
[[UICommon currentVC].navigationController pushViewController:vc animated:YES];
|
||
|
}];
|
||
|
otherBtn.hidden = [WXApi isWXAppInstalled] ? NO : YES;
|
||
|
self.otherBtn = otherBtn;
|
||
|
[self.view addSubview:otherBtn];
|
||
|
[otherBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self.view);
|
||
|
make.top.equalTo(weChatBtn.mas_bottom).offset(20);
|
||
|
make.size.mas_equalTo(CGSizeMake(200, 30));
|
||
|
}];
|
||
|
|
||
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
||
|
if (![userDefaults objectForKey:@"启动次数"])
|
||
|
{
|
||
|
// [userDefaults setObject:@"不止一次" forKey:@"启动次数"];
|
||
|
// [userDefaults synchronize];
|
||
|
|
||
|
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
|
||
|
self.scrollView.pagingEnabled = YES;
|
||
|
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.scrollView.frame) * 4, CGRectGetHeight(self.scrollView.frame));
|
||
|
self.scrollView.delegate = self;
|
||
|
self.scrollView.showsVerticalScrollIndicator = NO;
|
||
|
self.scrollView.showsHorizontalScrollIndicator = NO;
|
||
|
self.scrollView.backgroundColor = [UIColor whiteColor];
|
||
|
|
||
|
[self.view addSubview:self.scrollView];
|
||
|
|
||
|
self.pageControl = [[UIPageControl alloc] init];
|
||
|
self.pageControl.numberOfPages = 4;
|
||
|
self.pageControl.pageIndicatorTintColor = [KKMainColor colorWithAlphaComponent:0.3];
|
||
|
self.pageControl.currentPageIndicatorTintColor = KKMainColor;
|
||
|
[self.view addSubview:self.pageControl];
|
||
|
[self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self.scrollView.mas_centerX);
|
||
|
make.bottom.equalTo(self.scrollView.mas_bottom).offset(-10);
|
||
|
}];
|
||
|
|
||
|
NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];
|
||
|
NSArray *array = [language componentsSeparatedByString:@"-"];
|
||
|
NSString *currentLanguage = array[0];
|
||
|
for (int i = 0; i < 4; i++)
|
||
|
{
|
||
|
UIImage *image = [currentLanguage isEqualToString:@"zh"] ? ImageName_(F(@"q-zh-%d", i+1)) : ImageName_(F(@"q-en-%d", i+1));
|
||
|
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.scrollView.frame) * i,
|
||
|
0,
|
||
|
CGRectGetWidth(self.scrollView.frame),
|
||
|
CGRectGetHeight(self.scrollView.frame))];
|
||
|
imageView.image = image;
|
||
|
[self.scrollView addSubview:imageView];
|
||
|
|
||
|
if (i == 3)
|
||
|
{
|
||
|
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||
|
// [btn setImage:[myHelper getImageWithName:@"立即体验按钮"] forState:UIControlStateNormal];
|
||
|
[btn setTitleColor:KKMainColor forState:UIControlStateNormal];
|
||
|
btn.frame = CGRectMake(SCREEN_WIDTH*3 + SCREEN_WIDTH/4, SCREEN_HEIGHT-45-30, SCREEN_WIDTH/2, 45);
|
||
|
[btn setTitle:GJText(@"开始体验") forState:0];
|
||
|
btn.layer.masksToBounds = YES;
|
||
|
btn.layer.cornerRadius = btn.height/2.0;
|
||
|
[btn setBackgroundColor:KKMainColor];
|
||
|
[btn setTitleColor:[UIColor whiteColor] forState:0];
|
||
|
|
||
|
[btn addTarget:self action:@selector(removeScrollView)forControlEvents:UIControlEventTouchUpInside];
|
||
|
[self.scrollView addSubview:btn];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
/// 微信登录跳转微信授权
|
||
|
- (void)WXAccredit
|
||
|
{
|
||
|
[[APHandleManager sharedManager] authorizationWachat:^(NSDictionary *authInfo) {
|
||
|
|
||
|
NSLog(@"%@",authInfo);
|
||
|
[self WXLogin:authInfo];
|
||
|
} failure:^(HandleStatus code) {
|
||
|
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#pragma mark 微信授权后调用本地微信登录解救
|
||
|
/// 微信授权后调用本地微信登录解救
|
||
|
- (void)WXLogin:(NSDictionary *)authInfo
|
||
|
{
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[parameters setValue:authInfo[@"city"] forKey:@"city"];
|
||
|
[parameters setValue:authInfo[@"country"] forKey:@"country"];
|
||
|
[parameters setValue:authInfo[@"headimgurl"] forKey:@"headimgurl"];
|
||
|
[parameters setValue:authInfo[@"nickname"] forKey:@"nickname"];
|
||
|
[parameters setValue:authInfo[@"openid"] forKey:@"openid"];
|
||
|
[parameters setValue:authInfo[@"privilege"] forKey:@"privilege"];
|
||
|
[parameters setValue:authInfo[@"province"] forKey:@"province"];
|
||
|
[parameters setValue:authInfo[@"sex"] forKey:@"sex"];
|
||
|
[parameters setValue:authInfo[@"unionid"] forKey:@"unionid"];
|
||
|
[[[APIManager sharedManager] APPOST:WechatLogin_URL parameters:parameters isJson:YES resultClass:LoginModel.class] subscribeNext:^(id _Nullable x) {
|
||
|
[UICommon HidenLoading];
|
||
|
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||
|
[app showRootViewController];
|
||
|
|
||
|
} error:^(NSError * _Nullable error) {
|
||
|
NSDictionary *dic = error.userInfo;
|
||
|
if ([dic[@"detail"] intValue] == 302)
|
||
|
{
|
||
|
RegisterViewController *vc = [[RegisterViewController alloc] init];
|
||
|
vc.navTitle = @"绑定手机号";
|
||
|
vc.isViewType = 2;
|
||
|
vc.authInfo = parameters;
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
return;
|
||
|
}
|
||
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]];
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
#pragma mark UITextViewDelegate
|
||
|
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
|
||
|
{
|
||
|
|
||
|
if ([URL.absoluteString containsString:AccoutXieYiURLStr])
|
||
|
{
|
||
|
commWebViewController *vc = [commWebViewController new];
|
||
|
vc.url = AccoutXieYiURLStr;
|
||
|
vc.navTitle = GJText(@"用户协议");
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
return NO;
|
||
|
}
|
||
|
else if ([URL.absoluteString containsString:PrivacyPolicyURLStr])
|
||
|
{
|
||
|
commWebViewController *vc = [commWebViewController new];
|
||
|
vc.url = AccoutXieYiURLStr;
|
||
|
vc.navTitle = GJText(@"隐私政策");
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
return NO;
|
||
|
}
|
||
|
return YES;
|
||
|
}
|
||
|
|
||
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||
|
{
|
||
|
int page = scrollView.contentOffset.x / scrollView.frame.size.width;
|
||
|
//NSLog(@"%d", page);
|
||
|
//NSLog(@"%f", scrollView.contentOffset.x);
|
||
|
|
||
|
// 设置页码
|
||
|
self.pageControl.currentPage = page;
|
||
|
if (/*scrollView.contentOffset.x > ScreenWidth*/ page==3 ){ // update by lsz 2021-7-23
|
||
|
[self.pageControl setHidden: YES];
|
||
|
}else{
|
||
|
[self.pageControl setHidden: NO];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)removeScrollView
|
||
|
{
|
||
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
||
|
[userDefaults setObject:@"不止一次" forKey:@"启动次数"];
|
||
|
[userDefaults synchronize];
|
||
|
[self.scrollView removeFromSuperview];
|
||
|
[self.pageControl removeFromSuperview];
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
#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.
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
@end
|