完善实名认证、钱包与打卡点模块 UI 与业务逻辑。
对齐 Android 实名认证流程与审核页、钱包提现/积分兑换界面,优化打卡点列表与详情交互,并补充相关资源、主题 token 与单元测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -15,9 +15,9 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
|
||||
private let mapView = PunchPointMapView()
|
||||
private let zoomStack = UIStackView()
|
||||
private let zoomInButton = PunchPointMapControlButton(symbol: "plus")
|
||||
private let zoomOutButton = PunchPointMapControlButton(symbol: "minus")
|
||||
private let locateButton = PunchPointMapControlButton(symbol: "location.fill")
|
||||
private let zoomInButton = PunchPointMapControlButton(assetName: "punch_point_zoom_in")
|
||||
private let zoomOutButton = PunchPointMapControlButton(assetName: "punch_point_zoom_out")
|
||||
private let locateButton = PunchPointMapControlButton(assetName: "punch_point_map_location")
|
||||
private let cardView = UIView()
|
||||
private let scrollView = UIScrollView()
|
||||
private let contentStack = UIStackView()
|
||||
@ -102,11 +102,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
zoomStack.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(cardView.snp.top).offset(-16)
|
||||
make.bottom.equalTo(locateButton.snp.top).offset(-12)
|
||||
}
|
||||
locateButton.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
make.bottom.equalTo(zoomStack.snp.top).offset(-12)
|
||||
make.bottom.equalTo(cardView.snp.top).offset(-16)
|
||||
make.size.equalTo(40)
|
||||
}
|
||||
zoomInButton.snp.makeConstraints { make in
|
||||
@ -178,8 +178,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
bottomBar.isHidden = false
|
||||
if let region = detail.region {
|
||||
let coordinate = CLLocationCoordinate2D(latitude: region.lat, longitude: region.lot)
|
||||
mapView.updateMarker(coordinate: coordinate)
|
||||
mapView.setCenter(coordinate, zoomLevel: 16)
|
||||
mapView.updatePunchPointMarker(
|
||||
coordinate: coordinate,
|
||||
imageURL: detail.guideImages.first,
|
||||
fitWithUserLocation: true
|
||||
)
|
||||
}
|
||||
rebuildContent(detail)
|
||||
}
|
||||
@ -188,7 +191,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
contentStack.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "*打卡点名称", value: detail.name))
|
||||
let coordinateText = detail.region.map { "\($0.lat),\($0.lot)" } ?? "--"
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "*打卡点坐标", value: coordinateText))
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(
|
||||
title: "*打卡点坐标",
|
||||
value: coordinateText,
|
||||
showsLocationIcon: true
|
||||
))
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "*打卡点地址", value: detail.displayAddress.nonEmptyTrimmed ?? "--"))
|
||||
if let description = detail.description?.nonEmptyTrimmed {
|
||||
contentStack.addArrangedSubview(PunchPointReadOnlyField(title: "打卡点描述", value: description, multiline: true))
|
||||
@ -241,7 +248,9 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
imageView.isUserInteractionEnabled = true
|
||||
imageView.tag = index
|
||||
if let url = URL(string: urlText) {
|
||||
imageView.kf.setImage(with: url)
|
||||
imageView.kf.setImage(with: url, placeholder: UIImage(named: "SplashLogo"))
|
||||
} else {
|
||||
imageView.image = UIImage(named: "SplashLogo")
|
||||
}
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.width.equalTo(120)
|
||||
@ -266,7 +275,7 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
label.font = .systemFont(ofSize: 14)
|
||||
label.textColor = UIColor(hex: 0x2E3746)
|
||||
let chip = PunchPointStatusChip()
|
||||
chip.apply(text: detail.statusLabel.nonEmptyTrimmed ?? "--", status: detail.status)
|
||||
chip.apply(PunchPointDisplayFormatter.auditStatus(detail.status), compact: false)
|
||||
row.addArrangedSubview(label)
|
||||
row.addArrangedSubview(chip)
|
||||
row.isLayoutMarginsRelativeArrangement = true
|
||||
@ -301,7 +310,9 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
imageView.clipsToBounds = true
|
||||
imageView.layer.cornerRadius = 16
|
||||
if let url = URL(string: qrCode) {
|
||||
imageView.kf.setImage(with: url)
|
||||
imageView.kf.setImage(with: url, placeholder: UIImage(named: "SplashLogo"))
|
||||
} else {
|
||||
imageView.image = UIImage(named: "SplashLogo")
|
||||
}
|
||||
imageView.snp.makeConstraints { make in
|
||||
make.size.equalTo(180)
|
||||
@ -331,6 +342,11 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
Task {
|
||||
do {
|
||||
let authorization = await PHPhotoLibrary.requestAuthorization(for: .addOnly)
|
||||
guard authorization == .authorized || authorization == .limited else {
|
||||
await MainActor.run { self.presentPhotoPermissionAlert() }
|
||||
return
|
||||
}
|
||||
let (data, _) = try await URLSession.shared.data(from: url)
|
||||
guard let image = UIImage(data: data) else { throw APIError.decodeFailed("二维码图片无效") }
|
||||
try await PHPhotoLibrary.shared().performChanges {
|
||||
@ -343,6 +359,21 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func presentPhotoPermissionAlert() {
|
||||
let alert = UIAlertController(
|
||||
title: "无法保存二维码",
|
||||
message: "相册权限未授予,请在设置中开启",
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "去设置", style: .default) { _ in
|
||||
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
|
||||
UIApplication.shared.open(url)
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
private func requiredTitle(_ text: String) -> NSAttributedString {
|
||||
let mutable = NSMutableAttributedString(string: text, attributes: [
|
||||
.font: UIFont.systemFont(ofSize: 14, weight: .medium),
|
||||
@ -368,7 +399,35 @@ final class PunchPointDetailViewController: BaseViewController {
|
||||
}
|
||||
|
||||
@objc private func locateTapped() {
|
||||
mapView.centerOnUserLocation()
|
||||
Task {
|
||||
do {
|
||||
let snapshot = try await LocationProvider.shared.requestSnapshot()
|
||||
let coordinate = CLLocationCoordinate2D(
|
||||
latitude: snapshot.latitude,
|
||||
longitude: snapshot.longitude
|
||||
)
|
||||
await MainActor.run { self.mapView.setCenter(coordinate, zoomLevel: 16) }
|
||||
} catch LocationProviderError.permissionDenied {
|
||||
await MainActor.run { self.presentLocationPermissionAlert() }
|
||||
} catch {
|
||||
await MainActor.run { self.showToast("定位失败") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func presentLocationPermissionAlert() {
|
||||
let alert = UIAlertController(
|
||||
title: "无法定位",
|
||||
message: "定位权限未授予,请在设置中开启",
|
||||
preferredStyle: .alert
|
||||
)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
alert.addAction(UIAlertAction(title: "去设置", style: .default) { _ in
|
||||
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
|
||||
UIApplication.shared.open(url)
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
@objc private func retryTapped() {
|
||||
@ -393,7 +452,10 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
var onMapTap: ((CLLocationCoordinate2D) -> Void)?
|
||||
|
||||
private let mapView: MAMapView
|
||||
private var markerAnnotation: MAPointAnnotation?
|
||||
private var punchPointAnnotation: MAPointAnnotation?
|
||||
private var selectedAnnotation: MAPointAnnotation?
|
||||
private var punchPointImageURL: URL?
|
||||
private var fitWithUserLocation = false
|
||||
|
||||
override init(frame: CGRect) {
|
||||
_ = AMapBootstrap.configureIfNeeded()
|
||||
@ -403,6 +465,7 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
mapView.showsUserLocation = true
|
||||
mapView.showsCompass = false
|
||||
mapView.showsScale = false
|
||||
mapView.touchPOIEnabled = true
|
||||
mapView.zoomLevel = 15
|
||||
addSubview(mapView)
|
||||
mapView.snp.makeConstraints { make in
|
||||
@ -415,17 +478,45 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
/// 更新打卡点标记。
|
||||
/// 更新原打卡点标记,可使用首张图片作为 Android 同款圆角 Marker。
|
||||
func updatePunchPointMarker(
|
||||
coordinate: CLLocationCoordinate2D?,
|
||||
imageURL: String? = nil,
|
||||
fitWithUserLocation: Bool = false
|
||||
) {
|
||||
if let punchPointAnnotation {
|
||||
mapView.removeAnnotation(punchPointAnnotation)
|
||||
self.punchPointAnnotation = nil
|
||||
}
|
||||
punchPointImageURL = imageURL.flatMap(URL.init(string:))
|
||||
self.fitWithUserLocation = fitWithUserLocation
|
||||
guard let coordinate, CLLocationCoordinate2DIsValid(coordinate) else { return }
|
||||
let annotation = MAPointAnnotation()
|
||||
annotation.coordinate = coordinate
|
||||
annotation.title = "punch_point_original"
|
||||
punchPointAnnotation = annotation
|
||||
mapView.addAnnotation(annotation)
|
||||
if fitWithUserLocation {
|
||||
fitPunchPointAndUserLocation()
|
||||
}
|
||||
}
|
||||
|
||||
/// 兼容仅需更新普通 Marker 的调用。
|
||||
func updateMarker(coordinate: CLLocationCoordinate2D?) {
|
||||
if let markerAnnotation {
|
||||
mapView.removeAnnotation(markerAnnotation)
|
||||
self.markerAnnotation = nil
|
||||
updatePunchPointMarker(coordinate: coordinate)
|
||||
}
|
||||
|
||||
/// 更新地图点击产生的新位置 Marker。
|
||||
func updateSelectedMarker(coordinate: CLLocationCoordinate2D?) {
|
||||
if let selectedAnnotation {
|
||||
mapView.removeAnnotation(selectedAnnotation)
|
||||
self.selectedAnnotation = nil
|
||||
}
|
||||
guard let coordinate, CLLocationCoordinate2DIsValid(coordinate) else { return }
|
||||
let annotation = MAPointAnnotation()
|
||||
annotation.coordinate = coordinate
|
||||
annotation.title = "打卡点位置"
|
||||
markerAnnotation = annotation
|
||||
annotation.title = "punch_point_selected"
|
||||
selectedAnnotation = annotation
|
||||
mapView.addAnnotation(annotation)
|
||||
}
|
||||
|
||||
@ -453,21 +544,92 @@ final class PunchPointMapView: UIView, MAMapViewDelegate {
|
||||
setCenter(coordinate)
|
||||
}
|
||||
|
||||
/// 同时展示原打卡点、用户位置和新选位置,并留出 Android 同款边距。
|
||||
func fitAllMarkers(edgePadding: UIEdgeInsets = UIEdgeInsets(top: 80, left: 56, bottom: 80, right: 56)) {
|
||||
var annotations: [MAAnnotation] = []
|
||||
if let punchPointAnnotation { annotations.append(punchPointAnnotation) }
|
||||
if let selectedAnnotation { annotations.append(selectedAnnotation) }
|
||||
if let userLocation = mapView.userLocation,
|
||||
let location = userLocation.location,
|
||||
CLLocationCoordinate2DIsValid(location.coordinate) {
|
||||
annotations.append(userLocation)
|
||||
}
|
||||
guard !annotations.isEmpty else { return }
|
||||
if annotations.count == 1, let annotation = annotations.first {
|
||||
setCenter(annotation.coordinate, zoomLevel: 16)
|
||||
} else {
|
||||
mapView.showAnnotations(annotations, edgePadding: edgePadding, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
private func fitPunchPointAndUserLocation() {
|
||||
guard fitWithUserLocation else { return }
|
||||
fitAllMarkers(edgePadding: UIEdgeInsets(top: 80, left: 50, bottom: 80, right: 50))
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
|
||||
if annotation is MAUserLocation { return nil }
|
||||
let isOriginal = annotation === punchPointAnnotation
|
||||
let reuseIdentifier = isOriginal ? "PunchPointImageMarker" : "PunchPointSelectedMarker"
|
||||
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
|
||||
?? MAAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)
|
||||
annotationView?.annotation = annotation
|
||||
annotationView?.canShowCallout = false
|
||||
annotationView?.centerOffset = CGPoint(x: 0, y: -12)
|
||||
|
||||
if isOriginal, let punchPointImageURL {
|
||||
annotationView?.image = UIImage(named: "punch_point_marker")
|
||||
KingfisherManager.shared.retrieveImage(with: punchPointImageURL) { result in
|
||||
guard case let .success(value) = result else { return }
|
||||
Task { @MainActor in
|
||||
guard annotationView?.annotation === annotation else { return }
|
||||
annotationView?.image = Self.roundedMarkerImage(value.image)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
annotationView?.image = UIImage(named: "punch_point_marker")
|
||||
}
|
||||
return annotationView
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, didUpdate userLocation: MAUserLocation!, updatingLocation: Bool) {
|
||||
guard updatingLocation, userLocation.location != nil else { return }
|
||||
fitPunchPointAndUserLocation()
|
||||
}
|
||||
|
||||
private static func roundedMarkerImage(_ source: UIImage) -> UIImage {
|
||||
let size = CGSize(width: 40, height: 40)
|
||||
return UIGraphicsImageRenderer(size: size).image { _ in
|
||||
UIBezierPath(roundedRect: CGRect(origin: .zero, size: size), cornerRadius: 6).addClip()
|
||||
source.draw(in: CGRect(origin: .zero, size: size))
|
||||
}
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, didSingleTappedAt coordinate: CLLocationCoordinate2D) {
|
||||
onMapTap?(coordinate)
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MAMapView!, didTouchPois pois: [Any]!) {
|
||||
guard let poi = pois.first as? MATouchPoi else { return }
|
||||
onMapTap?(poi.coordinate)
|
||||
}
|
||||
}
|
||||
|
||||
/// 打卡点地图控制按钮。
|
||||
/// 地图悬浮控制按钮。
|
||||
final class PunchPointMapControlButton: UIButton {
|
||||
init(symbol: String) {
|
||||
init(assetName: String) {
|
||||
super.init(frame: .zero)
|
||||
setImage(UIImage(systemName: symbol), for: .normal)
|
||||
tintColor = AppColor.textPrimary
|
||||
setImage(UIImage(named: assetName), for: .normal)
|
||||
backgroundColor = .white
|
||||
layer.cornerRadius = 12
|
||||
clipsToBounds = true
|
||||
imageView?.contentMode = .scaleAspectFit
|
||||
accessibilityLabel = switch assetName {
|
||||
case "punch_point_zoom_in": "放大地图"
|
||||
case "punch_point_zoom_out": "缩小地图"
|
||||
default: "定位当前位置"
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
@ -479,20 +641,46 @@ final class PunchPointMapControlButton: UIButton {
|
||||
/// 打卡点只读字段。
|
||||
/// 详情页只读字段块。
|
||||
final class PunchPointReadOnlyField: UIView {
|
||||
init(title: String, value: String, multiline: Bool = false) {
|
||||
init(title: String, value: String, multiline: Bool = false, showsLocationIcon: Bool = false) {
|
||||
super.init(frame: .zero)
|
||||
let stack = UIStackView()
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 8
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.attributedText = Self.requiredTitle(title)
|
||||
let valueContainer = UIView()
|
||||
valueContainer.backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
valueContainer.layer.cornerRadius = 8
|
||||
let valueLabel = UILabel()
|
||||
valueLabel.text = value.nonEmptyTrimmed ?? "--"
|
||||
valueLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
||||
valueLabel.textColor = AppColor.textPrimary
|
||||
valueLabel.font = .systemFont(ofSize: 14)
|
||||
valueLabel.textColor = UIColor(hex: 0x4B5563)
|
||||
valueLabel.numberOfLines = multiline ? 0 : 2
|
||||
stack.addArrangedSubview(titleLabel)
|
||||
stack.addArrangedSubview(valueLabel)
|
||||
stack.addArrangedSubview(valueContainer)
|
||||
valueContainer.addSubview(valueLabel)
|
||||
if showsLocationIcon {
|
||||
let icon = UIImageView(image: UIImage(named: "punch_point_location"))
|
||||
icon.contentMode = .scaleAspectFit
|
||||
valueContainer.addSubview(icon)
|
||||
icon.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(12)
|
||||
make.centerY.equalToSuperview()
|
||||
make.size.equalTo(20)
|
||||
}
|
||||
valueLabel.snp.makeConstraints { make in
|
||||
make.top.bottom.equalToSuperview().inset(12)
|
||||
make.leading.equalToSuperview().offset(12)
|
||||
make.trailing.lessThanOrEqualTo(icon.snp.leading).offset(-8)
|
||||
}
|
||||
} else {
|
||||
valueLabel.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview().inset(UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12))
|
||||
}
|
||||
}
|
||||
valueContainer.snp.makeConstraints { make in
|
||||
make.height.greaterThanOrEqualTo(multiline ? 72 : 46)
|
||||
}
|
||||
addSubview(stack)
|
||||
stack.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
|
||||
Reference in New Issue
Block a user