280 lines
8.5 KiB
Swift
280 lines
8.5 KiB
Swift
//
|
||
// SignInView.swift
|
||
// QuickLocation
|
||
//
|
||
// Created by 八条 on 2026/6/17.
|
||
//
|
||
|
||
import UIKit
|
||
import RxSwift
|
||
import RxCocoa
|
||
import Lottie
|
||
import CoreLocation
|
||
|
||
class SignInView: UIView {
|
||
|
||
var disposeBag = DisposeBag()
|
||
|
||
func setupData(_ model: SignInModel) {
|
||
|
||
signInTextImg.image = UIImage(named: model.signInStatus == 1 ? "SignIn/today_text" : "SignIn/signIn_text")
|
||
|
||
let text = "已连续签到\(model.signCount)天"
|
||
let attr = NSMutableAttributedString(string: text)
|
||
let range = (text as NSString).range(of: model.signCount.string)
|
||
attr.addAttribute(.foregroundColor, value: UIColor(hexStr: "#FF8B39"), range: range)
|
||
signInDaysLab.attributedText = attr
|
||
}
|
||
|
||
/// 签到按钮回调
|
||
var onSignInTap: ((CLLocationCoordinate2D?) -> Void)?
|
||
/// 当前坐标(由 VC 传入)
|
||
var currentCoordinate: CLLocationCoordinate2D?
|
||
|
||
private func setupRx() {
|
||
backBtn.rx.tap.subscribe(onNext: { _ in
|
||
AppRouter.shared.popOrDismiss()
|
||
}).disposed(by: disposeBag)
|
||
|
||
|
||
}
|
||
|
||
private func setupUI() {
|
||
addSubview(navBgView)
|
||
addSubview(navBarView)
|
||
navBarView.addSubview(navTitleLabel)
|
||
navBarView.addSubview(backBtn)
|
||
|
||
addSubview(emailView)
|
||
addSubview(signInLottieView)
|
||
addSubview(signInTextImg)
|
||
addSubview(signInDaysLab)
|
||
addSubview(tipsView)
|
||
addSubview(agreementTV)
|
||
|
||
navBgView.layoutChain
|
||
.edges(excludingEdge: .bottom)
|
||
.heightToWidth(160/375)
|
||
|
||
navBarView.layoutChain
|
||
.edges(excludingEdge: .bottom)
|
||
.height(kNaviHeight)
|
||
|
||
navTitleLabel.layoutChain
|
||
.top(kStatusBarHeight + 12)
|
||
.centerY(backBtn)
|
||
.centerX()
|
||
|
||
backBtn.layoutChain
|
||
.centerY(navTitleLabel)
|
||
.left(15)
|
||
.width(24)
|
||
.height(24)
|
||
|
||
emailView.layoutChain
|
||
.topToBottomOfView(navBarView, offset: 20)
|
||
.centerX()
|
||
|
||
signInLottieView.layoutChain
|
||
.topToBottomOfView(emailView, offset: 30)
|
||
.edgesHorzontal(16)
|
||
.heightToWidth(1.0)
|
||
|
||
signInTextImg.layoutChain
|
||
.centerX(signInLottieView)
|
||
.centerY(signInLottieView)
|
||
|
||
signInDaysLab.layoutChain
|
||
.topToBottomOfView(signInLottieView, offset: 16)
|
||
.centerX()
|
||
|
||
agreementTV.layoutChain
|
||
.centerX()
|
||
.bottom(kSafeBottomMargin + 30)
|
||
|
||
tipsView.layoutChain
|
||
.bottomToTopOfView(agreementTV, offset: -20)
|
||
.edgesHorzontal(40)
|
||
.centerX()
|
||
}
|
||
|
||
lazy var navBgView: UIImageView = {
|
||
let iv = UIImageView()
|
||
iv.image = UIImage(named: "Common/navBar_bg_2")
|
||
iv.contentMode = .scaleAspectFill
|
||
return iv
|
||
}()
|
||
|
||
lazy var navBarView: UIView = {
|
||
let view = UIView()
|
||
view.backgroundColor = .clear
|
||
return view
|
||
}()
|
||
|
||
lazy var navTitleLabel: UILabel = {
|
||
let label = UILabel()
|
||
label.text = "还在吗?"
|
||
label.font = .systemFont(ofSize: 18, weight: .medium)
|
||
label.textColor = ThemeManager.shared.color.titleAuxColor
|
||
label.textAlignment = .center
|
||
return label
|
||
}()
|
||
|
||
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: 100, right: 100)
|
||
return btn
|
||
}()
|
||
|
||
lazy var emailView: UIView = {
|
||
let view = UIView()
|
||
view.backgroundColor = .clear
|
||
|
||
let title = UILabel()
|
||
title.text = "紧急人邮箱:"
|
||
title.textColor = UIColor(hexStr: "#999999")
|
||
title.font = .systemFont(ofSize: 14, weight: .regular)
|
||
view.addSubview(title)
|
||
title.layoutChain
|
||
.left()
|
||
.centerY()
|
||
.width(84)
|
||
|
||
view.addSubview(emailLab)
|
||
emailLab.layoutChain
|
||
.leftToRightOfView(title)
|
||
.edgesVertical(2)
|
||
|
||
let icon = UIImageView()
|
||
icon.image = UIImage(named: "Group/edit")
|
||
view.addSubview(icon)
|
||
icon.layoutChain
|
||
.leftToRightOfView(emailLab, offset: 10)
|
||
.right(15)
|
||
.width(20)
|
||
.height(20)
|
||
.centerY()
|
||
|
||
return view
|
||
}()
|
||
|
||
lazy var emailLab: UILabel = {
|
||
let label = UILabel()
|
||
label.text = "暂未添加"
|
||
label.textColor = UIColor(hexStr: "#333333")
|
||
label.font = .systemFont(ofSize: 14, weight: .medium)
|
||
return label
|
||
}()
|
||
|
||
lazy var signInLottieView: LottieAnimationView = {
|
||
let view = LottieAnimationView(name: "sign_in_continuous_data")
|
||
view.loopMode = .loop
|
||
return view
|
||
}()
|
||
|
||
lazy var signInTextImg: UIImageView = {
|
||
let view = UIImageView(image: UIImage(named: "SignIn/signIn_text"))
|
||
|
||
return view
|
||
}()
|
||
|
||
lazy var signInDaysLab: UILabel = {
|
||
let label = UILabel()
|
||
label.textColor = UIColor(hexStr: "#333333")
|
||
label.font = .systemFont(ofSize: 16, weight: .medium)
|
||
return label
|
||
}()
|
||
|
||
lazy var tipsView: UIView = {
|
||
let view = UIView()
|
||
view.backgroundColor = UIColor(hexStr: "#F5FBFF")
|
||
view.cornerRadius = 5
|
||
|
||
let icon = UIImageView(image: UIImage(named: "SignIn/tips"))
|
||
view.addSubview(icon)
|
||
icon.layoutChain
|
||
.top(14)
|
||
.left(12)
|
||
.width(14)
|
||
.height(14)
|
||
|
||
view.addSubview(tipsLab)
|
||
tipsLab.layoutChain
|
||
.leftToRightOfView(icon, offset: 3)
|
||
.edgesVertical(13)
|
||
.right(14)
|
||
|
||
return view
|
||
}()
|
||
|
||
lazy var tipsLab: UILabel = {
|
||
let label = UILabel()
|
||
label.text = "提示:2日未签到,系统将以您的名义, 在次日邮件通知您的紧急联系人。"
|
||
label.numberOfLines = 0
|
||
label.textColor = UIColor(hexStr: "#666666")
|
||
label.font = .systemFont(ofSize: 14, weight: .regular)
|
||
return label
|
||
}()
|
||
|
||
lazy var agreementTV: UITextView = {
|
||
let textView = UITextView()
|
||
textView.font = .systemFont(ofSize: 12, weight: .regular)
|
||
textView.backgroundColor = .clear
|
||
textView.isEditable = false
|
||
textView.isScrollEnabled = false
|
||
textView.isSelectable = false
|
||
textView.linkTextAttributes = [:]
|
||
textView.delegate = self
|
||
|
||
let text = "签到即同意 用户协议 和 隐私政策"
|
||
let attributedString = NSMutableAttributedString(string: text)
|
||
attributedString.addAttributes([.foregroundColor: UIColor(hexStr: "#666666")],
|
||
range: NSRange(location: 0, length: text.length))
|
||
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: "隐私政策"))
|
||
|
||
textView.attributedText = attributedString
|
||
return textView
|
||
}()
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: .zero)
|
||
backgroundColor = .white
|
||
setupUI()
|
||
setupRx()
|
||
|
||
signInLottieView.play()
|
||
}
|
||
|
||
required init?(coder aDecoder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
|
||
}
|
||
|
||
extension SignInView: UITextViewDelegate {
|
||
func textView(_ textView: UITextView,
|
||
shouldInteractWith URL: URL,
|
||
in characterRange: NSRange,
|
||
interaction: UITextItemInteraction) -> Bool {
|
||
if URL.absoluteString == "UserAgreement" {
|
||
AppRouter.push(Route.web, userInfo: ["url": URLManager.shared.userAgreementUrl])
|
||
}
|
||
if URL.absoluteString == "PrivacyPolicy" {
|
||
AppRouter.push(Route.web, userInfo: ["url": URLManager.shared.privacyPolicyUrl])
|
||
}
|
||
return true
|
||
}
|
||
|
||
func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
|
||
false
|
||
}
|
||
|
||
private func openURL(_ url: String) {}
|
||
}
|