jsdw_ios/QuickLocation/Section/Login/LoginView.swift

484 lines
16 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LoginView.swift
// QuickLocation
//
// Created by on 2026/5/26.
//
import UIKit
import RxSwift
import RxCocoa
#if !targetEnvironment(simulator)
import GeYanSdk
#endif
class LoginView: UIView {
var disposeBag = DisposeBag()
var oneTapLogin = true
private func setupRx() {
backBtn.rx.tap.subscribe(onNext: { _ in
AppRouter.shared.popOrDismiss()
}).disposed(by: disposeBag)
phoneInputTF.rx.text
.map { text -> String? in
guard let text = text else { return nil }
return String(text.prefix(11))
}.bind(to: phoneInputTF.rx.text)
.disposed(by: disposeBag)
phoneInputTF.rx.text.orEmpty.map { phone -> Bool in
if phone.count == 11 {
return true
} else {
return false
}
}
.bind(to: smsCodeBtn.rx.isEnabled)
.disposed(by: disposeBag)
}
func setupAgreementTextWithCarrier(carrier: String) {
let text = carrier.isEmpty ? "登录即同意《用户协议》和《隐私政策》" : "登录即同意\(carrier)、《隐私政策》和《用户协议》"
agreementLabel.text = text
//
let paragraphStyle = NSMutableParagraphStyle()
// lineSpacing lineHeightMultiple
paragraphStyle.lineSpacing = 4.0 //
let attributedString = NSMutableAttributedString(string: text)
attributedString.addAttributes([.foregroundColor: UIColor(hexStr: "#A4A7AE"),
.paragraphStyle: paragraphStyle], range: NSRange(location: 0, length: text.length))
attributedString.addAttributes([.foregroundColor: UIColor(hexStr: "#16B3FF"),
.link: "Carrier"],
range: (text as NSString).range(of: carrier))
attributedString.addAttributes([.foregroundColor: UIColor(hexStr: "#16B3FF"),
.link: "UserAgreement"],
range: (text as NSString).range(of: "《用户协议》"))
attributedString.addAttributes([.foregroundColor: UIColor(hexStr: "#16B3FF"),
.link: "PrivacyPolicy"],
range: (text as NSString).range(of: "《隐私政策》"))
agreementTV.attributedText = attributedString
}
private func setupUI() {
// addSubview(bgMaskImage)
addSubview(backBtn)
addSubview(guestLoginButton)
addSubview(welcomeView)
welcomeView.addSubview(welcomeLineView)
welcomeView.addSubview(welcomeLabel)
welcomeView.addSubview(welcomeTitleLab)
addSubview(inputContainerView)
inputContainerView.addSubview(phoneInputView)
inputContainerView.addSubview(smsCodeInputView)
addSubview(loginButton)
addSubview(appleLoginBtn)
addSubview(wechatLoginBtn)
addSubview(phoneLoginBtn)
addSubview(otherLoginTitleLab)
addSubview(leftSeparator)
addSubview(rightSeparator)
addSubview(agreementView)
agreementView.addSubview(checkBox)
agreementView.addSubview(agreementTV)
agreementView.addSubview(agreementLabel)
// bgMaskImage.layoutChain.edges()
backBtn.layoutChain
.top(54)
.left(15)
.width(24)
.height(24)
guestLoginButton.layoutChain
.centerY(backBtn)
.right(15)
.width(85)
.height(29)
inputContainerView.layoutChain
.centerY()
.edgesHorzontal()
welcomeView.layoutChain
.bottomToTopOfView(inputContainerView, offset: -100)
.left(38)
welcomeLineView.layoutChain
.edges(excludingEdge: .right)
.width(4)
welcomeLabel.layoutChain
.top()
.leftToRightOfView(welcomeLineView, offset: 12)
welcomeTitleLab.layoutChain
.topToBottomOfView(welcomeLabel)
.leftToView(welcomeLabel)
.right()
.bottom()
phoneInputView.layoutChain
.edges(excludingEdge: .bottom)
.edgesHorzontal(38)
.height(50)
phoneLineView.layoutChain
.left(58)
.centerY()
.width(1)
.height(25)
areaCodeLab.layoutChain
.left()
.rightToView(phoneLineView)
.centerY()
phoneInputTF.layoutChain
.leftToView(phoneLineView, offset: 13)
.right()
.edgesVertical()
smsCodeInputView.layoutChain
.topToBottomOfView(phoneInputView, offset: 20)
.leftToView(phoneInputView)
.rightToView(phoneInputView)
.heightToView(phoneInputView)
.bottom()
smsCodeBtn.layoutChain
.edgesVertical(5)
.right(5)
.width(100)
smsCodeTF.layoutChain
.edgesVertical()
.left(20)
.rightToLeftOfView(smsCodeBtn)
loginButton.layoutChain
.topToBottomOfView(inputContainerView, offset: 46)
.edgesHorzontal(30)
.height(56)
agreementView.layoutChain
.topToBottomOfView(loginButton, offset: 14)
.centerX()
.height(30)
agreementLabel.layoutChain.edges()
checkBox.layoutChain
.left()
.centerY()
.width(12)
.height(12)
agreementTV.layoutChain
.leftToRightOfView(checkBox, offset: 0)
.right()
.top()
phoneLoginBtn.layoutChain
.bottom(kSafeBottomMargin + 30)
.centerX()
.width(40)
.heightToWidth(1)
appleLoginBtn.layoutChain
.rightToLeftOfView(phoneLoginBtn, offset: -43)
.centerY(phoneLoginBtn)
.widthToView(phoneLoginBtn)
.heightToView(phoneLoginBtn)
wechatLoginBtn.layoutChain
.leftToRightOfView(phoneLoginBtn, offset: 43)
.centerY(phoneLoginBtn)
.widthToView(phoneLoginBtn)
.heightToView(phoneLoginBtn)
otherLoginTitleLab.layoutChain
.bottomToTopOfView(phoneLoginBtn, offset: -18)
.centerX()
leftSeparator.layoutChain
.centerY(otherLoginTitleLab)
.rightToLeftOfView(otherLoginTitleLab, offset: -14)
.width(60)
.height(2)
rightSeparator.layoutChain
.centerY(otherLoginTitleLab)
.leftToRightOfView(otherLoginTitleLab, offset: 14)
.widthToView(leftSeparator)
.heightToView(leftSeparator)
}
override init(frame: CGRect) {
super.init(frame: .zero)
backgroundColor = .white
setupUI()
setupRx()
setupAgreementTextWithCarrier(carrier: "")
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
leftSeparator.layoutIfNeeded()
leftSeparator.setGradientLayer(frame: leftSeparator.bounds,
startPoint: CGPoint(x: 0, y: 0.5),
endPoint: CGPoint(x: 1, y: 0.5),
colors: [UIColor(hexStr: "#D8D8D8", alpha: 0), UIColor(hexStr: "#E5E5E5")],
locations: [0, 1])
rightSeparator.layoutIfNeeded()
rightSeparator.setGradientLayer(frame: rightSeparator.bounds,
startPoint: CGPoint(x: 0, y: 0.5),
endPoint: CGPoint(x: 1, y: 0.5),
colors: [UIColor(hexStr: "#E5E5E5"), UIColor(hexStr: "#D8D8D8", alpha: 0)],
locations: [0, 1])
}
// MARK: - UI Components
lazy var bgMaskImage: UIImageView = {
let iv = UIImageView()
iv.image = UIImage(named: "Login/bg")
iv.contentMode = .scaleAspectFill
return iv
}()
lazy var backBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "Common/back"), for: .normal)
btn.extendEdgeInsets = UIEdgeInsets(top: 54, left: 15, bottom: 50, right: 50)
return btn
}()
lazy var guestLoginButton: UIButton = {
let btn = UIButton(type: .system)
btn.setTitle("游客登录", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
btn.setBackgroundImage(UIImage(named: "Login/visitor_bg"), for: .normal)
btn.isHidden = true
return btn
}()
lazy var welcomeView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var welcomeLineView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#99F2FC")
view.cornerRadius = 2
return view
}()
lazy var welcomeLabel: UILabel = {
let label = UILabel()
label.text = "欢迎登录"
label.font = .systemFont(ofSize: 18, weight: .medium)
label.textColor = .black
return label
}()
lazy var welcomeTitleLab: UILabel = {
let label = UILabel()
label.text = "极速定位"
label.font = .systemFont(ofSize: 32, weight: .bold)
label.textColor = .black
return label
}()
lazy var phoneNumberLabel: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 20, weight: .medium)
label.textColor = ThemeManager.shared.color.titleAuxColor
label.textAlignment = .center
return label
}()
lazy var carrierLabel: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 12)
label.textColor = ThemeManager.shared.color.contentColor
label.textAlignment = .center
return label
}()
//
lazy var inputContainerView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
//
lazy var phoneInputView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#F8F8F8")
view.cornerRadius = 12
view.addSubview(areaCodeLab)
view.addSubview(phoneLineView)
view.addSubview(phoneInputTF)
return view
}()
lazy var areaCodeLab: UILabel = {
let label = UILabel()
label.text = "+86"
label.font = .systemFont(ofSize: 16, weight: .medium)
label.textColor = UIColor(hexStr: "#3D3D3D")
label.textAlignment = .center
return label
}()
lazy var phoneLineView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#D8D8D8")
return view
}()
lazy var phoneInputTF: UITextField = {
let textField = UITextField()
textField.font = .systemFont(ofSize: 16, weight: .medium)
textField.placeholderColor(placeholder: "请输入手机号码",
color: UIColor(hexStr: "#767676"))
// textField.tintColor = ThemeManager.shared.color.mainColor
textField.clearButtonMode = .whileEditing
textField.keyboardType = .numberPad
return textField
}()
//
lazy var smsCodeInputView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(hexStr: "#F8F8F8")
view.cornerRadius = 12
view.addSubview(smsCodeTF)
view.addSubview(smsCodeBtn)
return view
}()
lazy var smsCodeTF: UITextField = {
let textField = UITextField()
textField.font = .systemFont(ofSize: 16, weight: .medium)
textField.placeholderColor(placeholder: "请输入验证码",
color: UIColor(hexStr: "#767676"))
textField.keyboardType = .numberPad
return textField
}()
lazy var smsCodeBtn: UIButton = {
let button = UIButton()
button.backgroundColor = .white
button.cornerRadius = 8
button.setTitle("获取验证码", for: .normal)
button.setTitleColor(UIColor(hexStr: "#1A1A1A"), for: .normal)
button.setTitleColor(UIColor(hexStr: "#767676"), for: .disabled)
button.titleLabel?.font = .systemFont(ofSize: 12, weight: .medium)
return button
}()
lazy var loginButton: UIButton = {
let btn = UIButton(type: .system)
btn.setTitle("立即登录", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal)
btn.cornerRadius = 20
return btn
}()
lazy var otherLoginTitleLab: UILabel = {
let label = UILabel()
label.text = "其他登录方式"
label.font = .systemFont(ofSize: 14, weight: .regular)
label.textColor = UIColor(hexStr: "#767676")
return label
}()
lazy var leftSeparator: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var rightSeparator: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var wechatLoginBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setBackgroundImage(UIImage(named: "Login/wechat"), for: .normal)
btn.backgroundColor = .clear
return btn
}()
lazy var appleLoginBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setBackgroundImage(UIImage(named: "Login/apple"), for: .normal)
btn.backgroundColor = .clear
return btn
}()
lazy var phoneLoginBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setBackgroundImage(UIImage(named: "Login/phone"), for: .normal)
btn.backgroundColor = .clear
return btn
}()
lazy var agreementView: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
lazy var checkBox: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "Login/checkbox"), for: .normal)
btn.setImage(UIImage(named: "Login/selected"), for: .selected)
btn.extendEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
return btn
}()
lazy var agreementLabel: UILabel = {
let label = UILabel()
label.textColor = .clear
label.numberOfLines = 1
label.textAlignment = .center
label.font = .systemFont(ofSize: 10)
return label
}()
lazy var agreementTV: UITextView = {
let textView = UITextView()
textView.font = .systemFont(ofSize: 10, weight: .medium)
textView.backgroundColor = .clear
textView.isEditable = false
textView.isScrollEnabled = false
textView.linkTextAttributes = [:]
return textView
}()
}