feat(drone-dock): 实现局域网扫码直传交付
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 真实订单的交付方式弹窗,只展示方式选择并将云端交付导航交回入口。
|
||||
/// 订单的交付方式弹窗,将云端交付和局域网闪传导航交回统一入口。
|
||||
@MainActor
|
||||
final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
/// 用户选择云端上传后,由入口打开现有真实交付页。
|
||||
var onCloudUpload: (() -> Void)?
|
||||
/// 用户选择面对面闪传后,由入口打开独立本地传输页。
|
||||
var onNearbyTransfer: (() -> Void)?
|
||||
/// 用户关闭弹窗后,由入口统一结束当前模态流程。
|
||||
var onClose: (() -> Void)?
|
||||
|
||||
/// 闪传只显示未接入说明,不创建传输任务或连接设备。
|
||||
private enum Phase: Equatable { case methods, nearby }
|
||||
/// 两种交付方式与闪传说明使用独立、稳定的列表身份。
|
||||
private enum Item: Hashable { case nearby, cloud, nearbyMessage }
|
||||
/// 两种交付方式使用独立、稳定的列表身份。
|
||||
private enum Item: Hashable { case nearby, cloud }
|
||||
|
||||
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
|
||||
private var hasRequestedNavigation = false
|
||||
|
||||
/// 游客标题由选中的订单传入,本弹窗不读取网络或改变订单状态。
|
||||
init(customerTitle: String) {
|
||||
@@ -34,7 +33,7 @@ final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
hasRequestedCloud = false
|
||||
hasRequestedNavigation = false
|
||||
navigationController?.isModalInPresentation = false
|
||||
isModalInPresentation = false
|
||||
navigationController?.setNavigationBarHidden(true, animated: false)
|
||||
@@ -54,7 +53,6 @@ final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
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)
|
||||
@@ -76,7 +74,6 @@ final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
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() {
|
||||
@@ -93,14 +90,13 @@ final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func makeLayout() -> UICollectionViewLayout {
|
||||
UICollectionViewCompositionalLayout { [weak self] _, _ in
|
||||
guard let self else { return nil }
|
||||
let height: CGFloat = self.phase == .methods ? 88 : 132
|
||||
UICollectionViewCompositionalLayout { _, _ in
|
||||
let height: CGFloat = 88
|
||||
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.interGroupSpacing = 12
|
||||
section.contentInsets = .init(top: 4, leading: 20, bottom: 4, trailing: 20)
|
||||
return section
|
||||
}
|
||||
@@ -112,16 +108,11 @@ final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
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")
|
||||
cell.apply(title: "面对面闪传", detail: "同一 Wi-Fi 扫码接收 · 无需上传", 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,41 +121,30 @@ final class DroneDockDeliveryMethodViewController: BaseViewController {
|
||||
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])
|
||||
}
|
||||
headerView.apply(title: "交付成片", customer: customerTitle, detail: "请选择本次交付方式")
|
||||
footerView.apply(primaryTitle: nil, enabled: false, identifier: "", detail: "可分批交付多个作品,不影响拍摄次数", secondaryTitle: nil)
|
||||
snapshot.appendItems([.nearby, .cloud])
|
||||
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
|
||||
guard !hasRequestedNavigation, let onCloudUpload else { return }
|
||||
hasRequestedNavigation = true
|
||||
onCloudUpload()
|
||||
}
|
||||
}
|
||||
|
||||
extension DroneDockDeliveryMethodViewController: UICollectionViewDelegate {
|
||||
/// 云端方式交回调用方,闪传方式只在当前弹窗展示待接入说明。
|
||||
/// 只在用户选择后进入对应流程,方式弹窗本身不读取网络。
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard let item = dataSource.itemIdentifier(for: indexPath), !hasRequestedCloud else { return }
|
||||
guard let item = dataSource.itemIdentifier(for: indexPath), !hasRequestedNavigation else { return }
|
||||
switch item {
|
||||
case .nearby: showPhase(.nearby)
|
||||
case .nearby:
|
||||
guard let onNearbyTransfer else { return }
|
||||
hasRequestedNavigation = true
|
||||
onNearbyTransfer()
|
||||
case .cloud: requestCloudUpload()
|
||||
case .nearbyMessage: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user