jsdw_ios/QuickLocation/Section/Mine/Account/AccountView.swift

321 lines
9.2 KiB
Swift

//
// AccountView.swift
// QuickLocation
//
// Created by on 2026/6/10.
//
import UIKit
import RxSwift
import RxCocoa
class AccountView: UIView {
var disposeBag = DisposeBag()
private func setupRx() {
copyBtn.rx.tap
.subscribe(onNext: { _ in
UIPasteboard.general.string = AppContextManager.shared.userId
DLToast.showSuccess(text: "已复制")
})
.disposed(by: disposeBag)
phoneView.rx.tapGesture.subscribe(onNext: { _ in
AppRouter.push(Route.changePhone)
}).disposed(by: disposeBag)
}
private func setupUI() {
addSubview(navBgView)
addSubview(navView)
addSubview(infoView)
infoView.addSubview(infoStackView)
addSubview(otherInfoView)
otherInfoView.addSubview(otherInfoStackView)
addSubview(logoutBtn)
addSubview(cancelledBtn)
navBgView.layoutChain
.edges(excludingEdge: .bottom)
.heightToWidth(160/375)
navView.layoutChain
.edges(excludingEdge: .bottom)
.height(kNaviHeight)
infoView.layoutChain
.topToBottomOfView(navView, offset: 18)
.edgesHorzontal(16)
infoStackView.layoutChain.edges()
userIdView.layoutChain.height(52)
phoneView.layoutChain.height(52)
otherInfoView.layoutChain
.topToBottomOfView(infoView, offset: 18)
.edgesHorzontal(16)
otherInfoStackView.layoutChain.edges()
versionView.layoutChain.height(52)
clearView.layoutChain.height(52)
logoutBtn.layoutChain
.edgesHorzontal(30)
.bottomToTopOfView(cancelledBtn, offset: -10)
.height(50)
cancelledBtn.layoutChain
.edgesHorzontal(30)
.bottom(kSafeBottomMargin + 10)
.height(50)
}
lazy var navBgView: UIImageView = {
let iv = UIImageView()
iv.image = UIImage(named: "Common/navBar_bg_2")
iv.contentMode = .scaleAspectFill
return iv
}()
lazy var navView: BaseNavigationView = {
let nav = BaseNavigationView(title: "账号与安全")
return nav
}()
lazy var infoView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.layer.shadowColor = UIColor(hexStr: "#0F2846", alpha: 0.1).cgColor
view.layer.shadowOffset = CGSize(width: 0, height: 0)
view.layer.shadowOpacity = 1
view.layer.shadowRadius = 10
return view
}()
lazy var infoStackView: UIStackView = {
let view = UIStackView(arrangedSubviews: [userIdView, phoneView])
view.axis = .vertical
view.alignment = .fill
view.distribution = .fill
view.spacing = 0
view.backgroundColor = .white
view.cornerRadius = 10
return view
}()
/// UserID
lazy var userIdView: UIView = {
let view = UIView()
view.backgroundColor = .clear
let titleLab = UILabel()
titleLab.text = "ID"
titleLab.font = .systemFont(ofSize: 14, weight: .medium)
titleLab.textColor = UIColor(hexStr: "#1A1A1A")
view.addSubview(titleLab)
titleLab.layoutChain
.left(15)
.centerY()
view.addSubview(copyBtn)
copyBtn.layoutChain
.right(15)
.centerY()
.width(14)
.height(14)
let contentLab = UILabel()
contentLab.text = AppContextManager.shared.userId
contentLab.font = .systemFont(ofSize: 14, weight: .medium)
contentLab.textColor = UIColor(hexStr: "#1A1A1A")
view.addSubview(contentLab)
contentLab.layoutChain
.rightToLeftOfView(copyBtn, offset: -2)
.centerY()
let line = UIView()
line.backgroundColor = ThemeManager.shared.color.lineColor
view.addSubview(line)
line.layoutChain
.bottom()
.height(0.5)
.edgesHorzontal(15)
return view
}()
lazy var copyBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setImage(UIImage(named: "Mine/copy"), for: .normal)
return btn
}()
///
lazy var phoneView: UIView = {
let view = UIView()
view.backgroundColor = .clear
let titleLab = UILabel()
titleLab.text = "手机号"
titleLab.font = .systemFont(ofSize: 14, weight: .medium)
titleLab.textColor = UIColor(hexStr: "#1A1A1A")
view.addSubview(titleLab)
titleLab.layoutChain
.left(15)
.centerY()
let arrow = UIImageView(image: UIImage(named: "Group/arrow"))
view.addSubview(arrow)
arrow.layoutChain
.right(15)
.width(14)
.height(14)
.centerY()
view.addSubview(phoneLab)
phoneLab.layoutChain
.rightToLeftOfView(arrow, offset: -8)
.centerY()
return view
}()
lazy var phoneLab: UILabel = {
let lab = UILabel()
lab.text = AppContextManager.shared.userPhone
lab.font = .systemFont(ofSize: 14, weight: .medium)
lab.textColor = UIColor(hexStr: "#1A1A1A")
return lab
}()
//
lazy var otherInfoView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.layer.shadowColor = UIColor(hexStr: "#0F2846", alpha: 0.1).cgColor
view.layer.shadowOffset = CGSize(width: 0, height: 0)
view.layer.shadowOpacity = 1
view.layer.shadowRadius = 10
return view
}()
lazy var otherInfoStackView: UIStackView = {
let view = UIStackView(arrangedSubviews: [versionView, clearView])
view.axis = .vertical
view.alignment = .fill
view.distribution = .fill
view.spacing = 0
view.backgroundColor = .white
view.cornerRadius = 10
return view
}()
///
lazy var versionView: UIView = {
let view = UIView()
view.backgroundColor = .clear
let titleLab = UILabel()
titleLab.text = "当前版本"
titleLab.font = .systemFont(ofSize: 14, weight: .medium)
titleLab.textColor = UIColor(hexStr: "#1A1A1A ")
view.addSubview(titleLab)
titleLab.layoutChain
.left(15)
.centerY()
let contentLab = UILabel()
contentLab.text = kAppShortVersion
contentLab.font = .systemFont(ofSize: 14, weight: .medium)
contentLab.textColor = UIColor(hexStr: "#1A1A1A")
view.addSubview(contentLab)
contentLab.layoutChain
.right(15)
.centerY()
let line = UIView()
line.backgroundColor = ThemeManager.shared.color.lineColor
view.addSubview(line)
line.layoutChain
.bottom()
.height(0.5)
.edgesHorzontal(15)
return view
}()
///
lazy var clearView: UIView = {
let view = UIView()
view.backgroundColor = .clear
let titleLab = UILabel()
titleLab.text = "清除缓存"
titleLab.font = .systemFont(ofSize: 14, weight: .medium)
titleLab.textColor = UIColor(hexStr: "#1A1A1A")
view.addSubview(titleLab)
titleLab.layoutChain
.left(15)
.centerY()
let arrow = UIImageView(image: UIImage(named: "Group/arrow"))
view.addSubview(arrow)
arrow.layoutChain
.right(15)
.width(14)
.height(14)
.centerY()
view.addSubview(cacheLab)
cacheLab.layoutChain
.rightToLeftOfView(arrow, offset: -8)
.centerY()
return view
}()
lazy var cacheLab: UILabel = {
let lab = UILabel()
lab.font = .systemFont(ofSize: 14, weight: .medium)
lab.textColor = UIColor(hexStr: "#1A1A1A")
return lab
}()
lazy var logoutBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("退出登录", for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
btn.setTitleColor(.white, for: .normal)
btn.setBackgroundImage(UIImage(named: "Common/button_bg_2"), for: .normal)
btn.cornerRadius = 25
return btn
}()
lazy var cancelledBtn: UIButton = {
let btn = UIButton(type: .custom)
btn.setTitle("注销账号", for: .normal)
btn.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
btn.setTitleColor(UIColor(hexStr: "#767676"), for: .normal)
btn.backgroundColor = .clear
return btn
}()
override init(frame: CGRect) {
super.init(frame: .zero)
backgroundColor = UIColor(hexStr: "#FAFAFA")
setupUI()
setupRx()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}