feat(drone-dock): 完善真实联调、状态轮询与准备页反馈
开放 Release 真实操作并保留 Debug 拦截;恢复前台 shooting 串行轮询;统一打印机巢请求与完整原值响应;优化长点位名称、未拍摄文案、报备失败及已结束任务提示,移除成功回执 UI。补充相关测试、离线策略检查和联调说明。
This commit is contained in:
@@ -181,6 +181,14 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
|
||||
/// 首次创建并召唤;成功后进入原任务,再次查看不经过创建或召唤接口。
|
||||
private func createSelectedTask() {
|
||||
DroneDockDiagnostics.event("preparation.confirm_tapped", taskID: viewModel.createdTask?.taskID, fields: [
|
||||
"order_number": viewModel.order.orderNumber as Any? ?? NSNull(),
|
||||
"scenic_id": viewModel.context.scenicID,
|
||||
"spot_id": viewModel.selectedSpotID as Any? ?? NSNull(),
|
||||
"air_line_id": viewModel.selectedRouteID as Any? ?? NSNull(),
|
||||
"enabled": viewModel.isPrimaryActionEnabled,
|
||||
"blocked": viewModel.isTaskSubmissionBlocked
|
||||
])
|
||||
guard !isRefreshing, !isStartingCreation else { return }
|
||||
if viewModel.canOpenShootingTask {
|
||||
_ = openShootingTask(automatically: false)
|
||||
@@ -199,17 +207,29 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
guard let self,
|
||||
let path = self.dataSource.indexPath(for: .shootResult) ?? self.dataSource.indexPath(for: .creationResult) else { return }
|
||||
self.collectionView.scrollToItem(at: path, at: .top, animated: true)
|
||||
self.showFilingFailureIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 只在准备页可见且召唤已成功时导航一次;返回后允许主动查看同一任务。
|
||||
/// 报备问题在明确提交失败后提示一次,后台及设备轮询不会反复弹窗。
|
||||
private func showFilingFailureIfNeeded() {
|
||||
guard isPageVisible, isApplicationActive, presentedViewController == nil,
|
||||
let failure = viewModel.summonFailure ?? viewModel.creationFailure,
|
||||
failure.requiresFiling else { return }
|
||||
let alert = UIAlertController(title: failure.title, message: failure.message, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "我知道了", style: .default))
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
/// 成功后自动导航一次;失败的已结束任务只在用户明确点击时查看原任务。
|
||||
@discardableResult
|
||||
private func openShootingTask(automatically: Bool) -> Bool {
|
||||
guard isPageVisible, isApplicationActive, viewModel.canOpenShootingTask,
|
||||
let taskID = viewModel.createdTask?.taskID,
|
||||
let navigationController, navigationController.topViewController === self,
|
||||
!automatically || automaticallyOpenedTaskID != taskID else { return false }
|
||||
!automatically || (viewModel.shootResponse != nil && automaticallyOpenedTaskID != taskID) else { return false }
|
||||
DroneDockDiagnostics.event("navigation.open_task", taskID: taskID)
|
||||
automaticallyOpenedTaskID = taskID
|
||||
let controller = taskControllerFactory(taskID, viewModel.order, viewModel.context)
|
||||
navigationController.pushViewController(controller, animated: true)
|
||||
@@ -284,17 +304,15 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
return cell
|
||||
case .creationResult:
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "creationResult", for: path) as! DroneDockTaskCreationResultCell
|
||||
cell.apply(task: self.viewModel.createdTask, errorMessage: self.viewModel.taskCreationErrorMessage,
|
||||
outcomeUnknown: self.viewModel.taskCreationOutcomeUnknown)
|
||||
if let failure = self.viewModel.creationFailure {
|
||||
cell.apply(failure: failure, identifier: "drone.preparation.creationResponse")
|
||||
}
|
||||
return cell
|
||||
case .shootResult:
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "creationResult", for: path) as! DroneDockTaskCreationResultCell
|
||||
cell.applyShoot(taskID: self.viewModel.createdTask?.taskID,
|
||||
dataJSON: self.viewModel.shootDataJSON,
|
||||
errorMessage: self.viewModel.shootErrorMessage,
|
||||
isLoading: self.viewModel.isSummoning,
|
||||
hasSucceeded: self.viewModel.shootResponse != nil,
|
||||
outcomeUnknown: self.viewModel.summonOutcomeUnknown)
|
||||
if let failure = self.viewModel.summonFailure {
|
||||
cell.apply(failure: failure, identifier: "drone.preparation.shootResponse")
|
||||
}
|
||||
return cell
|
||||
case .emptyPoints, .emptyRoutes, .status:
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "message", for: path) as! DronePreparationEmptyCell
|
||||
@@ -344,11 +362,10 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
} else {
|
||||
snapshot.appendItems([.status], toSection: .status)
|
||||
}
|
||||
if viewModel.createdTask != nil || (viewModel.errorMessage == nil && viewModel.projectInfo != nil && viewModel.taskCreationErrorMessage != nil) {
|
||||
if viewModel.creationFailure != nil {
|
||||
snapshot.appendItems([.creationResult], toSection: .creationResult)
|
||||
}
|
||||
if viewModel.createdTask != nil,
|
||||
viewModel.isSummoning || viewModel.shootResponse != nil || viewModel.shootErrorMessage != nil {
|
||||
if viewModel.summonFailure != nil {
|
||||
snapshot.appendItems([.shootResult], toSection: .shootResult)
|
||||
}
|
||||
snapshot.reconfigureItems(snapshot.itemIdentifiers.filter { existing.contains($0) })
|
||||
@@ -360,7 +377,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
|| previous.itemIdentifiers.contains(.emptyPoints) != snapshot.itemIdentifiers.contains(.emptyPoints)
|
||||
|| previous.itemIdentifiers.contains(.emptyRoutes) != snapshot.itemIdentifiers.contains(.emptyRoutes)
|
||||
|| previousRouteCount != snapshot.numberOfItems(inSection: .routes)
|
||||
if layoutChanged { collectionView.collectionViewLayout.invalidateLayout() }
|
||||
if layoutChanged || viewModel.projectInfo != nil { collectionView.collectionViewLayout.invalidateLayout() }
|
||||
dataSource.apply(snapshot, animatingDifferences: animated) { [weak self] in
|
||||
guard let self else { return }
|
||||
let kind = UICollectionView.elementKindSectionHeader
|
||||
@@ -374,21 +391,21 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func makeLayout() -> UICollectionViewLayout {
|
||||
UICollectionViewCompositionalLayout { [weak self] index, _ in
|
||||
UICollectionViewCompositionalLayout { [weak self] index, environment in
|
||||
guard let self, let section = Section(rawValue: index) else { return nil }
|
||||
let height: NSCollectionLayoutDimension
|
||||
let width: NSCollectionLayoutDimension
|
||||
switch section {
|
||||
case .order: height = .estimated(100); width = .fractionalWidth(1)
|
||||
case .points:
|
||||
height = .absolute(self.viewModel.spots.isEmpty ? 150 : 64)
|
||||
width = self.viewModel.spots.isEmpty ? .fractionalWidth(1) : .absolute(160)
|
||||
height = .absolute(self.viewModel.spots.isEmpty ? 150 : DronePreparationPointCell.preferredHeight(
|
||||
names: self.viewModel.spots.map(\.name), width: 200))
|
||||
width = self.viewModel.spots.isEmpty ? .fractionalWidth(1) : .absolute(200)
|
||||
case .routes:
|
||||
height = self.viewModel.routes.isEmpty ? .absolute(160) : .estimated(64)
|
||||
width = .fractionalWidth(1)
|
||||
case .status: height = .absolute(160); width = .fractionalWidth(1)
|
||||
case .creationResult: height = .absolute(380); width = .fractionalWidth(1)
|
||||
case .shootResult: height = .absolute(420); width = .fractionalWidth(1)
|
||||
case .creationResult, .shootResult: height = .estimated(100); width = .fractionalWidth(1)
|
||||
}
|
||||
let item = NSCollectionLayoutItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: height))
|
||||
let group = NSCollectionLayoutGroup.vertical(layoutSize: NSCollectionLayoutSize(widthDimension: width, heightDimension: height), subitems: [item])
|
||||
@@ -402,7 +419,9 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
&& (section == .points || (section == .routes && !self.viewModel.spots.isEmpty))
|
||||
if showsHeading {
|
||||
layout.boundarySupplementaryItems = [NSCollectionLayoutBoundarySupplementaryItem(
|
||||
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(section == .points ? 46 : 64)),
|
||||
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(section == .points ? 46 : DronePreparationHeadingView.preferredHeight(
|
||||
title: self.viewModel.selectedSpot.map { "\($0.name)的航线" } ?? "拍摄航线",
|
||||
detail: "共 \(self.viewModel.routes.count) 条", width: environment.container.effectiveContentSize.width - 32))),
|
||||
elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)]
|
||||
}
|
||||
return layout
|
||||
|
||||
Reference in New Issue
Block a user