fix
无故事王国
2024-06-20 f2e891eecfac25bf6aed38c8eadfdf05704b16b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
//  LoginVC.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/5/22.
//
 
import UIKit
import QMUIKit
 
class LoginVC: BaseVC {
 
                @IBOutlet weak var btn_login: UIButton!
                @IBOutlet weak var tf_authCode: QMUITextField!
                @IBOutlet weak var tf_phone: QMUITextField!
                @IBOutlet weak var btn_isRead: UIButton!
 
                override func viewDidLoad() {
                                super.viewDidLoad()
 
                }
 
                override func setUI() {
                                super.setUI()
                }
 
                private func authInputPhone()->Bool{
                                guard !tf_phone.text!.isEmpty else {
                                                alert(msg: "请输入手机号");return false
                                }
 
                                guard tf_phone.text!.jq_isPhone else {
                                                alert(msg: "请输入正确的手机号");return false
                                }
 
                                return true
                }
 
                private func authInputCode()->Bool{
                                guard !tf_authCode.text!.isEmpty else {
                                                alert(msg: "请输入验证码");return false
                                }
 
                                guard tf_authCode.text!.count == 6 else {
                                                alert(msg: "请输入6位验证码");return false
                                }
                                return true
                }
 
                @IBAction func chooseAction(_ sender: UIButton) {
                                sender.isSelected = !sender.isSelected
                }
 
 
                /// 隐私协议
                @IBAction func privacyAction(_ sender: UIButton) {
                                let vc = CommonWebVC(type: .PrivacyPolicy)
                                vc.title = "隐私协议"
                                self.navigationController?.pushViewController(vc, animated: true)
                }
 
                /// 用户协议
                @IBAction func privacyUserAction(_ sender: UIButton) {
                                let vc = CommonWebVC(type: .UserProtocol)
                                vc.title = "用户协议"
                                self.navigationController?.pushViewController(vc, animated: true)
                }
 
 
                @IBAction func getCodeAction(_ sender: UIButton) {
                                view.endEditing(true)
                                guard authInputPhone() else {return}
                                Services.sendPhoneCode(phone: tf_phone.text!).subscribe(onNext: {_ in
                                                sender.openCountDown(60, defultTitle: "获取验证码", textColor:UIColor(hexStr: "#41A2EB"), unenableColor: .gray)
                                }).disposed(by: disposeBag)
                }
 
                @IBAction func loginAction(_ sender: UIButton) {
 
                                guard authInputPhone() else {return}
                                guard authInputCode() else {return}
 
                                guard btn_isRead.isSelected else {
                                                alert(msg: "请阅读并同意《隐私协议》《用户协议》");return
                                }
 
                                Services.login(phone: tf_phone.text!, code: tf_authCode.text!).subscribe(onNext: {result in
                                                if var token = result.data?.token{
                                                                token.request_time = Int(Date().timeIntervalSince1970)
                                                                LoginTokenModel.saveToken(token)
                                                                sceneDelegate?.loginSuccess()
                                                }
                                }).disposed(by: disposeBag)
                }
}