feat: 完善机巢任务安全控制与状态诊断
同步新版飞控与 WebSocket 回执合同,完善独立指令等待、暂停继续和返航状态;增加真机诊断并优化倒计时与素材库展示。
This commit is contained in:
@@ -16,8 +16,6 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
private let deliveryControllerFactory: (DroneDockHomeOrder, DroneDockHomeContext, Int?) -> UIViewController
|
||||
private let downloadSourceDescription: String?
|
||||
private let downloadIsSimulated: Bool
|
||||
private let taskControllerFactory: (Int, DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController
|
||||
private var taskButton: UIBarButtonItem?
|
||||
|
||||
/// 元数据与媒体分区独立,任务没有素材时也保留其状态。
|
||||
private enum Section: Hashable { case order, filters, summary, task(Int), media(Int), message }
|
||||
@@ -45,16 +43,12 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
mediaPreviewControllerFactory: ((URL, Bool, String) -> UIViewController)? = nil,
|
||||
downloadViewModel: DroneDockMaterialDownloadViewModel? = nil,
|
||||
downloadSourceDescription: String? = nil,
|
||||
downloadIsSimulated: Bool = false,
|
||||
taskControllerFactory: ((Int, DroneDockHomeOrder, DroneDockHomeContext) -> UIViewController)? = nil) {
|
||||
downloadIsSimulated: Bool = false) {
|
||||
self.viewModel = viewModel
|
||||
self.downloadViewModel = downloadViewModel ?? DroneDockMaterialDownloadViewModel(
|
||||
isContextValid: { [weak viewModel] in viewModel?.acceptsDownloadContext() == true })
|
||||
self.downloadSourceDescription = downloadSourceDescription
|
||||
self.downloadIsSimulated = downloadIsSimulated
|
||||
self.taskControllerFactory = taskControllerFactory ?? { id, order, context in
|
||||
DroneDockShootingTaskEntry.makeController(taskID: id, order: order, context: context)
|
||||
}
|
||||
self.thumbnailProvider = thumbnailProvider
|
||||
self.mediaPreviewControllerFactory = mediaPreviewControllerFactory
|
||||
self.deliveryControllerFactory = deliveryControllerFactory ?? DroneDockDeliveryEntry.makeController
|
||||
@@ -73,11 +67,7 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
let refresh = UIBarButtonItem(image: UIImage(systemName: "arrow.clockwise"), style: .plain, target: self, action: #selector(refreshTapped))
|
||||
refresh.accessibilityLabel = "刷新素材状态"
|
||||
refresh.accessibilityIdentifier = "drone.materials.remote.refresh"
|
||||
let tasks = UIBarButtonItem(title: "查看任务", style: .plain, target: self, action: #selector(viewTasksTapped))
|
||||
tasks.accessibilityIdentifier = "drone.materials.remote.viewTasks"
|
||||
tasks.isEnabled = false
|
||||
taskButton = tasks
|
||||
navigationItem.rightBarButtonItems = [refresh, tasks]
|
||||
navigationItem.rightBarButtonItems = [refresh]
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
@@ -168,8 +158,8 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
return cell
|
||||
case .filter(let id):
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "filter", for: path) as! DroneMaterialFilterCell
|
||||
let title = id.flatMap { id in self.viewModel.spots.first { $0.id == id } }.map { Self.usable($0.name, fallback: "点位 \($0.id)") } ?? "全部点位"
|
||||
cell.apply(title: title, id: id.map(String.init), selected: id == self.displayedSpotID, locked: self.viewModel.detail == nil || self.selectionLocked)
|
||||
cell.apply(title: self.filterTitle(for: id), id: id.map(String.init), selected: id == self.displayedSpotID,
|
||||
locked: self.viewModel.detail == nil || self.selectionLocked, wrapsTitle: true)
|
||||
return cell
|
||||
case .task(let taskID):
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "record", for: path) as! DroneDockMaterialRecordCell
|
||||
@@ -228,8 +218,20 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
guard sections.indices.contains(index) else { return nil }
|
||||
switch sections[index] {
|
||||
case .filters:
|
||||
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
|
||||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .estimated(104), heightDimension: .absolute(36)), subitems: [item])
|
||||
let maximumWidth = min(200, max(1, environment.container.effectiveContentSize.width - 32))
|
||||
let sizes = dataSource.snapshot().itemIdentifiers(inSection: .filters).compactMap { item -> CGSize? in
|
||||
guard case .filter(let id) = item else { return nil }
|
||||
return DroneMaterialFilterCell.wrappedSize(title: self.filterTitle(for: id), maximumWidth: maximumWidth)
|
||||
}
|
||||
let width = sizes.reduce(0) { $0 + $1.width } + CGFloat(max(0, sizes.count - 1)) * 8
|
||||
let height = sizes.map(\.height).max() ?? 40
|
||||
let group = NSCollectionLayoutGroup.custom(layoutSize: .init(widthDimension: .absolute(max(1, width)), heightDimension: .absolute(height))) { _ in
|
||||
var x: CGFloat = 0
|
||||
return sizes.map { size in
|
||||
defer { x += size.width + 8 }
|
||||
return NSCollectionLayoutGroupCustomItem(frame: CGRect(x: x, y: 0, width: size.width, height: size.height))
|
||||
}
|
||||
}
|
||||
let section = NSCollectionLayoutSection(group: group)
|
||||
section.orthogonalScrollingBehavior = .continuous
|
||||
section.interGroupSpacing = 8
|
||||
@@ -267,7 +269,6 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
|
||||
private func applySnapshot(animated: Bool) {
|
||||
guard dataSource != nil else { return }
|
||||
taskButton?.isEnabled = operation == nil && !selectionLocked && viewModel.canViewRecordedTasks
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||
if viewModel.detail != nil {
|
||||
snapshot.appendSections([.order, .filters])
|
||||
@@ -375,7 +376,6 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
|
||||
private func updateDownloadFooter() {
|
||||
navigationItem.rightBarButtonItem?.isEnabled = !selectionLocked
|
||||
taskButton?.isEnabled = operation == nil && !selectionLocked && viewModel.canViewRecordedTasks
|
||||
let model = downloadViewModel
|
||||
let identifier = "drone.materials.remote.download"
|
||||
switch model.phase {
|
||||
@@ -401,31 +401,6 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
/// 从张工已返回的任务中选择并进入状态页,不创建新任务或调用召唤接口。
|
||||
@objc private func viewTasksTapped() {
|
||||
guard operation == nil, !selectionLocked, viewModel.canViewRecordedTasks,
|
||||
viewModel.acceptsDownloadContext(), presentedViewController == nil else { return }
|
||||
if let task = viewModel.tasks.first, viewModel.tasks.count == 1 {
|
||||
openRecordedTask(id: task.id)
|
||||
return
|
||||
}
|
||||
let sheet = UIAlertController(title: "选择拍摄任务", message: nil, preferredStyle: .actionSheet)
|
||||
for task in viewModel.tasks {
|
||||
let spot = task.spotName.isEmpty ? "拍摄任务" : task.spotName
|
||||
let sequence = task.sequence.map { "第\($0)次拍摄" } ?? "拍摄记录"
|
||||
let title = "\(spot) · \(sequence)" + (task.createdAt.map { " · \($0)" } ?? "")
|
||||
sheet.addAction(UIAlertAction(title: title, style: .default) { [weak self] _ in self?.openRecordedTask(id: task.id) })
|
||||
}
|
||||
sheet.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
present(sheet, animated: true)
|
||||
}
|
||||
|
||||
private func openRecordedTask(id: Int) {
|
||||
guard operation == nil, !selectionLocked, viewModel.taskForViewing(id: id) != nil,
|
||||
navigationController?.topViewController === self else { return }
|
||||
navigationController?.pushViewController(taskControllerFactory(id, viewModel.order, viewModel.context), animated: true)
|
||||
}
|
||||
|
||||
private func previewFile(taskID: Int, fileID: Int) {
|
||||
guard operation == nil, let file = task(taskID)?.materials.first(where: { $0.id == fileID }), let url = file.previewURL else { return }
|
||||
preview(url: url, isVideo: file.fileType == 2, title: file.fileName ?? "原素材")
|
||||
@@ -447,6 +422,11 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
DroneDockHomeMetric.usableText(value) ?? fallback
|
||||
}
|
||||
|
||||
private func filterTitle(for id: Int?) -> String {
|
||||
id.flatMap { id in viewModel.spots.first { $0.id == id } }
|
||||
.map { Self.usable($0.name, fallback: "点位 \($0.id)") } ?? "全部点位"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user