feat(drone-dock): 接入已购套餐快照并固定首页无人机占位

准备页改用 project-info 购买快照,校验订单与项目身份,并按可用性选择已购点位和航线。首页在加载、空数据及失败时保留等高无人机卡片。同步相关测试与接口联调记录、响应和截图。

验证:iPhone 18 Pro 模拟器上 81 项相关测试通过。
This commit is contained in:
2026-10-28 16:50:35 +08:00
parent d01d18d5b3
commit 2793f6b113
58 changed files with 3890 additions and 717 deletions
@@ -1,3 +1,4 @@
import Kingfisher
import SnapKit
import UIKit
@@ -67,17 +68,19 @@ final class DronePreparationOrderCell: UICollectionViewCell {
accessibilityLabel = "\(order.customerName),含\(order.totalShootingCount)次拍摄,已拍摄\(order.successfulShootingCount)次,剩余\(order.remainingShootingCount)次"
}
/// 使用真实首页游客信息与准备页最新次数;准备响应中的未知次数不回填成旧值。
func apply(homeOrder: DroneDockHomeOrder, progress: DroneDockPreparationOrderProgress?, usesHomeSnapshot: Bool = false) {
let total = usesHomeSnapshot ? homeOrder.shotTotal : progress?.shotTotal
let used = usesHomeSnapshot ? homeOrder.shotUsed : progress?.shotUsed
let remaining = usesHomeSnapshot ? homeOrder.shotRemain : progress?.shotRemain
let package = progress == nil ? homeOrder.packageTitle : progress?.packageName
customerLabel.text = homeOrder.touristTitle
/// 使用 project-info 的最新购买摘要;缺失次数不回退旧订单或 workbench 统计。
func apply(homeOrder: DroneDockHomeOrder, summary: DroneDockHomeOrder?, usesHomeSnapshot: Bool = false) {
let snapshot = usesHomeSnapshot ? homeOrder : summary
let total = snapshot?.shotTotal
let used = snapshot?.shotUsed
let remaining = snapshot?.shotRemain
let package = snapshot?.packageName
let tourist = summary?.touristTitle ?? homeOrder.touristTitle
customerLabel.text = tourist
packageLabel.text = package?.isEmpty == false ? package : "含 \(total.map(String.init) ?? "—") 次拍摄"
completedLabel.text = "已拍摄 \(used.map(String.init) ?? "—") 次"
remainingLabel.attributedText = remainingText(remaining.map(String.init) ?? "—")
accessibilityLabel = "\(homeOrder.touristTitle),\(packageLabel.text ?? ""),已拍摄\(used.map(String.init) ?? "—")次,剩余\(remaining.map(String.init) ?? "—")次"
accessibilityLabel = "\(tourist),\(packageLabel.text ?? ""),已拍摄\(used.map(String.init) ?? "—")次,剩余\(remaining.map(String.init) ?? "—")次"
accessibilityIdentifier = "drone.preparation.order"
}
@@ -142,6 +145,8 @@ final class DronePreparationPointCell: UICollectionViewCell {
/// 仅映射模型提供的范围和次数,已拍摄的点位仍保持可选择。
func apply(point: DroneShootingPoint, selected: Bool) {
thumbnail.kf.cancelDownloadTask()
contentView.alpha = 1
nameLabel.text = point.name
thumbnail.contentMode = .scaleAspectFill
thumbnail.image = UIImage(named: point.id == "point-jinque" ? "drone_demo_pagoda" : "drone_demo_mountain")
@@ -160,39 +165,47 @@ final class DronePreparationPointCell: UICollectionViewCell {
accessibilityIdentifier = "drone.preparation.point.\(point.id)"
}
/// 距离只在请求携带有效定位时展示,服务端未提供点位图片时不使用演示山景。
func apply(spot: DroneDockPreparationSpot, selected: Bool, hasLocation: Bool) {
/// 展示已购点位;当前接口未提供距离与点位已拍次数,保持未知占位。
func apply(spot: DroneDockPurchasedSpot, selected: Bool) {
nameLabel.text = spot.name
thumbnail.kf.cancelDownloadTask()
thumbnail.image = UIImage(systemName: "mappin.and.ellipse")
thumbnail.contentMode = .center
thumbnail.tintColor = DroneDockStyle.secondary
if hasLocation {
rangeLabel.text = spot.distanceLabel?.isEmpty == false ? spot.distanceLabel : "距离待确认"
rangeLabel.textColor = spot.inRange == true ? DroneDockStyle.success : DroneDockStyle.secondary
} else {
rangeLabel.text = "待定位"
rangeLabel.textColor = DroneDockStyle.warning
if let text = spot.coverURL, let url = URL(string: text),
let scheme = url.scheme?.lowercased(), ["https", "http"].contains(scheme), url.host != nil {
thumbnail.contentMode = .scaleAspectFill
thumbnail.kf.setImage(with: url, placeholder: UIImage(systemName: "mappin.and.ellipse"))
}
rangeLabel.text = "距离待确认"
rangeLabel.textColor = DroneDockStyle.secondary
locationIcon.tintColor = rangeLabel.textColor
if let status = spot.shotStatusLabel, !status.isEmpty {
countLabel.text = status
} else if let count = spot.shotCount {
countLabel.text = count == 0 ? "未拍摄" : "已拍摄 \(count) 次"
if spot.available != true {
countLabel.text = spot.available == false ? "拍摄点不可用" : "可用性待确认"
} else {
countLabel.text = "已拍摄 — 次"
}
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.07) : .white
contentView.layer.borderColor = (selected ? DroneDockStyle.primary : DroneDockStyle.border).cgColor
contentView.alpha = spot.available == true ? 1 : 0.55
accessibilityLabel = "\(spot.name),\(rangeLabel.text ?? ""),\(countLabel.text ?? "")"
accessibilityTraits = selected ? [.button, .selected] : .button
if spot.available != true { accessibilityTraits.insert(.notEnabled) }
accessibilityIdentifier = "drone.preparation.point.\(spot.id)"
}
override func prepareForReuse() {
super.prepareForReuse()
thumbnail.kf.cancelDownloadTask()
thumbnail.image = nil
}
}
/// 纵向单选航线行,点击整行后由 ViewModel 保留有效选择。
@MainActor
final class DronePreparationRouteCell: UICollectionViewCell {
private let nameLabel = DroneDockStyle.label(size: 16, weight: .semibold)
private let unavailableLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
private let routeIcon = DronePreparationRouteIconView()
private let checkmark = UIImageView()
private let separator = UIView()
@@ -203,16 +216,24 @@ final class DronePreparationRouteCell: UICollectionViewCell {
contentView.layer.cornerCurve = .continuous
checkmark.contentMode = .scaleAspectFit
separator.backgroundColor = DroneDockStyle.border
[routeIcon, nameLabel, checkmark, separator].forEach(contentView.addSubview)
nameLabel.numberOfLines = 0
unavailableLabel.numberOfLines = 0
unavailableLabel.isHidden = true
let labels = UIStackView(arrangedSubviews: [nameLabel, unavailableLabel])
labels.axis = .vertical
labels.spacing = 5
[routeIcon, labels, checkmark, separator].forEach(contentView.addSubview)
routeIcon.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(12)
make.centerY.equalToSuperview()
make.size.equalTo(40)
}
nameLabel.snp.makeConstraints { make in
labels.snp.makeConstraints { make in
make.leading.equalTo(routeIcon.snp.trailing).offset(14)
make.centerY.equalToSuperview()
make.trailing.lessThanOrEqualTo(checkmark.snp.leading).offset(-12)
make.top.greaterThanOrEqualToSuperview().offset(12)
make.bottom.lessThanOrEqualToSuperview().inset(12)
make.trailing.equalTo(checkmark.snp.leading).offset(-12)
}
checkmark.snp.makeConstraints { make in
make.trailing.equalToSuperview().inset(14)
@@ -229,8 +250,21 @@ final class DronePreparationRouteCell: UICollectionViewCell {
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 航线原因允许换行,自适应高度时保持列表提供的整行宽度。
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
let width = layoutAttributes.size.width
let attributes = layoutAttributes.copy() as! UICollectionViewLayoutAttributes
let size = contentView.systemLayoutSizeFitting(
CGSize(width: width, height: 0),
withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
attributes.size = CGSize(width: width, height: max(64, ceil(size.height)))
return attributes
}
/// 选中样式仅反映现有选择,重复点击不会在视图中取消单选。
func apply(route: DroneShootingRoute, selected: Bool) {
unavailableLabel.isHidden = true
contentView.alpha = 1
nameLabel.text = route.name
nameLabel.textColor = selected ? DroneDockStyle.primary : DroneDockStyle.text
routeIcon.apply(selected: selected)
@@ -244,16 +278,23 @@ final class DronePreparationRouteCell: UICollectionViewCell {
}
/// 展示当前真实点位的航线选择,不从行点击发起任何飞行操作。
func apply(route: DroneDockPreparationAirLine, selected: Bool) {
func apply(route: DroneDockPurchasedAirLine, selected: Bool) {
nameLabel.text = route.name
let reason = route.available == false
? DroneDockHomeMetric.usableText(route.unavailableReason) ?? "航线暂不可用"
: "可用性待确认"
unavailableLabel.text = reason
unavailableLabel.isHidden = route.available == true
contentView.alpha = route.available == true ? 1 : 0.55
nameLabel.textColor = selected ? DroneDockStyle.primary : DroneDockStyle.text
routeIcon.apply(selected: selected)
checkmark.image = UIImage(systemName: selected ? "checkmark.circle.fill" : "circle")
checkmark.tintColor = selected ? DroneDockStyle.primary : UIColor(hex: 0xA4ABB8)
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.08) : .white
separator.isHidden = selected
accessibilityLabel = route.name
accessibilityLabel = route.available == true ? route.name : "\(route.name),\(reason)"
accessibilityTraits = selected ? [.button, .selected] : .button
if route.available != true { accessibilityTraits.insert(.notEnabled) }
accessibilityIdentifier = "drone.preparation.route.\(route.id)"
}
}