feat: 完善机巢任务安全控制与状态诊断
同步新版飞控与 WebSocket 回执合同,完善独立指令等待、暂停继续和返航状态;增加真机诊断并优化倒计时与素材库展示。
This commit is contained in:
@@ -140,12 +140,14 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
super.viewWillAppear(animated)
|
||||
isPageVisible = true
|
||||
isApplicationActive = UIApplication.shared.applicationState == .active
|
||||
logPreparationEvent("preparation.page.appeared")
|
||||
refreshPreparation()
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
isPageVisible = false
|
||||
logPreparationEvent("preparation.page.disappeared", fields: ["moving_from_parent": isMovingFromParent])
|
||||
stopPlaneStatusPolling()
|
||||
refreshTask?.cancel()
|
||||
creationTask?.cancel()
|
||||
@@ -183,7 +185,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
|
||||
/// 首次创建并召唤;成功后进入原任务,再次查看不经过创建或召唤接口。
|
||||
private func createSelectedTask() {
|
||||
DroneDockDiagnostics.event("preparation.confirm_tapped", taskID: viewModel.createdTask?.taskID, fields: [
|
||||
logPreparationEvent("preparation.confirm_tapped", fields: [
|
||||
"order_number": viewModel.order.orderNumber as Any? ?? NSNull(),
|
||||
"scenic_id": viewModel.context.scenicID,
|
||||
"spot_id": viewModel.selectedSpotID as Any? ?? NSNull(),
|
||||
@@ -191,12 +193,18 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
"enabled": viewModel.isPrimaryActionEnabled,
|
||||
"blocked": viewModel.isTaskSubmissionBlocked
|
||||
])
|
||||
guard !isRefreshing, !isStartingCreation else { return }
|
||||
guard !isRefreshing, !isStartingCreation else {
|
||||
logPreparationEvent("preparation.confirm_rejected", fields: ["reason": "refresh_or_submission_in_progress"])
|
||||
return
|
||||
}
|
||||
if viewModel.canOpenShootingTask {
|
||||
_ = openShootingTask(automatically: false)
|
||||
return
|
||||
}
|
||||
guard viewModel.isPrimaryActionEnabled else { return }
|
||||
guard viewModel.isPrimaryActionEnabled else {
|
||||
logPreparationEvent("preparation.confirm_rejected", fields: ["reason": "primary_action_disabled"])
|
||||
return
|
||||
}
|
||||
isStartingCreation = true
|
||||
applySnapshot(animated: false)
|
||||
creationTask = Task { @MainActor [weak self] in
|
||||
@@ -204,6 +212,10 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
await self.viewModel.prepareAndSummon { [weak self] in self?.applySnapshot(animated: false) }
|
||||
guard !Task.isCancelled else { return }
|
||||
self.isStartingCreation = false
|
||||
self.logPreparationEvent("preparation.submission_presented", fields: [
|
||||
"has_summon_receipt": self.viewModel.shootResponse != nil,
|
||||
"can_open_task": self.viewModel.canOpenShootingTask,
|
||||
"error_message": self.viewModel.errorMessage as Any? ?? NSNull()])
|
||||
if self.openShootingTask(automatically: true) { return }
|
||||
self.applySnapshot(animated: true) { [weak self] in
|
||||
guard let self,
|
||||
@@ -230,11 +242,23 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
guard isPageVisible, isApplicationActive, viewModel.canOpenShootingTask,
|
||||
let taskID = viewModel.createdTask?.taskID,
|
||||
let navigationController, navigationController.topViewController === self,
|
||||
!automatically || (viewModel.shootResponse != nil && automaticallyOpenedTaskID != taskID) else { return false }
|
||||
DroneDockDiagnostics.event("navigation.open_task", taskID: taskID)
|
||||
!automatically || (viewModel.shootResponse != nil && automaticallyOpenedTaskID != taskID) else {
|
||||
logPreparationEvent("navigation.open_task_rejected", fields: ["automatic": automatically,
|
||||
"can_open_task": viewModel.canOpenShootingTask,
|
||||
"is_navigation_top": navigationController?.topViewController === self,
|
||||
"has_summon_receipt": viewModel.shootResponse != nil,
|
||||
"previously_opened_task_id": automaticallyOpenedTaskID as Any? ?? NSNull()])
|
||||
return false
|
||||
}
|
||||
automaticallyOpenedTaskID = taskID
|
||||
let controller = taskControllerFactory(taskID, viewModel.order, viewModel.context)
|
||||
let stack = navigationController.viewControllers
|
||||
let fields: [String: Any] = ["automatic": automatically, "task_id": taskID,
|
||||
"preparation_session_id": viewModel.diagnosticSessionID,
|
||||
"replaces_preparation": stack.count > 1,
|
||||
"navigation_stack_before": stack.map { String(describing: type(of: $0)) }]
|
||||
logPreparationEvent("navigation.open_task", fields: fields)
|
||||
(controller as? DroneDockShootingTaskViewController)?.recordNavigationEntry(source: "preparation", fields: fields)
|
||||
if stack.count > 1 {
|
||||
navigationController.setViewControllers(Array(stack.dropLast()) + [controller], animated: true)
|
||||
} else {
|
||||
@@ -278,6 +302,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
|
||||
@objc private func applicationWillResignActive() {
|
||||
isApplicationActive = false
|
||||
logPreparationEvent("preparation.app.inactive")
|
||||
stopPlaneStatusPolling()
|
||||
footerView.apply(preparationViewModel: viewModel, isRefreshing: isRefreshing || isStartingCreation,
|
||||
isLocalSimulation: simulationRecordsProvider != nil)
|
||||
@@ -285,9 +310,23 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
|
||||
@objc private func applicationDidBecomeActive() {
|
||||
isApplicationActive = true
|
||||
logPreparationEvent("preparation.app.active")
|
||||
startPlaneStatusPolling()
|
||||
}
|
||||
|
||||
/// 准备页 UI 事件沿用业务会话,可与后续任务页的导航记录关联。
|
||||
private func logPreparationEvent(_ name: String, fields: [String: Any] = [:]) {
|
||||
var fields = fields
|
||||
fields["source"] = simulationRecordsProvider == nil ? "preparation_page" : "local_simulation"
|
||||
fields["task_id"] = viewModel.createdTask?.taskID as Any? ?? NSNull()
|
||||
fields["page_visible"] = isPageVisible
|
||||
fields["app_active"] = isApplicationActive
|
||||
fields["refreshing"] = isRefreshing
|
||||
fields["submitting"] = isStartingCreation
|
||||
fields["debug_flight_blocked"] = DeviceCommandDebugPolicy.blocksFlightRequests
|
||||
viewModel.recordPreparationEvent(name, fields: fields)
|
||||
}
|
||||
|
||||
private func configureDataSource() {
|
||||
dataSource = UICollectionViewDiffableDataSource<Section, Item>(collectionView: collectionView) { [weak self] list, path, item in
|
||||
guard let self else { return nil }
|
||||
|
||||
Reference in New Issue
Block a user