Files
suixinkan_uikit/suixinkan/UI/Home/Views/HomeLocationReportCardView.swift
汉秋 3b17b7f7f0 Implement permission-driven home tab aligned with Android.
Load role-permission on first visit to drive menus, role-based layout, store card, and location reporting with account-scoped persistence and unit tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 17:27:54 +08:00

71 lines
2.3 KiB
Swift

//
// HomeLocationReportCardView.swift
// suixinkan
//
import SnapKit
import UIKit
///
final class HomeLocationReportCardView: UIView {
var onReportTap: (() -> Void)?
private let titleLabel = UILabel()
private let addressLabel = UILabel()
private let reportButton = UIButton(type: .system)
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white
layer.cornerRadius = 10
titleLabel.text = "位置上报"
titleLabel.font = .systemFont(ofSize: 16, weight: .semibold)
titleLabel.textColor = AppColor.text333
addressLabel.font = .systemFont(ofSize: 13)
addressLabel.textColor = AppColor.text666
addressLabel.numberOfLines = 2
reportButton.setTitle("立即上报", for: .normal)
reportButton.setTitleColor(.white, for: .normal)
reportButton.backgroundColor = AppColor.primary
reportButton.layer.cornerRadius = 6
reportButton.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
reportButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 14, bottom: 8, right: 14)
reportButton.addTarget(self, action: #selector(reportTapped), for: .touchUpInside)
addSubview(titleLabel)
addSubview(addressLabel)
addSubview(reportButton)
titleLabel.snp.makeConstraints { make in
make.top.leading.equalToSuperview().offset(15)
}
addressLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(8)
make.leading.equalToSuperview().offset(15)
make.bottom.equalToSuperview().offset(-15)
make.trailing.lessThanOrEqualTo(reportButton.snp.leading).offset(-12)
}
reportButton.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-15)
make.centerY.equalToSuperview()
}
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func apply(address: String, isReporting: Bool) {
addressLabel.text = address
reportButton.isEnabled = !isReporting
reportButton.alpha = isReporting ? 0.6 : 1
}
@objc private func reportTapped() { onReportTap?() }
}