feat(drone-dock): 新增拍摄准备与当前任务页面
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// 两个机巢页面共享的本地数据源,不请求接口、不发送设备指令,也不自动推进任务。
|
||||
/// 机巢工作台、订单、准备和任务页面共享的本地数据源;不请求接口或自动推进任务。
|
||||
final class DroneDockDemoStore {
|
||||
/// 当前登录用户与景区范围。
|
||||
private(set) var context: DroneDockContext
|
||||
@@ -8,6 +8,15 @@ final class DroneDockDemoStore {
|
||||
private var ordersByContext: [DroneDockContext: [DroneShootingOrder]] = [:]
|
||||
private var devicesByContext: [DroneDockContext: [DroneDockDevice]] = [:]
|
||||
|
||||
/// 按上下文与订单保存的点位、航线和人工选择。
|
||||
var shootingPreparations: [DroneShootingSessionKey: DroneShootingPreparationState] = [:]
|
||||
/// 当前或最近一次本地任务;飞行结束后仍保留结果页快照。
|
||||
var shootingSessions: [DroneShootingSessionKey: DroneShootingSession] = [:]
|
||||
#if DEBUG
|
||||
/// 预览切换前的订单,恢复正常场景时不累计演示扣次。
|
||||
var shootingScenarioBaselines: [DroneShootingSessionKey: DroneShootingOrder] = [:]
|
||||
#endif
|
||||
|
||||
/// 注入初始上下文及可选数据,便于页面演示与独立规则测试。
|
||||
init(
|
||||
context: DroneDockContext = .demo,
|
||||
@@ -29,6 +38,24 @@ final class DroneDockDemoStore {
|
||||
/// 当前景区的无人机,不将横向浏览等同于执行资源选择。
|
||||
var devices: [DroneDockDevice] { devicesByContext[context] ?? [] }
|
||||
|
||||
/// 读取当前用户、当前景区内的指定订单。
|
||||
func shootingOrder(id: String) -> DroneShootingOrder? { orders.first { $0.id == id } }
|
||||
|
||||
/// 写回一个已校验归属的本地订单,使工作台与列表主动刷新时得到相同结果。
|
||||
func replaceShootingOrder(_ order: DroneShootingOrder) {
|
||||
guard order.scenicID == context.scenicID, order.assignedUserID == context.userID,
|
||||
let index = ordersByContext[context]?.firstIndex(where: { $0.id == order.id }) else { return }
|
||||
ordersByContext[context]?[index] = order
|
||||
}
|
||||
|
||||
/// 更新本地执行资源状态;仅使用明确状态,不从电量或卡片浏览位置推导许可。
|
||||
func setShootingDeviceState(_ state: DroneDockDeviceState, telemetry: DroneDockTelemetry? = nil) {
|
||||
guard let device = devices.first else { return }
|
||||
devicesByContext[context]?[0] = DroneDockDevice(
|
||||
id: device.id, name: device.name, state: state, telemetry: telemetry ?? device.telemetry
|
||||
)
|
||||
}
|
||||
|
||||
/// 当前演示上下文的今日统计;空场景不保留误导的数值。
|
||||
var statistics: DroneDockDailyStatistics {
|
||||
orders.isEmpty
|
||||
@@ -48,6 +75,9 @@ final class DroneDockDemoStore {
|
||||
#if DEBUG
|
||||
/// 只在 Debug 提供场景切换;不会触发扣次、真实设备或网络操作。
|
||||
func applyScenario(_ scenario: DroneDockDemoScenario) {
|
||||
shootingPreparations = shootingPreparations.filter { $0.key.context != context }
|
||||
shootingSessions = shootingSessions.filter { $0.key.context != context }
|
||||
shootingScenarioBaselines = shootingScenarioBaselines.filter { $0.key.context != context }
|
||||
var orders = DroneDockDemoData.orders(context: context)
|
||||
var devices = DroneDockDemoData.devices()
|
||||
switch scenario {
|
||||
|
||||
Reference in New Issue
Block a user