feat: 完善机巢任务实时状态、双路图传与继续查看入口
This commit is contained in:
@@ -88,6 +88,13 @@ final class DroneDockShootingTaskViewModel {
|
||||
await refreshSnapshot(allowWhileStarting: false)
|
||||
}
|
||||
|
||||
/// 操作提交前仅作废在途读取,保留快照和操作防重锁;迟到的旧读取不能覆盖操作回查。
|
||||
@MainActor
|
||||
func invalidatePendingRefresh() {
|
||||
generation &+= 1
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
/// 后端建议间隔限制为 2~30 秒;缺失或无效时默认 5 秒,从上次请求结束后计时。
|
||||
var pollIntervalNanoseconds: UInt64 {
|
||||
let hint = response?.planeStatus?.pollHintMS ?? 5_000
|
||||
@@ -109,7 +116,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
let requestGeneration = generation
|
||||
let revisionAtRequest = snapshotRevision
|
||||
isLoading = true
|
||||
errorMessage = nil
|
||||
// 已失败的旧快照须等有效新响应再恢复操作,避免每次重查先短暂放开。
|
||||
defer {
|
||||
if generation == requestGeneration {
|
||||
isLoading = false
|
||||
@@ -137,7 +144,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
}
|
||||
// 迟到 HTTP 失败不能覆盖请求期间已收到的有效实时状态。
|
||||
guard snapshotRevision == revisionAtRequest else { return }
|
||||
errorMessage = error is CancellationError ? nil : error.localizedDescription
|
||||
if !(error is CancellationError) { errorMessage = error.localizedDescription }
|
||||
DroneDockDiagnostics.event("shooting.refresh_failed", taskID: taskID, fields: [
|
||||
"retained_snapshot": response != nil, "error": DroneDockDiagnostics.errorFields(error)
|
||||
])
|
||||
@@ -167,7 +174,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
"state_version": value.stateVersion as Any? ?? NSNull(),
|
||||
"plane_id": value.currentPlane?.id as Any? ?? NSNull()
|
||||
])
|
||||
if awaitingResummonSnapshot, [.navigating, .ready, .shooting, .paused, .returning, .completed].contains(resolvedDisplayPhase().0) {
|
||||
if awaitingResummonSnapshot, [.navigating, .ready, .shooting, .postShootUploading, .paused, .returning, .completed].contains(resolvedDisplayPhase().0) {
|
||||
awaitingResummonSnapshot = false
|
||||
}
|
||||
pendingAcceptedCommands.formIntersection(availableSafetyCommands)
|
||||
@@ -218,7 +225,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
/// 只在有效读取明确到达、锁定飞机并允许 start_shoot 后开放;Debug 真实页面保持禁用。
|
||||
var canStartShooting: Bool {
|
||||
startService != nil && context.canLoad && taskID > 0 && !identityInvalidated
|
||||
&& readAccessError == nil && !isLoading && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
&& readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
&& !hasSubmittedStart && !startOutcomeUnknown
|
||||
&& !commandOutcomeUnknown && !resummonOutcomeUnknown && !awaitingResummonSnapshot && pendingAcceptedCommands.isEmpty
|
||||
&& resolvedDisplayPhase().0 == .ready
|
||||
@@ -238,6 +245,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
return
|
||||
}
|
||||
guard !Task.isCancelled else { return }
|
||||
invalidatePendingRefresh()
|
||||
let planeID = response?.currentPlane?.id
|
||||
startGeneration &+= 1
|
||||
let requestGeneration = startGeneration
|
||||
@@ -308,7 +316,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
/// 安全指令不借用开拍门禁;需明确任务、锁定飞机、当前指令及注入的本地服务。
|
||||
func canSendCommand(_ command: DroneDockSafetyCommand) -> Bool {
|
||||
commandService != nil && context.canLoad && taskID > 0 && !identityInvalidated
|
||||
&& readAccessError == nil && !isLoading && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
&& readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
&& !startOutcomeUnknown && !commandOutcomeUnknown && !resummonOutcomeUnknown && !awaitingResummonSnapshot
|
||||
&& !pendingAcceptedCommands.contains(command)
|
||||
&& (response?.orderFlightTask?.id == taskID || response?.task?.id == taskID)
|
||||
@@ -328,6 +336,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
return
|
||||
}
|
||||
guard !Task.isCancelled else { return }
|
||||
invalidatePendingRefresh()
|
||||
commandGeneration &+= 1
|
||||
let requestGeneration = commandGeneration
|
||||
isSendingCommand = true
|
||||
@@ -387,7 +396,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
/// 此门禁用于客户端模拟交互,不代表后端已提供真实重试许可。
|
||||
var canResummon: Bool {
|
||||
resummonService != nil && context.canLoad && taskID > 0 && !identityInvalidated
|
||||
&& readAccessError == nil && !isLoading && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
&& readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
&& !startOutcomeUnknown && !commandOutcomeUnknown && !resummonOutcomeUnknown
|
||||
&& !hasSubmittedResummon && pendingAcceptedCommands.isEmpty
|
||||
&& resolvedDisplayPhase().0 == .failed
|
||||
@@ -407,6 +416,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
return
|
||||
}
|
||||
guard !Task.isCancelled else { return }
|
||||
invalidatePendingRefresh()
|
||||
resummonGeneration &+= 1
|
||||
let requestGeneration = resummonGeneration
|
||||
isResummoning = true
|
||||
@@ -493,6 +503,9 @@ final class DroneDockShootingTaskViewModel {
|
||||
if isLoading { return "正在获取任务状态" }
|
||||
}
|
||||
if resolvedDisplayPhase().0 == .failed { return "任务执行失败" }
|
||||
if resolvedDisplayPhase().0 == .postShootUploading {
|
||||
return usable(response?.ui?.title) ?? "拍摄完毕上传中"
|
||||
}
|
||||
return usable(response?.ui?.title) ?? usable(response?.task?.statusLabel)
|
||||
?? usable(response?.orderFlightTask?.statusLabel) ?? "状态待确认"
|
||||
}
|
||||
@@ -512,6 +525,9 @@ final class DroneDockShootingTaskViewModel {
|
||||
if let startErrorMessage { return startErrorMessage }
|
||||
if hasSubmittedStart { return "开始拍摄请求已受理,请刷新确认任务状态" }
|
||||
}
|
||||
if resolvedDisplayPhase().0 == .postShootUploading {
|
||||
return usable(response?.ui?.message) ?? "录制已结束,素材正在处理,请稍候。"
|
||||
}
|
||||
return usable(response?.ui?.message) ?? usable(response?.executeGate?.message) ?? "—"
|
||||
}
|
||||
|
||||
@@ -564,7 +580,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
}
|
||||
return DroneDockTaskPresentation(phase: phase, title: title, message: message,
|
||||
deviceStatus: deviceStatusText, action: action, actionTitle: actionTitle,
|
||||
isActionEnabled: enabled && readAccessError == nil && !isLoading && !isStartingShooting && !isSendingCommand && !isResummoning && !identityInvalidated && (errorMessage == nil || action == .refresh),
|
||||
isActionEnabled: enabled && readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && !identityInvalidated && (errorMessage == nil || action == .refresh),
|
||||
actionNote: phase == .failed && action == .retry && !canResummon && !isResummoning ? retryUnavailableNote : nil)
|
||||
}
|
||||
|
||||
@@ -678,6 +694,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
let known: [String: DroneDockTaskDisplayPhase] = [
|
||||
"going_to_spot": .navigating, "failed_restartable": .failed, "waiting_summon": .blocked,
|
||||
"navigating": .navigating, "arrived_pending_start": .ready, "shooting": .shooting,
|
||||
"post_shoot_uploading": .postShootUploading,
|
||||
"paused": .paused, "returning": .returning, "completed": .completed, "failed": .failed, "blocked": .blocked
|
||||
]
|
||||
let rawPhase = usable(response.ui?.phase)
|
||||
@@ -686,7 +703,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
if phase == .failed { return (.failed, false) }
|
||||
if statuses.contains(30) {
|
||||
if phase == .returning { return (.returning, false) }
|
||||
if let phase, [.navigating, .ready, .shooting, .paused].contains(phase) { return (.unknown, true) }
|
||||
if let phase, [.navigating, .ready, .shooting, .postShootUploading, .paused].contains(phase) { return (.unknown, true) }
|
||||
return (.completed, false)
|
||||
}
|
||||
if phase == .completed {
|
||||
@@ -722,6 +739,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
case .navigating: return "无人机正在前往拍摄点"
|
||||
case .ready: return "无人机已到达"
|
||||
case .shooting: return "正在拍摄"
|
||||
case .postShootUploading: return "拍摄完毕上传中"
|
||||
case .paused: return "拍摄已暂停"
|
||||
case .returning: return "无人机正在返航"
|
||||
case .failed: return "任务执行失败"
|
||||
|
||||
Reference in New Issue
Block a user