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

验证:最近 157 项相关模拟器隔离测试通过,Release 无签名编译通过;未调用真实飞控或图传。
2026-11-03 16:43:23 +08:00

91 lines
4.3 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// 保留 shoot 原始 data,并读取明确的同任务前往回执;不补造飞机或飞行阶段字段。
struct DroneDockShootResponse: Decodable, Equatable, Sendable {
/// 完整 data JSON;nil 表示统一客户端未提供 data,不补造 null 或空对象。
let dataJSON: String?
/// 保留已格式化回执;业务成功但 data 缺失或为 null 时使用 nil。
init(dataJSON: String?) { self.dataJSON = dataJSON }
/// 支持任意真实 JSON 值,保留未知结构、空数组、布尔值及原始字段类型。
init(from decoder: Decoder) throws {
let raw = try DroneDockHomeJSONValue(from: decoder)
let encoder = JSONEncoder()
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 使用。
struct DroneDockResummonReceiptIdentity: Decodable, Sendable {
/// 后端明确回显的订单飞行任务 ID,缺失时由后续 shooting 核对。
let orderFlightTaskID: Int?
/// 后端已提供的订单任务摘要身份。
let orderFlightTask: TaskIdentity?
/// 已锁定任务的飞机 ID;实际提供时核对是否仍为原任务飞机。
let planeID: Int?
/// 只读取已约定的订单任务身份字段。
private enum CodingKeys: String, CodingKey {
case orderFlightTaskID = "order_flight_task_id", orderFlightTask = "order_flight_task", planeID = "plane_id"
}
/// 嵌套订单任务的可选身份字段,不读取或推断设备执行阶段。
struct TaskIdentity: Decodable, Sendable {
/// 原订单飞行任务 ID。
let id: Int?
/// 任务所属订单。
let orderNumber: String?
/// 任务所属景区。
let scenicID: Int?
/// 订单任务摘要字段映射。
private enum CodingKeys: String, CodingKey {
case id, orderNumber = "order_number", scenicID = "scenic_id"
}
}
}
/// 将现有 JSON 值解码结果格式化,完整保留 shoot 尚未约定的成功数据结构。
private struct DroneDockShootJSONSnapshot: Encodable {
let value: DroneDockHomeJSONValue
/// 按真实 JSON 类型编码,不推导任务身份或追加外层业务字段。
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch value {
case .object(let object): try container.encode(object.mapValues { DroneDockShootJSONSnapshot(value: $0) })
case .array(let array): try container.encode(array.map { DroneDockShootJSONSnapshot(value: $0) })
case .string(let text): try container.encode(text)
case .number(let number): try container.encode(number)
case .bool(let flag): try container.encode(flag)
case .null: try container.encodeNil()
}
}
}