feat(drone-dock): 展示首页真实拍摄订单

This commit is contained in:
2026-10-27 17:58:30 +08:00
parent 2db4ad8e69
commit f7a2a19dee
6 changed files with 552 additions and 42 deletions
@@ -11,10 +11,10 @@ final class DroneDockHomeViewController: BaseViewController {
private var devicePage = 0
private let pageControl = UIPageControl()
/// 首页固定分区;设备与订单的数据结构以实际联调结果为准。
/// 首页按当前身份、设备、订单与统计展示服务端快照。
private enum Section: Int, CaseIterable { case context, devices, orders, statistics }
/// 稳定身份确保刷新使用 Diffable 更新。
private enum Item: Hashable { case context, devices, device(Int), orders, statistics }
private enum Item: Hashable { case context, devices, device(Int), orders, order(Int), statistics }
private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeLayout())
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
@@ -56,6 +56,7 @@ final class DroneDockHomeViewController: BaseViewController {
collectionView.accessibilityIdentifier = "drone.home.remote.list"
collectionView.register(DroneDockHomeContentCell.self, forCellWithReuseIdentifier: "content")
collectionView.register(DroneDockDeviceCell.self, forCellWithReuseIdentifier: "device")
collectionView.register(DroneDockCompactOrderCell.self, forCellWithReuseIdentifier: "order")
collectionView.register(DroneDockHomeHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: "header")
collectionView.register(DroneDockHomePageFooter.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter,
@@ -97,12 +98,17 @@ final class DroneDockHomeViewController: BaseViewController {
isRefreshing = true
refreshTask = Task { @MainActor [weak self] in
guard let self else { return }
let isInitialLoad = self.viewModel.response == nil
self.applySnapshot(animated: false)
await self.viewModel.refresh()
guard !Task.isCancelled else { return }
self.isRefreshing = false
self.collectionView.refreshControl?.endRefreshing()
self.applySnapshot(animated: true) { [weak self] in
if isInitialLoad, let self {
self.collectionView.layoutIfNeeded()
self.collectionView.setContentOffset(CGPoint(x: 0, y: -self.collectionView.adjustedContentInset.top), animated: false)
}
#if DEBUG
Task { @MainActor [weak self] in await self?.captureHomeIfRequested() }
#endif
@@ -120,6 +126,17 @@ final class DroneDockHomeViewController: BaseViewController {
}
return cell
}
if case .order(let id) = item {
let cell = collection.dequeueReusableCell(withReuseIdentifier: "order", for: path) as! DroneDockCompactOrderCell
if let order = self.viewModel.response?.orders.first(where: { $0.orderID == id }) {
cell.apply(homeOrder: order)
cell.onShootingTap = { [weak self] in
self?.showAlert(title: order.actionTitle ?? "拍摄订单", message: "拍摄流程暂未接入,请稍后再试")
}
cell.onMaterialsTap = { [weak self] in self?.showUnavailable("订单素材") }
}
return cell
}
let cell = collection.dequeueReusableCell(withReuseIdentifier: "content", for: path) as! DroneDockHomeContentCell
switch item {
case .context:
@@ -130,7 +147,7 @@ final class DroneDockHomeViewController: BaseViewController {
cell.applyStatistics(self.viewModel.response?.today)
case .devices, .orders:
self.applyDataState(to: cell, isDevice: item == .devices)
case .device: break
case .device, .order: break
}
return cell
}
@@ -158,20 +175,13 @@ final class DroneDockHomeViewController: BaseViewController {
cell.applyMessage(symbol: "wifi.exclamationmark", title: "首页加载失败", detail: error + ",请下拉重试")
return
}
guard let response = viewModel.response else {
guard viewModel.response != nil else {
cell.applyMessage(symbol: "arrow.triangle.2.circlepath", title: "正在加载", detail: "正在获取最新数据")
return
}
let recordCount = isDevice ? response.airports.count : response.orders.count
if recordCount == 0 {
cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text",
title: isDevice ? "暂无无人机" : "暂无待拍摄订单",
detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据")
} else {
// 订单仍等待真实非空样例,不影响已接入的设备卡片。
cell.applyMessage(symbol: "exclamationmark.circle", title: "订单信息暂不可用",
detail: "已获取 \(recordCount) 条数据,暂时无法展示详情")
}
cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text",
title: isDevice ? "暂无无人机" : "暂无待拍摄订单",
detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据")
}
private func applySnapshot(animated: Bool, completion: (() -> Void)? = nil) {
@@ -181,7 +191,8 @@ final class DroneDockHomeViewController: BaseViewController {
snapshot.appendItems([.context], toSection: .context)
let airports = viewModel.response?.airports ?? []
snapshot.appendItems(airports.isEmpty ? [.devices] : airports.map { .device($0.id) }, toSection: .devices)
snapshot.appendItems([.orders], toSection: .orders)
let orders = viewModel.response?.orders ?? []
snapshot.appendItems(orders.isEmpty ? [.orders] : orders.map { .order($0.orderID) }, toSection: .orders)
snapshot.appendItems([.statistics], toSection: .statistics)
let old = Set(dataSource.snapshot().itemIdentifiers)
let previousDeviceCount = old.filter { if case .device = $0 { return true }; return false }.count
@@ -207,6 +218,7 @@ final class DroneDockHomeViewController: BaseViewController {
let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: width, heightDimension: height), subitems: [item])
let layout = NSCollectionLayoutSection(group: group)
layout.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: section == .statistics ? 24 : 0, trailing: 16)
if section == .orders { layout.interGroupSpacing = 12 }
if multipleDevices {
layout.interGroupSpacing = 12
layout.orthogonalScrollingBehavior = .groupPaging