feat: 完善机巢模拟调试与素材交付交互

增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
This commit is contained in:
2026-10-30 09:59:11 +08:00
parent e827bf8725
commit b95b251de1
100 changed files with 7256 additions and 500 deletions
@@ -0,0 +1,170 @@
import SnapKit
import UIKit
/// 真实订单的交付方式弹窗,只展示方式选择并将云端交付导航交回入口。
@MainActor
final class DroneDockDeliveryMethodViewController: BaseViewController {
/// 用户选择云端上传后,由入口打开现有真实交付页。
var onCloudUpload: (() -> Void)?
/// 用户关闭弹窗后,由入口统一结束当前模态流程。
var onClose: (() -> Void)?
/// 闪传只显示未接入说明,不创建传输任务或连接设备。
private enum Phase: Equatable { case methods, nearby }
/// 两种交付方式与闪传说明使用独立、稳定的列表身份。
private enum Item: Hashable { case nearby, cloud, nearbyMessage }
private let customerTitle: String
private let headerView = DroneDeliveryUploadHeaderView()
private let footerView = DroneDeliveryUploadFooterView()
private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeLayout())
private var dataSource: UICollectionViewDiffableDataSource<Int, Item>!
private var phase = Phase.methods
private var hasRequestedCloud = false
/// 游客标题由选中的订单传入,本弹窗不读取网络或改变订单状态。
init(customerTitle: String) {
self.customerTitle = customerTitle
super.init(nibName: nil, bundle: nil)
modalPresentationStyle = .pageSheet
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
hasRequestedCloud = false
navigationController?.isModalInPresentation = false
isModalInPresentation = false
navigationController?.setNavigationBarHidden(true, animated: false)
configureSheet()
}
override func setupNavigationBar() {
title = "交付成片"
navigationController?.setNavigationBarHidden(true, animated: false)
}
override func setupUI() {
view.backgroundColor = .white
collectionView.backgroundColor = .white
collectionView.alwaysBounceVertical = false
collectionView.showsVerticalScrollIndicator = false
collectionView.accessibilityIdentifier = "drone.delivery.method.list"
collectionView.delegate = self
collectionView.register(DroneDeliveryUploadMethodCell.self, forCellWithReuseIdentifier: "method")
collectionView.register(DroneDeliveryUploadMessageCell.self, forCellWithReuseIdentifier: "message")
[headerView, collectionView, footerView].forEach(view.addSubview)
configureDataSource()
applySnapshot(animated: false)
}
override func setupConstraints() {
headerView.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide)
make.leading.trailing.equalToSuperview()
}
collectionView.snp.makeConstraints { make in
make.top.equalTo(headerView.snp.bottom)
make.leading.trailing.equalToSuperview()
make.bottom.equalTo(footerView.snp.top)
}
footerView.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview() }
}
override func bindActions() {
headerView.onCloseTap = { [weak self] in self?.onClose?() }
footerView.onPrimaryTap = { [weak self] in self?.requestCloudUpload() }
footerView.onSecondaryTap = { [weak self] in self?.showPhase(.methods) }
}
private func configureSheet() {
guard let sheet = navigationController?.sheetPresentationController ?? sheetPresentationController else { return }
let identifier = UISheetPresentationController.Detent.Identifier("drone.delivery.method")
sheet.detents = [
.custom(identifier: identifier) { context in min(410, context.maximumDetentValue) },
.large()
]
sheet.selectedDetentIdentifier = identifier
sheet.prefersGrabberVisible = true
sheet.preferredCornerRadius = 22
sheet.prefersScrollingExpandsWhenScrolledToEdge = false
}
private func makeLayout() -> UICollectionViewLayout {
UICollectionViewCompositionalLayout { [weak self] _, _ in
guard let self else { return nil }
let height: CGFloat = self.phase == .methods ? 88 : 132
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
let group = NSCollectionLayoutGroup.vertical(
layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(height)), subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = self.phase == .methods ? 12 : 0
section.contentInsets = .init(top: 4, leading: 20, bottom: 4, trailing: 20)
return section
}
}
private func configureDataSource() {
dataSource = UICollectionViewDiffableDataSource<Int, Item>(collectionView: collectionView) { collection, path, item in
switch item {
case .nearby, .cloud:
let cell = collection.dequeueReusableCell(withReuseIdentifier: "method", for: path) as! DroneDeliveryUploadMethodCell
if item == .nearby {
cell.apply(title: "面对面闪传", detail: "近距离传给游客 · 流程待确认", symbol: "wifi", identifier: "drone.delivery.method.nearby")
} else {
cell.apply(title: "云端上传", detail: "选择打卡点,上传后游客可查看", symbol: "icloud.and.arrow.up", identifier: "drone.delivery.method.cloud")
}
return cell
case .nearbyMessage:
let cell = collection.dequeueReusableCell(withReuseIdentifier: "message", for: path) as! DroneDeliveryUploadMessageCell
cell.apply(title: "闪传流程待确认", detail: "热点连接与游客接收流程暂未接入。\n请使用云端上传交付成片。", symbol: "wifi")
cell.accessibilityIdentifier = "drone.delivery.method.nearbyMessage"
return cell
}
}
}
private func applySnapshot(animated: Bool) {
guard dataSource != nil else { return }
var snapshot = NSDiffableDataSourceSnapshot<Int, Item>()
snapshot.appendSections([0])
switch phase {
case .methods:
headerView.apply(title: "交付成片", customer: customerTitle, detail: "请选择本次交付方式")
footerView.apply(primaryTitle: nil, enabled: false, identifier: "", detail: "可分批交付多个作品,不影响拍摄次数", secondaryTitle: nil)
snapshot.appendItems([.nearby, .cloud])
case .nearby:
headerView.apply(title: "面对面闪传", customer: customerTitle, detail: "本次仅展示交付入口")
footerView.apply(primaryTitle: "改用云端上传", enabled: true, identifier: "drone.delivery.method.useCloud", detail: "", secondaryTitle: "返回交付方式")
snapshot.appendItems([.nearbyMessage])
}
dataSource.apply(snapshot, animatingDifferences: animated)
collectionView.collectionViewLayout.invalidateLayout()
}
private func showPhase(_ phase: Phase) {
self.phase = phase
applySnapshot(animated: true)
collectionView.setContentOffset(.zero, animated: false)
}
private func requestCloudUpload() {
guard !hasRequestedCloud, let onCloudUpload else { return }
hasRequestedCloud = true
onCloudUpload()
}
}
extension DroneDockDeliveryMethodViewController: UICollectionViewDelegate {
/// 云端方式交回调用方,闪传方式只在当前弹窗展示待接入说明。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let item = dataSource.itemIdentifier(for: indexPath), !hasRequestedCloud else { return }
switch item {
case .nearby: showPhase(.nearby)
case .cloud: requestCloudUpload()
case .nearbyMessage: break
}
}
}