feat: 完善机巢图传、拍摄阶段与任务交互

- 完善双路 RTC 接收、首帧切换及拍摄结束后的本地播放释放
- 对齐无人机状态枚举与正常拍完返航标记,新增到达后本地倒计时
- 补充准备页电量与前往回执,进入任务时移除准备页路由
- 对齐拍摄中和拍摄完成原型布局,移除详情按钮
- 补充隔离测试、接口记录与项目约定

验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
This commit is contained in:
2026-11-03 16:43:23 +08:00
parent 0ed0077ec4
commit 54210925f0
33 changed files with 3242 additions and 205 deletions
@@ -70,13 +70,13 @@ struct DroneDockHomeAirport: Decodable, Equatable, Sendable {
let snNumber: String?
/// 后端设备所属景区 ID。
let scenicAreaID: Int?
/// 原始在线状态;尚未取得完整枚举约定。
/// 飞机表在线标记:1 在线,其他已提供整数为离线;忙闲以 workStatus 为准。
let onlineStatus: Int?
/// 原始工作状态;不据此决定设备可否执行任务。
let workStatus: Int?
/// 后端工作状态展示文案。
let workStatusLabel: String?
/// 原始接单配置;不等同于本次起飞许可。
/// 接单配置:1 可接单、2 暂停接单;不等同于本次起飞许可。
let isReceiveOrder: Int?
/// 任务类型原始值;当前样本为 null,暂不假定其枚举或值类型。
let taskType: DroneDockHomeJSONValue?
@@ -1,6 +1,6 @@
import Foundation
/// shoot 业务成功后的原始 data 回执,不假设或构造飞机、任务及飞行阶段字段。
/// 保留 shoot 原始 data,并读取明确的同任务前往回执;不补造飞机或飞行阶段字段。
struct DroneDockShootResponse: Decodable, Equatable, Sendable {
/// 完整 data JSON;nil 表示统一客户端未提供 data,不补造 null 或空对象。
let dataJSON: String?
@@ -15,6 +15,30 @@ struct DroneDockShootResponse: Decodable, Equatable, Sendable {
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
dataJSON = String(decoding: try encoder.encode(DroneDockShootJSONSnapshot(value: raw)), as: UTF8.self)
}
/// 只认同一订单任务明确受理的前往阶段,用于进页过渡;回执不代表已经起飞或到达。
func confirmsTravel(taskID: Int, orderNumber: String?, scenicID: Int) -> Bool {
guard taskID > 0, scenicID > 0, let orderNumber, !orderNumber.isEmpty, let dataJSON,
let receipt = try? JSONDecoder().decode(DroneDockSummonProgressReceipt.self, from: Data(dataJSON.utf8)),
receipt.accepted == true, receipt.ui?.phase == "going_to_spot",
receipt.orderFlightTask?.id == taskID,
receipt.orderFlightTask?.orderNumber == orderNumber,
receipt.orderFlightTask?.scenicID == scenicID else { return false }
return receipt.orderFlightTaskID == nil || receipt.orderFlightTaskID == taskID
}
}
/// 首次召唤的已约定阶段和任务身份,仅支持显示前往中的过渡,不据此开放任何操作。
private struct DroneDockSummonProgressReceipt: Decodable {
let accepted: Bool?
let ui: DroneDockShootingUI?
let orderFlightTaskID: Int?
let orderFlightTask: DroneDockResummonReceiptIdentity.TaskIdentity?
/// 顶层 task_id 是航线任务,不参与订单任务匹配。
private enum CodingKeys: String, CodingKey {
case accepted, ui, orderFlightTaskID = "order_flight_task_id", orderFlightTask = "order_flight_task"
}
}
/// 重新召唤回执中可核对的订单任务身份;顶层 task_id 属于实际航线任务,不作订单任务 ID 使用。
@@ -16,6 +16,8 @@ struct DroneDockShootingResponse: Decodable, Equatable, Sendable {
let metricsUpdatedAt: String?
/// 设备缓存过期时保留数值,但标为非实时读数。
let metricsStale: Bool?
/// 后端确认本批次正常拍完并开始返航;缺失表示旧合同,不能从工作态忙闲推断。
let shootCompleteReturning: Bool?
/// 后端若明确提供订单号则保留,不由请求上下文伪造响应身份。
let orderNumber: String?
/// 实测返回的订单飞行任务身份;存在时必须与请求上下文核对。
@@ -48,6 +50,7 @@ struct DroneDockShootingResponse: Decodable, Equatable, Sendable {
case orderFlightTaskID = "order_flight_task_id", stateVersion = "state_version"
case executionBatch = "execution_batch", snapshotKind = "snapshot_kind"
case stateUpdatedAt = "state_updated_at", metricsUpdatedAt = "metrics_updated_at", metricsStale = "metrics_stale"
case shootCompleteReturning = "shoot_complete_returning"
case orderNumber = "order_number", orderFlightTask = "order_flight_task", task
case scenic, scenicSpot = "scenic_spot", airLine = "air_line"
case header, currentPlane = "current_plane", executeGate = "execute_gate", ui
@@ -64,6 +67,7 @@ struct DroneDockShootingResponse: Decodable, Equatable, Sendable {
stateUpdatedAt = try container.decodeIfPresent(String.self, forKey: .stateUpdatedAt)
metricsUpdatedAt = try container.decodeIfPresent(String.self, forKey: .metricsUpdatedAt)
metricsStale = try container.decodeIfPresent(Bool.self, forKey: .metricsStale)
shootCompleteReturning = try container.decodeIfPresent(Bool.self, forKey: .shootCompleteReturning)
orderNumber = try container.decodeIfPresent(String.self, forKey: .orderNumber)
orderFlightTask = try container.decodeIfPresent(DroneDockShootingTaskIdentity.self, forKey: .orderFlightTask)
task = try container.decodeIfPresent(DroneDockShootingTaskIdentity.self, forKey: .task)
@@ -91,22 +95,25 @@ struct DroneDockShootingTaskIdentity: Decodable, Equatable, Sendable {
let orderNumber: String?
/// 任务所属景区。
let scenicID: Int?
/// 后端原始任务状态,不与订单状态混用。
/// 订单飞行任务状态:10 待执行、20 执行中、30 成功、40 失败、50 取消、60 待确认。
let status: Int?
/// 服务端任务状态文案。
let statusLabel: String?
/// 实测航线任务状态,与订单飞行任务状态分别保留。
/// 航线状态独立保留:29/39/49/91 失败,90 取消,24/30/40 为录制后的素材处理。
let waylineStatus: Int?
/// 服务端航线状态文案;执行失败优先于笼统的订单任务执行中。
let waylineStatusLabel: String?
/// 服务端实际记录的任务结果原因,空值不视为具体失败说明。
let resultMessage: String?
/// 任务结果原因码;return_home 表示手动返航中断,不能展示正常拍完提示。
let resultCode: String?
/// 已确认嵌套任务字段映射。
private enum CodingKeys: String, CodingKey {
case id, orderNumber = "order_number", scenicID = "scenic_id", status, statusLabel = "status_label"
case waylineStatus = "wayline_status", waylineStatusLabel = "wayline_status_label"
case resultMessage = "result_message"
case resultCode = "result_code"
}
}
@@ -169,7 +176,7 @@ struct DroneDockShootingPlane: Decodable, Equatable, Sendable {
let id: Int?
/// 当前设备序列号。
let snNumber: String?
/// 服务端连接状态;实测 2 为离线,不从电量推导连接状态。
/// 飞机表在线标记:1 在线,0/2 等非 1 为离线;不覆盖明确的机巢工作态。
let onlineStatus: Int?
/// 文档工作状态:0 离线、1 空闲、2 拍摄中;不据此推断返航完成。
let workStatus: Int?
@@ -213,15 +220,28 @@ struct DroneDockShootingUI: Decodable, Equatable, Sendable {
let title: String?
/// 服务端阶段说明,不由 GET 请求成功拼造飞行进度。
let message: String?
/// 拍摄环节子阶段,shoot_done_returning 表示正常拍完后开始返航。
let waylineStage: String?
/// 页面层的正常拍完返航标记,和顶层字段共同保留。
let shootCompleteReturning: Bool?
/// 服务端实际提供的安全指令;缺失时保持未知,不据阶段文案自行补齐。
let commands: [DroneDockShootingCommand]?
/// 保留既有展示构造方式,新增动作列表默认为未知。
init(phase: String?, title: String?, message: String?, commands: [DroneDockShootingCommand]? = nil) {
init(phase: String?, title: String?, message: String?, commands: [DroneDockShootingCommand]? = nil,
waylineStage: String? = nil, shootCompleteReturning: Bool? = nil) {
self.phase = phase
self.title = title
self.message = message
self.commands = commands
self.waylineStage = waylineStage
self.shootCompleteReturning = shootCompleteReturning
}
/// 保留现有页面字段,并映射新增返航标记的原始命名。
private enum CodingKeys: String, CodingKey {
case phase, title, message, commands
case waylineStage = "wayline_stage", shootCompleteReturning = "shoot_complete_returning"
}
}
@@ -12,6 +12,8 @@ enum DroneDockTaskDisplayPhase: String, Equatable, Sendable {
case shooting
/// 录制已结束,素材仍在下载、上传或渲染,尚未就绪。
case postShootUploading
/// 录制已结束,但素材上传或渲染失败;可查看素材,不代表可重新召唤。
case postShootUploadFailed
/// 服务端明确已暂停。
case paused
/// 服务端明确正在返航。
@@ -62,10 +64,13 @@ struct DroneDockTaskPresentation: Equatable, Sendable {
let isActionEnabled: Bool
/// 主动作下方的真实设备限制说明,未提供时不展示。
let actionNote: String?
/// 已到达阶段的本地展示倒计时;零秒不表示后端已经开始拍摄。
let countdownSeconds: Int?
/// 创建状态展示;动作提示默认为空,既有非失败状态保持原布局。
init(phase: DroneDockTaskDisplayPhase, title: String, message: String, deviceStatus: String,
action: DroneDockTaskDisplayAction, actionTitle: String?, isActionEnabled: Bool, actionNote: String? = nil) {
action: DroneDockTaskDisplayAction, actionTitle: String?, isActionEnabled: Bool, actionNote: String? = nil,
countdownSeconds: Int? = nil) {
self.phase = phase
self.title = title
self.message = message
@@ -74,5 +79,6 @@ struct DroneDockTaskPresentation: Equatable, Sendable {
self.actionTitle = actionTitle
self.isActionEnabled = isActionEnabled
self.actionNote = actionNote
self.countdownSeconds = countdownSeconds
}
}
@@ -99,7 +99,7 @@ final class DroneDockLiveViewModel {
case .failed, .unavailable: return "重试"
case .localPreview: return "重新加载模拟图传"
case .connecting: return nil
case .playing: return "刷新图传"
case .playing: return nil
}
}
@@ -137,8 +137,14 @@ final class DroneDockLiveViewModel {
let canKeepSession = keepingPlayback && playbackSessionID != nil
&& sameDevice
&& rtcConfigurations.first?.appID == configurations.first?.appID
rtcConfigurations = configurations
rtcConfiguration = configurations.first
rtcConfigurations = configurations.map { incoming in
// live 每次可能生成新 user_id;补流时保留尚未临期的原入房身份,避免销毁健康房间。
guard canKeepSession, let previous = rtcConfigurations.first(where: { $0.role == incoming.role }),
previous.appID == incoming.appID, previous.roomID == incoming.roomID,
previous.userID != incoming.userID, previous.expiresAt.timeIntervalSince(now()) > 30 else { return incoming }
return previous
}
rtcConfiguration = rtcConfigurations.first
if !canKeepSession {
activeRole = nil
playbackSessionID = UUID()
@@ -430,15 +430,17 @@ final class DroneDockPreparationViewModel {
guard let selectedRoute else { return "\(selectedSpot.name) · 未选航线" }
return "\(selectedSpot.name) · \(selectedRoute.name)"
}
/// 优先展示服务端推荐无人机的完整文案,不自行重选列表中的另一架。
/// 展示后端推荐设备,状态文案缺少电量时补充电量字段,不重选设备或把未知电量当零。
var deviceStatusText: String {
guard let planeStatus else { return "状态待确认" }
guard let recommendation = planeStatus.recommend else {
return planeStatus.planes.isEmpty ? "暂无无人机" : "状态待确认"
}
if let text = DroneDockHomeMetric.usableText(recommendation.statusText) { return text }
let state = DroneDockHomeMetric.usableText(recommendation.workStatusLabel) ?? "状态待确认"
let battery = DroneDockHomeMetric.usableText(recommendation.batteryLabel)
let state = DroneDockHomeMetric.usableText(recommendation.statusText)
?? DroneDockHomeMetric.usableText(recommendation.workStatusLabel) ?? "状态待确认"
let percent = recommendation.batteryPercent.flatMap { (0...100).contains($0) ? $0 : nil }
let battery = DroneDockHomeMetric.usableText(recommendation.batteryLabel) ?? percent.map { "电量 \($0)%" }
if state.contains("%") || state.contains("%") || battery.map({ state.contains($0) }) == true { return state }
return battery.map { "\(state) · \($0)" } ?? state
}
/// 状态颜色只映射文档定义的工作状态,未知值不展示为空闲。
@@ -50,6 +50,8 @@ final class DroneDockShootingTaskViewModel {
private let commandService: (any DroneDockCommandSending)?
private let resummonService: (any DroneDockResummonServing)?
private let currentContext: @MainActor @Sendable () -> DroneDockHomeContext
private let countdownNow: @Sendable () -> ContinuousClock.Instant
private var arrivalCountdownDeadlines: [String: ContinuousClock.Instant] = [:]
/// 无权限或登录失效后停止自动读取,旧数据仅用于展示。
private(set) var readAccessError: String?
private var snapshotRevision = 0
@@ -62,6 +64,8 @@ final class DroneDockShootingTaskViewModel {
private var resummonGeneration = 0
private var didSendResummon = false
private var awaitingResummonSnapshot = false
// 仅在首份完整快照返回之前使用同一任务的 going_to_spot 回执,不补造设备状态。
private var hasInitialTravelReceipt: Bool
// 回查仍提供的已受理指令分别保留防重锁,避免另一条指令受理覆盖旧锁。
private var pendingAcceptedCommands: Set<DroneDockSafetyCommand> = []
@@ -71,6 +75,8 @@ final class DroneDockShootingTaskViewModel {
startService: (any DroneDockStartShooting)? = nil,
commandService: (any DroneDockCommandSending)? = nil,
resummonService: (any DroneDockResummonServing)? = nil,
initialSummonReceipt: DroneDockShootResponse? = nil,
countdownNow: @escaping @Sendable () -> ContinuousClock.Instant = { ContinuousClock.now },
currentContext: @escaping @MainActor @Sendable () -> DroneDockHomeContext) {
self.context = context
self.taskID = taskID
@@ -80,6 +86,9 @@ final class DroneDockShootingTaskViewModel {
self.commandService = commandService
self.resummonService = resummonService
self.currentContext = currentContext
self.countdownNow = countdownNow
self.hasInitialTravelReceipt = context.canLoad && initialSummonReceipt?.confirmsTravel(
taskID: taskID, orderNumber: order.orderNumber, scenicID: context.scenicID) == true
}
/// 页面可见时读取同一任务;刷新及普通失败保留旧快照,身份失效立即清除。
@@ -166,6 +175,10 @@ final class DroneDockShootingTaskViewModel {
}
}
response = value
if resolvedDisplayPhase().0 == .ready, arrivalCountdownDeadlines[recordingExecutionID] == nil {
arrivalCountdownDeadlines[recordingExecutionID] = countdownNow().advanced(by: .seconds(30))
}
hasInitialTravelReceipt = false
errorMessage = nil
snapshotRevision &+= 1
DroneDockDiagnostics.event("shooting.snapshot_applied", taskID: taskID, fields: [
@@ -174,7 +187,7 @@ final class DroneDockShootingTaskViewModel {
"state_version": value.stateVersion as Any? ?? NSNull(),
"plane_id": value.currentPlane?.id as Any? ?? NSNull()
])
if awaitingResummonSnapshot, [.navigating, .ready, .shooting, .postShootUploading, .paused, .returning, .completed].contains(resolvedDisplayPhase().0) {
if awaitingResummonSnapshot, [.navigating, .ready, .shooting, .postShootUploading, .postShootUploadFailed, .paused, .returning, .completed].contains(resolvedDisplayPhase().0) {
awaitingResummonSnapshot = false
}
pendingAcceptedCommands.formIntersection(availableSafetyCommands)
@@ -206,6 +219,8 @@ final class DroneDockShootingTaskViewModel {
generation &+= 1
isLoading = false
if !context.hasSameIdentity(as: currentContext()) { identityInvalidated = true }
if identityInvalidated || !preservingSnapshot { hasInitialTravelReceipt = false }
if identityInvalidated || !preservingSnapshot { arrivalCountdownDeadlines.removeAll() }
if identityInvalidated {
response = nil
startResponse = nil
@@ -316,6 +331,7 @@ final class DroneDockShootingTaskViewModel {
/// 安全指令不借用开拍门禁;需明确任务、锁定飞机、当前指令及注入的本地服务。
func canSendCommand(_ command: DroneDockSafetyCommand) -> Bool {
commandService != nil && context.canLoad && taskID > 0 && !identityInvalidated
&& !isTaskAwaitingConfirmation
&& readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
&& !startOutcomeUnknown && !commandOutcomeUnknown && !resummonOutcomeUnknown && !awaitingResummonSnapshot
&& !pendingAcceptedCommands.contains(command)
@@ -396,6 +412,7 @@ final class DroneDockShootingTaskViewModel {
/// 此门禁用于客户端模拟交互,不代表后端已提供真实重试许可。
var canResummon: Bool {
resummonService != nil && context.canLoad && taskID > 0 && !identityInvalidated
&& !isTaskAwaitingConfirmation
&& readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
&& !startOutcomeUnknown && !commandOutcomeUnknown && !resummonOutcomeUnknown
&& !hasSubmittedResummon && pendingAcceptedCommands.isEmpty
@@ -496,43 +513,102 @@ final class DroneDockShootingTaskViewModel {
usable(response?.currentPlane?.statusText) ?? usable(response?.currentPlane?.workStatusLabel) ?? "—"
}
/// 使用服务端阶段标题或任务状态,不从 GET 成功推导到达或拍摄完成。
/// 录制完成与素材就绪分别保留;只由可信阶段触发完成提示,不修改后端任务状态。
var isRecordingFinished: Bool {
let phase = resolvedDisplayPhase().0
return [.postShootUploading, .postShootUploadFailed, .completed].contains(phase)
|| (phase == .failed && hasMediaProcessingFailure)
}
/// 只有录制正常结束或素材就绪才弹出完成提示,素材处理失败只展示失败状态。
var shouldPresentRecordingCompletion: Bool {
[.postShootUploading, .completed].contains(resolvedDisplayPhase().0)
}
/// 正常拍完后的返航说明仅取本批次可信完成阶段,上传/渲染或显式清标记后不沿用。
var isShootCompleteReturning: Bool {
guard resolvedDisplayPhase().0 == .postShootUploading else { return false }
let waylines = [response?.task?.waylineStatus, response?.orderFlightTask?.waylineStatus].compactMap { $0 }
guard !waylines.contains(where: { [30, 40, 50].contains($0) }) else { return false }
let flags = [response?.shootCompleteReturning, response?.ui?.shootCompleteReturning].compactMap { $0 }
if flags.contains(false) { return false }
if flags.contains(true) || response?.ui?.waylineStage == "shoot_done_returning" { return true }
// 旧回包仍保留明确的设备返航文案;新合同不再依赖只有忙闲的 work_status。
guard response?.ui?.waylineStage == nil else { return false }
return ["返航中", "正在返航"].contains(usable(response?.currentPlane?.workStatusLabel) ?? "")
}
/// 完成提示按当前任务的执行批次去重,旧快照仍由统一版本校验拒绝。
var recordingExecutionID: String {
"\(taskID):\(response?.executionBatch ?? 0)"
}
/// App 首次确认本批次到达后显示 30 秒本地倒计时;到零仍等待后端阶段,不触发控制或状态读取。
var countdownRemainingSeconds: Int? {
guard !identityInvalidated, readAccessError == nil, resolvedDisplayPhase().0 == .ready,
let deadline = arrivalCountdownDeadlines[recordingExecutionID] else { return nil }
let remaining = countdownNow().duration(to: deadline)
guard remaining > .zero else { return 0 }
let parts = remaining.components
return Int(min(30, parts.seconds + (parts.attoseconds > 0 ? 1 : 0)))
}
/// 根据可信阶段使用产品标题,其余保留服务端标题,不从 GET 成功推导到达或拍摄完成。
var statusTitle: String {
if response == nil {
if errorMessage != nil { return "任务状态读取失败" }
if hasInitialTravelReceipt { return "无人机正在赶来" }
if isLoading { return "正在获取任务状态" }
}
if resolvedDisplayPhase().0 == .navigating { return "无人机正在赶来" }
if resolvedDisplayPhase().0 == .shooting { return "无人机正在拍摄中" }
if resolvedDisplayPhase().0 == .failed { return "任务执行失败" }
if resolvedDisplayPhase().0 == .postShootUploadFailed { return mediaFailureTitle }
if isTaskAwaitingConfirmation { return "任务待确认" }
if resolvedDisplayPhase().0 == .postShootUploading {
return usable(response?.ui?.title) ?? "拍摄完毕上传中"
return "拍摄已完成"
}
return usable(response?.ui?.title) ?? usable(response?.task?.statusLabel)
?? usable(response?.orderFlightTask?.statusLabel) ?? "状态待确认"
}
/// 保留服务端阶段说明;操作结果未知时优先提示核对,不伪装为设备已执行。
/// 拍摄阶段使用产品提示,其余保留服务端说明;操作结果未知时优先提示核对。
var statusMessage: String {
if response == nil {
if let errorMessage { return errorMessage }
if hasInitialTravelReceipt { return "召唤已受理,正在等待设备到达确认,请留在拍摄点。" }
if isLoading { return "正在读取当前拍摄任务" }
}
if let resummonErrorMessage { return resummonErrorMessage }
if awaitingResummonSnapshot { return "重新召唤请求已受理,请刷新核对任务状态" }
if let commandErrorMessage { return commandErrorMessage }
if resolvedDisplayPhase().0 == .failed { return failureMessage }
if resolvedDisplayPhase().0 == .postShootUploadFailed { return mediaFailureMessage }
if isTaskAwaitingConfirmation { return usable(response?.ui?.message) ?? "任务结果待确认,请刷新核对状态。" }
if startOutcomeUnknown, let startErrorMessage { return startErrorMessage }
if resolvedDisplayPhase().0 == .ready {
if let startErrorMessage { return startErrorMessage }
if hasSubmittedStart { return "开始拍摄请求已受理,请刷新确认任务状态" }
}
if resolvedDisplayPhase().0 == .postShootUploading {
return usable(response?.ui?.message) ?? "录制已结束,素材正在处理,请稍候。"
let waylines = [response?.task?.waylineStatus, response?.orderFlightTask?.waylineStatus]
let note: String
if isShootCompleteReturning { note = "无人机正在返航,请留意现场。" }
else if waylines.contains(30) { note = "素材上传中,可在素材库查看进度。" }
else if waylines.contains(40) { note = "素材渲染中,可在素材库查看进度。" }
else { note = "素材处理中,可在素材库查看进度。" }
return "本次拍摄已结束,可前往查看素材。\n" + note
}
if resolvedDisplayPhase().0 == .shooting { return "请关注现场及实时画面。\n请勿关闭本页或息屏。" }
return usable(response?.ui?.message) ?? usable(response?.executeGate?.message) ?? "—"
}
/// 组合可信阶段与本轮可用动作,不从请求成功、执行中或指令列表推断飞行进度。
var presentation: DroneDockTaskPresentation {
if response == nil, hasInitialTravelReceipt, errorMessage == nil, !identityInvalidated {
return DroneDockTaskPresentation(phase: .navigating, title: statusTitle, message: statusMessage,
deviceStatus: deviceStatusText, action: .none, actionTitle: nil, isActionEnabled: false)
}
if response == nil, isLoading {
return DroneDockTaskPresentation(phase: .loading, title: "正在获取任务状态", message: "正在读取当前拍摄任务",
deviceStatus: deviceStatusText, action: .none, actionTitle: nil, isActionEnabled: false)
@@ -548,6 +624,10 @@ final class DroneDockShootingTaskViewModel {
let actionTitle: String?
let enabled: Bool
switch phase {
case .shooting:
action = .none
actionTitle = "拍摄中"
enabled = false
case .ready where hasSubmittedStart || startOutcomeUnknown || commandOutcomeUnknown || resummonOutcomeUnknown:
action = .refresh
actionTitle = "刷新状态"
@@ -561,7 +641,7 @@ final class DroneDockShootingTaskViewModel {
action = .resume
actionTitle = usable(response?.executeGate?.primaryActionLabel) ?? "继续拍摄"
enabled = false
case .completed:
case .completed, .postShootUploading, .postShootUploadFailed:
action = .materials
actionTitle = "查看素材"
enabled = true
@@ -581,7 +661,8 @@ final class DroneDockShootingTaskViewModel {
return DroneDockTaskPresentation(phase: phase, title: title, message: message,
deviceStatus: deviceStatusText, action: action, actionTitle: actionTitle,
isActionEnabled: enabled && readAccessError == nil && !isStartingShooting && !isSendingCommand && !isResummoning && !identityInvalidated && (errorMessage == nil || action == .refresh),
actionNote: phase == .failed && action == .retry && !canResummon && !isResummoning ? retryUnavailableNote : nil)
actionNote: phase == .failed && action == .retry && !canResummon && !isResummoning ? retryUnavailableNote : nil,
countdownSeconds: countdownRemainingSeconds)
}
/// 后端六项展示读数,不解析文案反推设备状态或数值单位。
@@ -683,27 +764,34 @@ final class DroneDockShootingTaskViewModel {
&& scenicIDs.allSatisfy { $0 == context.scenicID }
}
/// 只认识显式阶段和已确认任务状态;91 为真实航线执行失败,不把订单状态 20 当作正在拍摄。
/// 按任务终态、明确 UI 阶段与航线失败判断,不把机巢忙闲或订单执行中当作拍摄进度。
private func resolvedDisplayPhase() -> (DroneDockTaskDisplayPhase, Bool) {
guard let response else { return (.unknown, false) }
let tasks = [response.task, response.orderFlightTask].compactMap { $0 }
let statuses = Set(tasks.compactMap(\.status))
if tasks.contains(where: { $0.waylineStatus == 91 }) || statuses.contains(40) { return (.failed, false) }
if statuses.contains(50) { return (.blocked, false) }
let waylines = Set(tasks.compactMap(\.waylineStatus))
let rawPhase = usable(response.ui?.phase)
if statuses.contains(50) || waylines.contains(90) || statuses.contains(60) { return (.blocked, false) }
if tasks.contains(where: { $0.resultCode == "return_home" }) { return (.failed, false) }
if !waylines.isDisjoint(with: [29, 39, 49, 91]) || statuses.contains(40) {
let isMediaFailure = rawPhase == "post_shoot_upload_failed"
|| (hasMediaProcessingFailure && rawPhase != "failed_restartable")
return (isMediaFailure ? .postShootUploadFailed : .failed, false)
}
if statuses.count > 1 { return (.unknown, true) }
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,
"post_shoot_upload_failed": .postShootUploadFailed,
"paused": .paused, "returning": .returning, "completed": .completed, "failed": .failed, "blocked": .blocked
]
let rawPhase = usable(response.ui?.phase)
let phase = rawPhase.flatMap { known[$0] }
if rawPhase != nil && phase == nil { return (.unknown, false) }
if phase == .failed { return (.failed, false) }
if statuses.contains(30) {
if phase == .returning { return (.returning, false) }
if let phase, [.navigating, .ready, .shooting, .postShootUploading, .paused].contains(phase) { return (.unknown, true) }
if let phase, [.navigating, .ready, .shooting, .postShootUploading, .postShootUploadFailed, .paused].contains(phase) { return (.unknown, true) }
return (.completed, false)
}
if phase == .completed {
@@ -725,21 +813,28 @@ final class DroneDockShootingTaskViewModel {
if conflict { return "状态待确认" }
let tasks = [response?.task, response?.orderFlightTask].compactMap { $0 }
if phase == .failed { return "任务执行失败" }
if phase == .postShootUploadFailed { return mediaFailureTitle }
if phase == .blocked, isTaskAwaitingConfirmation { return "任务待确认" }
if phase == .blocked, let cancelled = tasks.first(where: { $0.status == 50 }) {
return usable(cancelled.statusLabel) ?? "任务已取消"
}
if phase == .blocked, tasks.contains(where: { $0.waylineStatus == 90 }) { return "任务已取消" }
if phase == .blocked, response?.ui?.phase == "arrived_pending_start" { return "暂不可开始拍摄" }
if phase == .postShootUploading { return "拍摄已完成" }
if phase == .completed {
return usable(response?.ui?.phase == "completed" ? response?.ui?.title : nil)
?? tasks.first(where: { $0.status == 30 }).flatMap { usable($0.statusLabel) } ?? "拍摄已完成"
}
if phase == .unknown { return "状态待确认" }
if phase == .navigating { return "无人机正在赶来" }
if phase == .shooting { return "无人机正在拍摄中" }
if let title = usable(response?.ui?.title) { return title }
switch phase {
case .navigating: return "无人机正在前往拍摄点"
case .navigating: return "无人机正在赶来"
case .ready: return "无人机已到达"
case .shooting: return "正在拍摄"
case .postShootUploading: return "拍摄完毕上传中"
case .postShootUploading: return "拍摄已完成"
case .postShootUploadFailed: return mediaFailureTitle
case .paused: return "拍摄已暂停"
case .returning: return "无人机正在返航"
case .failed: return "任务执行失败"
@@ -756,20 +851,54 @@ final class DroneDockShootingTaskViewModel {
?? usable(response?.executeGate?.message) ?? usable(response?.ui?.message) ?? "暂未返回具体失败原因"
}
/// 39/49 表示录制后的素材处理失败,不能据此生成起飞或重召唤许可。
private var hasMediaProcessingFailure: Bool {
[response?.task?.waylineStatus, response?.orderFlightTask?.waylineStatus]
.compactMap { $0 }.contains { [39, 49].contains($0) }
}
private var isTaskAwaitingConfirmation: Bool {
response?.orderFlightTask?.status == 60 || response?.task?.status == 60
}
private var mediaFailureTitle: String {
if response?.ui?.phase == "post_shoot_upload_failed", let title = usable(response?.ui?.title) { return title }
return [response?.task?.waylineStatus, response?.orderFlightTask?.waylineStatus].contains(49)
? "素材渲染失败" : "素材上传失败"
}
private var mediaFailureMessage: String {
usable(response?.orderFlightTask?.resultMessage) ?? usable(response?.task?.resultMessage)
?? usable(response?.ui?.message) ?? usable(response?.task?.waylineStatusLabel)
?? usable(response?.orderFlightTask?.waylineStatusLabel) ?? "素材处理失败,请前往素材库查看。"
}
/// 工作态优先;工作态缺失或未识别时才用飞机表在线标记保守兜底。
private var isResummonDeviceOffline: Bool {
switch response?.currentPlane?.workStatus {
case 0: return true
case 1, 2: return false
default:
if let online = response?.currentPlane?.onlineStatus { return online != 1 }
return usable(response?.currentPlane?.workStatusLabel) == "离线"
}
}
/// 明确离线或返航时保持禁用,不从普通空闲文案推导后端重试许可。
private var isResummonDeviceUnavailable: Bool {
let plane = response?.currentPlane
return response?.planeStatus?.connected == false || plane?.onlineStatus == 2 || plane?.workStatus == 0
|| ["离线", "返航中", "正在返航"].contains(usable(plane?.workStatusLabel) ?? "")
return response?.planeStatus?.connected == false || isResummonDeviceOffline || plane?.workStatus == 2
|| ["返航中", "正在返航"].contains(usable(plane?.workStatusLabel) ?? "")
|| response?.ui?.phase == "returning"
}
/// 正式入口未注入操作服务时说明当前限制;模拟页保留实际设备不可用原因。
private var retryUnavailableNote: String {
let plane = response?.currentPlane
if plane?.onlineStatus == 2 || plane?.workStatus == 0 || usable(plane?.workStatusLabel) == "离线" {
if isResummonDeviceOffline {
return "无人机离线,暂不可召唤"
}
if plane?.workStatus == 2 { return "无人机忙碌,暂不可召唤" }
if let status = usable(plane?.workStatusLabel), ["返航中", "正在返航"].contains(status) {
return "无人机返航中,暂不可召唤"
}