qingqiu chegngong

This commit is contained in:
fengshuo
2024-02-24 13:49:51 +08:00
parent 990dfebf8a
commit d0f0f68e2b
69 changed files with 4861 additions and 3864 deletions

View File

@@ -7,12 +7,23 @@
import UIKit
import SnapKit
import NSObject_Rx
class AuthLoginVC: BaseViewController, HiddenNavigationBarProtocol {
var countdownSeconds = 60
var timer: Timer?
var viewModel:AuthViewModel = AuthViewModel()
var phone:String = ""
var code:String = ""
override func viewDidLoad() {
super.viewDidLoad()
loadSubViews()
viewModel.data.subscribe(onNext: { [weak self] success in
if success {
self?.startCountdown()
}
}).disposed(by: rx.disposeBag)
}
func loadSubViews() {
@@ -180,6 +191,7 @@ class AuthLoginVC: BaseViewController, HiddenNavigationBarProtocol {
button.setTitleColor(UIColor.white, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
button.addTarget(self, action: #selector(phoneLoginBtnAction), for: .touchUpInside)
button.isSelected = true
return button
}()
@@ -374,11 +386,19 @@ extension AuthLoginVC {
}
@objc func getCodeBtnAction() {
if phone.count > 0 {
viewModel.getSmsCode(phone: phone, type: 1)
} else {
HUDTool.showSuccess(with: "请输入正确的手机号码")
}
}
@objc func confirmBtnAction() {
if self.phoneLoginBtn.isSelected == true {
viewModel.authPhoneCode(phone: phone, code: code)
} else {
//TODO: id
}
}
@objc func forgetBtnAction() {
@@ -386,11 +406,21 @@ extension AuthLoginVC {
}
@objc func phoneTextFiledDidChange(_ textField: UITextField) {
if let text = textField.text {
if text.count > 11 {
textField.text = text.substring(start: 0, 11)
}
}
phone = textField.text ?? ""
}
@objc func codeTextFiledDidChange(_ textField: UITextField) {
if let text = textField.text {
if text.count > 11 {
textField.text = text.substring(start: 0, 11)
}
}
code = textField.text ?? ""
}
@objc func idTextFiledDidChange(_ textField: UITextField) {
@@ -401,3 +431,38 @@ extension AuthLoginVC {
}
}
extension AuthLoginVC {
func startCountdown() {
if timer != nil {
timer?.invalidate()
timer = nil
}
countdownSeconds = 60
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateCountdown), userInfo: nil, repeats: true)
timer!.fire()
}
@objc func updateCountdown() {
countdownSeconds -= 1
if countdownSeconds <= 0 {
getCodeBtn.setTitle("重新获取验证码", for: .normal)
getCodeBtn.isEnabled = true
stopCountdown()
return
}
getCodeBtn.isHidden = false
let seconds = countdownSeconds % 60
getCodeBtn.setTitle("重新获取验证码(\(seconds)s", for: .disabled)
getCodeBtn.isEnabled = false
}
func stopCountdown() {
timer?.invalidate()
timer = nil
}
}