feat(drone-dock): 搭建机巢工作台与拍摄订单UI
This commit is contained in:
@@ -0,0 +1,339 @@
|
||||
import Foundation
|
||||
|
||||
/// 机巢页面的数据所属范围;景区切换不改变原景区的任务。
|
||||
struct DroneDockContext: Hashable, Sendable {
|
||||
/// 当前景区的稳定标识。
|
||||
let scenicID: String
|
||||
/// 顶部展示的景区名称。
|
||||
let scenicName: String
|
||||
/// 当前工作人员的稳定标识。
|
||||
let userID: String
|
||||
/// 顶部展示的工作人员姓名。
|
||||
let photographerName: String
|
||||
|
||||
/// UI 首轮验收使用的本地上下文,不关联实际订单。
|
||||
static let demo = DroneDockContext(
|
||||
scenicID: "demo-songshan", scenicName: "嵩山少林景区",
|
||||
userID: "demo-photographer", photographerName: "吴家俊"
|
||||
)
|
||||
}
|
||||
|
||||
/// 由视图映射到具体颜色的语义色,不依赖 UIKit。
|
||||
enum DroneDockStatusTone: Hashable, Sendable {
|
||||
case blue, green, orange, red, gray
|
||||
}
|
||||
|
||||
/// 设备独立于订单履约的可用状态;低电量由设备状态指定,不推导电量阈值。
|
||||
enum DroneDockDeviceState: Hashable, Sendable {
|
||||
case ready, occupied, disconnected, lowBattery, noSignal, unknown
|
||||
|
||||
/// 无人机卡片的状态文字。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .ready: "空闲"
|
||||
case .occupied: "占用中"
|
||||
case .disconnected: "未连接"
|
||||
case .lowBattery: "低电量"
|
||||
case .noSignal: "无信号"
|
||||
case .unknown: "状态待确认"
|
||||
}
|
||||
}
|
||||
|
||||
/// 状态标签语义色。
|
||||
var tone: DroneDockStatusTone {
|
||||
switch self {
|
||||
case .ready: .green
|
||||
case .occupied, .lowBattery: .orange
|
||||
case .disconnected, .unknown: .gray
|
||||
case .noSignal: .red
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 无人机六项遥测;未知读数使用 nil,避免误显示成零。
|
||||
struct DroneDockTelemetry: Hashable, Sendable {
|
||||
/// 电池电量百分比。
|
||||
let batteryPercent: Int?
|
||||
/// 摄氏温度。
|
||||
let temperatureCelsius: Double?
|
||||
/// 每秒米数的风速。
|
||||
let windSpeed: Double?
|
||||
/// 设备提供的雨量描述。
|
||||
let rainDescription: String?
|
||||
/// 设备提供的信号描述。
|
||||
let signalDescription: String?
|
||||
/// 搜星数量。
|
||||
let satelliteCount: Int?
|
||||
|
||||
/// 六项均无有效遥测的占位数据。
|
||||
static let unknown = DroneDockTelemetry(
|
||||
batteryPercent: nil, temperatureCelsius: nil, windSpeed: nil,
|
||||
rainDescription: nil, signalDescription: nil, satelliteCount: nil
|
||||
)
|
||||
|
||||
/// 电池读数,未知时显示破折号。
|
||||
var batteryText: String { batteryPercent.map { "\($0)%" } ?? "—" }
|
||||
/// 环形电量的有效进度,未知时不绘制进度。
|
||||
var batteryProgress: Double? { batteryPercent.map { Double(min(100, max(0, $0))) / 100 } }
|
||||
/// 温度读数及单位。
|
||||
var temperatureText: String { temperatureCelsius.map { String(format: "%.1f°C", $0) } ?? "—" }
|
||||
/// 风速读数及单位。
|
||||
var windText: String {
|
||||
windSpeed.map { $0 == $0.rounded() ? String(format: "%.0fm/s", $0) : String(format: "%.1fm/s", $0) } ?? "—"
|
||||
}
|
||||
/// 雨量描述,空字符串同样视为未知。
|
||||
var rainText: String { Self.knownText(rainDescription) }
|
||||
/// 信号描述,空字符串同样视为未知。
|
||||
var signalText: String { Self.knownText(signalDescription) }
|
||||
/// 搜星读数及单位。
|
||||
var satelliteText: String { satelliteCount.map { "\($0)颗" } ?? "—" }
|
||||
|
||||
private static func knownText(_ value: String?) -> String {
|
||||
guard let value, !value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return "—" }
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
/// 横向设备列表中的单架无人机。
|
||||
struct DroneDockDevice: Hashable, Sendable {
|
||||
/// 无人机稳定标识。
|
||||
let id: String
|
||||
/// 无人机展示名称。
|
||||
let name: String
|
||||
/// 设备可用状态。
|
||||
let state: DroneDockDeviceState
|
||||
/// 六项遥测。
|
||||
let telemetry: DroneDockTelemetry
|
||||
}
|
||||
|
||||
/// 经确认的七种当前任务标签;不与成功扣次或上传结果合并。
|
||||
enum DroneShootingTaskPhase: String, CaseIterable, Hashable, Sendable {
|
||||
case navigating, arrived, shooting, shootingPaused, returning, returnPaused, unconfirmed
|
||||
|
||||
/// 首页及订单卡右上角展示的任务标签。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .navigating: "前往拍摄点中"
|
||||
case .arrived: "已到达,待拍摄"
|
||||
case .shooting: "拍摄中"
|
||||
case .shootingPaused: "拍摄已暂停"
|
||||
case .returning: "返航中"
|
||||
case .returnPaused: "返航已暂停"
|
||||
case .unconfirmed: "任务状态待确认"
|
||||
}
|
||||
}
|
||||
|
||||
/// 任务标签的语义色。
|
||||
var tone: DroneDockStatusTone {
|
||||
switch self {
|
||||
case .shootingPaused, .returnPaused, .unconfirmed: .orange
|
||||
case .returning: .red
|
||||
case .navigating, .arrived, .shooting: .blue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 一次拍摄的结果独立于飞行阶段。
|
||||
enum DroneShootingResult: Hashable, Sendable {
|
||||
case notStarted, inProgress, succeeded, failed, unknown
|
||||
}
|
||||
|
||||
/// 尚未结束的飞行任务引用,不暴露点位信息到首页卡片。
|
||||
struct DroneShootingTask: Hashable, Sendable {
|
||||
/// 任务稳定标识。
|
||||
let id: String
|
||||
/// 飞行或暂停阶段。
|
||||
let phase: DroneShootingTaskPhase
|
||||
/// 该次拍摄的独立结果。
|
||||
let shootingResult: DroneShootingResult
|
||||
}
|
||||
|
||||
/// 订单按已成功拍摄次数和当前任务归属的履约分类。
|
||||
enum DroneShootingFulfillmentState: Hashable, Sendable {
|
||||
case pending, inProgress, completed
|
||||
|
||||
/// 列表状态标签。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .pending: "待拍摄"
|
||||
case .inProgress: "进行中"
|
||||
case .completed: "拍摄完成"
|
||||
}
|
||||
}
|
||||
|
||||
/// 履约状态的语义色。
|
||||
var tone: DroneDockStatusTone {
|
||||
switch self {
|
||||
case .pending: .gray
|
||||
case .inProgress: .blue
|
||||
case .completed: .green
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 原素材上传摘要,与拍摄次数和后续成片交付分开。
|
||||
enum DroneShootingMaterialState: Hashable, Sendable {
|
||||
case none, uploading, partiallyReady, ready, failed
|
||||
|
||||
/// 订单卡素材栏文案。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .none: "暂无拍摄素材"
|
||||
case .uploading: "上传中"
|
||||
case .partiallyReady: "部分上传完成"
|
||||
case .ready: "上传完成"
|
||||
case .failed: "上传失败"
|
||||
}
|
||||
}
|
||||
|
||||
/// 素材栏语义色。
|
||||
var tone: DroneDockStatusTone {
|
||||
switch self {
|
||||
case .none: .gray
|
||||
case .uploading, .partiallyReady: .blue
|
||||
case .ready: .green
|
||||
case .failed: .red
|
||||
}
|
||||
}
|
||||
|
||||
/// 素材状态对应的 SF Symbol 名称。
|
||||
var systemImageName: String {
|
||||
switch self {
|
||||
case .none: "photo.on.rectangle"
|
||||
case .uploading, .partiallyReady: "icloud.and.arrow.up"
|
||||
case .ready: "checkmark.icloud"
|
||||
case .failed: "exclamationmark.icloud"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 新版卡片中游客确认摘要的静态展示状态;本期不实现交付流程。
|
||||
enum DroneVisitorConfirmationState: Hashable, Sendable {
|
||||
case none, awaitingConfirmation, confirmed
|
||||
|
||||
/// 卡片确认区文案。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .none: "尚未交付成片"
|
||||
case .awaitingConfirmation: "待游客确认"
|
||||
case .confirmed: "游客已确认"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 订单主要入口的语义,避免 View 自行根据数字推断行为。
|
||||
enum DroneShootingPrimaryAction: Hashable, Sendable {
|
||||
case startShooting, continueShooting, viewCurrentTask, prepareAgain, none
|
||||
|
||||
/// 主要按钮标题。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .startShooting: "开始拍摄"
|
||||
case .continueShooting: "继续拍摄"
|
||||
case .viewCurrentTask: "查看当前任务"
|
||||
case .prepareAgain: "重新准备拍摄"
|
||||
case .none: "拍摄已完成"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 两种订单卡共享的数据;计数、当前任务、原素材和成片交付各自独立。
|
||||
struct DroneShootingOrder: Hashable, Sendable {
|
||||
/// 订单稳定标识。
|
||||
let id: String
|
||||
/// 所属景区标识。
|
||||
let scenicID: String
|
||||
/// 被分配的工作人员标识。
|
||||
let assignedUserID: String
|
||||
/// 游客脱敏展示名称。
|
||||
let customerName: String
|
||||
/// 可见订单号。
|
||||
let orderNumber: String
|
||||
/// 下单时间展示值。
|
||||
let createdAtText: String
|
||||
/// 套餐展示名称,不包含次数。
|
||||
let packageName: String
|
||||
/// 本单包含的拍摄次数。
|
||||
let totalShootingCount: Int
|
||||
/// 已确认成功的拍摄次数。
|
||||
let successfulShootingCount: Int
|
||||
/// 尚未结束的任务,次数为零时仍可存在。
|
||||
let activeTask: DroneShootingTask?
|
||||
/// 设备已确认失败并可重新准备时的入口提示。
|
||||
let needsRepreparation: Bool
|
||||
/// 原素材上传状态。
|
||||
let materialState: DroneShootingMaterialState
|
||||
/// 新版视觉中的已交付数量,仅为演示摘要。
|
||||
let deliveredVideoCount: Int
|
||||
/// 新版视觉中的游客确认摘要。
|
||||
let visitorConfirmationState: DroneVisitorConfirmationState
|
||||
|
||||
/// 剩余次数只由成功数计算;查看任务、上传和交付不扣次。
|
||||
var remainingShootingCount: Int { max(0, totalShootingCount - successfulShootingCount) }
|
||||
/// 拍摄进度,防止除零或异常值溢出进度条。
|
||||
var progress: Double {
|
||||
guard totalShootingCount > 0 else { return 0 }
|
||||
return min(1, max(0, Double(successfulShootingCount) / Double(totalShootingCount)))
|
||||
}
|
||||
/// 零次立即已完成;有成功记录或当前任务时仍归进行中。
|
||||
var fulfillmentState: DroneShootingFulfillmentState {
|
||||
if remainingShootingCount == 0 { return .completed }
|
||||
if successfulShootingCount > 0 || activeTask != nil { return .inProgress }
|
||||
return .pending
|
||||
}
|
||||
/// 有当前任务时优先回到该任务,包括零次仍在返航的情况。
|
||||
var primaryAction: DroneShootingPrimaryAction {
|
||||
if activeTask != nil { return .viewCurrentTask }
|
||||
guard remainingShootingCount > 0 else { return .none }
|
||||
if needsRepreparation { return .prepareAgain }
|
||||
return successfulShootingCount == 0 ? .startShooting : .continueShooting
|
||||
}
|
||||
/// 主要按钮可点击性。
|
||||
var primaryActionEnabled: Bool { primaryAction != .none }
|
||||
/// 是否存在可进入的原素材记录;上传中和失败也保留查看入口。
|
||||
var hasMaterials: Bool { materialState != .none }
|
||||
/// 首页和列表右上角优先展示具体任务阶段。
|
||||
var statusTitle: String { activeTask?.phase.title ?? fulfillmentState.title }
|
||||
/// 状态文字对应语义色。
|
||||
var statusTone: DroneDockStatusTone { activeTask?.phase.tone ?? fulfillmentState.tone }
|
||||
/// 套餐与购买次数的组合文案。
|
||||
var packageSummary: String { "\(packageName) · 含\(totalShootingCount)次拍摄" }
|
||||
}
|
||||
|
||||
/// 我的拍摄订单四个筛选入口。
|
||||
enum DroneShootingOrderFilter: String, CaseIterable, Hashable, Sendable {
|
||||
case all, pending, inProgress, completed
|
||||
|
||||
/// Tab 标题。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .all: "全部"
|
||||
case .pending: "待拍摄"
|
||||
case .inProgress: "进行中"
|
||||
case .completed: "已完成"
|
||||
}
|
||||
}
|
||||
|
||||
/// 订单列表区标题。
|
||||
var listTitle: String { self == .all ? "全部订单" : "\(title)订单" }
|
||||
|
||||
/// 筛选只根据履约状态,上传或交付不会改变订单归属。
|
||||
func includes(_ order: DroneShootingOrder) -> Bool {
|
||||
switch self {
|
||||
case .all: true
|
||||
case .pending: order.fulfillmentState == .pending
|
||||
case .inProgress: order.fulfillmentState == .inProgress
|
||||
case .completed: order.fulfillmentState == .completed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 工作台的本地演示统计,与列表中的历史订单数量分别展示。
|
||||
struct DroneDockDailyStatistics: Hashable, Sendable {
|
||||
/// 今日成交订单数。
|
||||
let orderCount: Int
|
||||
/// 已格式化的成交金额,不使用浮点计算金额。
|
||||
let revenueText: String
|
||||
/// 今日成功拍摄次数。
|
||||
let successfulShootingCount: Int
|
||||
}
|
||||
@@ -0,0 +1,278 @@
|
||||
import Foundation
|
||||
|
||||
/// 两个机巢页面共享的本地数据源,不请求接口、不发送设备指令,也不自动推进任务。
|
||||
final class DroneDockDemoStore {
|
||||
/// 当前登录用户与景区范围。
|
||||
private(set) var context: DroneDockContext
|
||||
|
||||
private var ordersByContext: [DroneDockContext: [DroneShootingOrder]] = [:]
|
||||
private var devicesByContext: [DroneDockContext: [DroneDockDevice]] = [:]
|
||||
|
||||
/// 注入初始上下文及可选数据,便于页面演示与独立规则测试。
|
||||
init(
|
||||
context: DroneDockContext = .demo,
|
||||
orders: [DroneShootingOrder]? = nil,
|
||||
devices: [DroneDockDevice]? = nil
|
||||
) {
|
||||
self.context = context
|
||||
ordersByContext[context] = orders ?? DroneDockDemoData.orders(context: context)
|
||||
devicesByContext[context] = devices ?? DroneDockDemoData.devices()
|
||||
}
|
||||
|
||||
/// 只向页面提供当前用户在当前景区的订单。
|
||||
var orders: [DroneShootingOrder] {
|
||||
(ordersByContext[context] ?? []).filter {
|
||||
$0.scenicID == context.scenicID && $0.assignedUserID == context.userID
|
||||
}
|
||||
}
|
||||
|
||||
/// 当前景区的无人机,不将横向浏览等同于执行资源选择。
|
||||
var devices: [DroneDockDevice] { devicesByContext[context] ?? [] }
|
||||
|
||||
/// 当前演示上下文的今日统计;空场景不保留误导的数值。
|
||||
var statistics: DroneDockDailyStatistics {
|
||||
orders.isEmpty
|
||||
? DroneDockDailyStatistics(orderCount: 0, revenueText: "¥0", successfulShootingCount: 0)
|
||||
: DroneDockDailyStatistics(orderCount: 12, revenueText: "¥1,896", successfulShootingCount: 9)
|
||||
}
|
||||
|
||||
/// 更换范围并保留旧范围中的本地任务,切回后仍可查看。
|
||||
func switchContext(to context: DroneDockContext) {
|
||||
if ordersByContext[context] == nil {
|
||||
ordersByContext[context] = DroneDockDemoData.orders(context: context)
|
||||
devicesByContext[context] = DroneDockDemoData.devices()
|
||||
}
|
||||
self.context = context
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// 只在 Debug 提供场景切换;不会触发扣次、真实设备或网络操作。
|
||||
func applyScenario(_ scenario: DroneDockDemoScenario) {
|
||||
var orders = DroneDockDemoData.orders(context: context)
|
||||
var devices = DroneDockDemoData.devices()
|
||||
switch scenario {
|
||||
case .standard: break
|
||||
case .singleDevice: devices = Array(devices.prefix(1))
|
||||
case .unknownTelemetry:
|
||||
devices = [DroneDockDevice(id: "demo-unknown", name: "01号无人机", state: .unknown, telemetry: .unknown)]
|
||||
case .noDevices: devices = []
|
||||
case .emptyOrders: orders = []
|
||||
case .completedReturning:
|
||||
let index = 4
|
||||
orders[index] = DroneDockDemoData.withTask(
|
||||
orders[index], phase: .returning, shootingResult: .succeeded
|
||||
)
|
||||
default:
|
||||
if let phase = scenario.taskPhase {
|
||||
orders[2] = DroneDockDemoData.withTask(
|
||||
orders[2], phase: phase,
|
||||
shootingResult: phase == .returning || phase == .returnPaused ? .succeeded : .inProgress
|
||||
)
|
||||
}
|
||||
}
|
||||
ordersByContext[context] = orders
|
||||
devicesByContext[context] = devices
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// 工作台的展示规则:仅余次订单、当前任务置顶,多设备只作展示。
|
||||
final class DroneDockWorkbenchViewModel {
|
||||
/// 页面共享数据源,进入订单列表时传递同一实例。
|
||||
let store: DroneDockDemoStore
|
||||
/// 当前用户与景区。
|
||||
var context: DroneDockContext { store.context }
|
||||
/// 首页可见订单,不包含零次但尚在返航的订单。
|
||||
private(set) var orders: [DroneShootingOrder] = []
|
||||
/// 当前景区的设备列表。
|
||||
private(set) var devices: [DroneDockDevice] = []
|
||||
/// 今日统计摘要。
|
||||
private(set) var statistics = DroneDockDailyStatistics(orderCount: 0, revenueText: "¥0", successfulShootingCount: 0)
|
||||
/// 当前用户全部订单数量,含已完成。
|
||||
var allOrderCount: Int { store.orders.count }
|
||||
/// 首页实际可拍摄订单数量。
|
||||
var orderCount: Int { orders.count }
|
||||
|
||||
/// 读取本地初始数据。
|
||||
init(store: DroneDockDemoStore = DroneDockDemoStore()) {
|
||||
self.store = store
|
||||
refresh()
|
||||
}
|
||||
|
||||
/// 在出现、返回或切换展示场景后主动刷新,不创建或取消任务。
|
||||
func refresh() {
|
||||
orders = DroneShootingOrderSorter.activeFirst(store.orders.filter { $0.remainingShootingCount > 0 })
|
||||
devices = store.devices
|
||||
statistics = store.statistics
|
||||
}
|
||||
|
||||
/// 返回当前范围中的订单,避免使用过期卡片跨景区跳转。
|
||||
func order(id: String) -> DroneShootingOrder? {
|
||||
orders.first { $0.id == id }
|
||||
}
|
||||
|
||||
/// 切换景区并刷新展示;原景区数据保持不变。
|
||||
func switchContext(to context: DroneDockContext) {
|
||||
store.switchContext(to: context)
|
||||
refresh()
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// 应用仅本地有效的验收场景。
|
||||
func applyScenario(_ scenario: DroneDockDemoScenario) {
|
||||
store.applyScenario(scenario)
|
||||
refresh()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// 我的拍摄订单展示逻辑;筛选按履约状态,不受上传、交付或返航干扰。
|
||||
final class DroneShootingOrdersViewModel {
|
||||
/// 与工作台共享的数据源。
|
||||
let store: DroneDockDemoStore
|
||||
/// 当前范围。
|
||||
var context: DroneDockContext { store.context }
|
||||
/// 当前选中的 Tab;支付成功入口可显式传入 pending。
|
||||
private(set) var selectedFilter: DroneShootingOrderFilter
|
||||
/// 当前 Tab 下的订单。
|
||||
private(set) var orders: [DroneShootingOrder] = []
|
||||
/// 当前列表的标题。
|
||||
var listTitle: String { selectedFilter.listTitle }
|
||||
|
||||
/// 初始化明确的入口 Tab,普通查看全部默认 all。
|
||||
init(store: DroneDockDemoStore = DroneDockDemoStore(), initialFilter: DroneShootingOrderFilter = .all) {
|
||||
self.store = store
|
||||
selectedFilter = initialFilter
|
||||
refresh()
|
||||
}
|
||||
|
||||
/// 进入页面时主动读取数据,不改变任务和计数。
|
||||
func refresh() {
|
||||
orders = DroneShootingOrderSorter.activeFirst(store.orders.filter(selectedFilter.includes))
|
||||
}
|
||||
|
||||
/// 用户切换 Tab。
|
||||
func selectFilter(_ filter: DroneShootingOrderFilter) {
|
||||
selectedFilter = filter
|
||||
refresh()
|
||||
}
|
||||
|
||||
/// 返回指定 Tab 下当前用户的订单数量。
|
||||
func count(for filter: DroneShootingOrderFilter) -> Int {
|
||||
store.orders.filter(filter.includes).count
|
||||
}
|
||||
|
||||
/// 获取当前显示订单,过滤失效卡片操作。
|
||||
func order(id: String) -> DroneShootingOrder? {
|
||||
orders.first { $0.id == id }
|
||||
}
|
||||
}
|
||||
|
||||
/// 稳定地将当前任务置顶,其余顺序延续数据源。
|
||||
private enum DroneShootingOrderSorter {
|
||||
static func activeFirst(_ orders: [DroneShootingOrder]) -> [DroneShootingOrder] {
|
||||
orders.filter { $0.activeTask != nil } + orders.filter { $0.activeTask == nil }
|
||||
}
|
||||
}
|
||||
|
||||
/// 本地 UI 展示夹具,不使用远程图片或任何真实接口。
|
||||
private enum DroneDockDemoData {
|
||||
static func devices() -> [DroneDockDevice] {
|
||||
[
|
||||
device(1, .ready, 95, 19.3, 0, 36),
|
||||
device(2, .occupied, 72, 20.1, 1.2, 32),
|
||||
DroneDockDevice(id: "demo-device-3", name: "03号无人机", state: .disconnected, telemetry: .unknown),
|
||||
device(4, .lowBattery, 18, 19.8, 0.6, 34),
|
||||
device(5, .ready, 88, 20.3, 0.8, 35),
|
||||
DroneDockDevice(
|
||||
id: "demo-device-6", name: "06号无人机", state: .noSignal,
|
||||
telemetry: DroneDockTelemetry(
|
||||
batteryPercent: nil, temperatureCelsius: nil, windSpeed: nil,
|
||||
rainDescription: nil, signalDescription: "无信号", satelliteCount: nil
|
||||
)
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
private static func device(
|
||||
_ number: Int, _ state: DroneDockDeviceState, _ battery: Int,
|
||||
_ temperature: Double, _ wind: Double, _ satellites: Int
|
||||
) -> DroneDockDevice {
|
||||
DroneDockDevice(
|
||||
id: "demo-device-\(number)", name: String(format: "%02d号无人机", number), state: state,
|
||||
telemetry: DroneDockTelemetry(
|
||||
batteryPercent: battery, temperatureCelsius: temperature, windSpeed: wind,
|
||||
rainDescription: "无雨", signalDescription: "良好", satelliteCount: satellites
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
static func orders(context: DroneDockContext) -> [DroneShootingOrder] {
|
||||
[
|
||||
order(context, 1, "158****8888", 5, 3, .uploading),
|
||||
order(context, 2, "136****2806", 1, 0, .none),
|
||||
order(context, 3, "139****5192", 5, 2, .failed),
|
||||
order(context, 4, "137****6628", 5, 5, .ready),
|
||||
order(context, 5, "180****4075", 1, 1, .uploading),
|
||||
order(context, 6, "185****5736", 5, 5, .ready, delivered: 2, confirmation: .awaitingConfirmation),
|
||||
order(context, 7, "188****3160", 5, 5, .ready, delivered: 3, confirmation: .confirmed),
|
||||
order(context, 8, "135****2026", 3, 3, .partiallyReady)
|
||||
]
|
||||
}
|
||||
|
||||
private static func order(
|
||||
_ context: DroneDockContext, _ number: Int, _ phone: String,
|
||||
_ total: Int, _ successful: Int, _ material: DroneShootingMaterialState,
|
||||
delivered: Int = 0, confirmation: DroneVisitorConfirmationState = .none
|
||||
) -> DroneShootingOrder {
|
||||
DroneShootingOrder(
|
||||
id: "\(context.scenicID)-\(context.userID)-order-\(number)",
|
||||
scenicID: context.scenicID, assignedUserID: context.userID,
|
||||
customerName: "游客\(phone)", orderNumber: String(format: "HT2026102000%02d", number),
|
||||
createdAtText: "10-20 \(14 - number):18", packageName: total == 1 ? "单次航拍" : "航拍套餐",
|
||||
totalShootingCount: total, successfulShootingCount: successful, activeTask: nil,
|
||||
needsRepreparation: false, materialState: material, deliveredVideoCount: delivered,
|
||||
visitorConfirmationState: confirmation
|
||||
)
|
||||
}
|
||||
|
||||
static func withTask(
|
||||
_ order: DroneShootingOrder, phase: DroneShootingTaskPhase, shootingResult: DroneShootingResult
|
||||
) -> DroneShootingOrder {
|
||||
DroneShootingOrder(
|
||||
id: order.id, scenicID: order.scenicID, assignedUserID: order.assignedUserID,
|
||||
customerName: order.customerName, orderNumber: order.orderNumber, createdAtText: order.createdAtText,
|
||||
packageName: order.packageName, totalShootingCount: order.totalShootingCount,
|
||||
successfulShootingCount: order.successfulShootingCount,
|
||||
activeTask: DroneShootingTask(id: "\(order.id)-task", phase: phase, shootingResult: shootingResult),
|
||||
needsRepreparation: order.needsRepreparation, materialState: order.materialState,
|
||||
deliveredVideoCount: order.deliveredVideoCount, visitorConfirmationState: order.visitorConfirmationState
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// 仅供 Debug 页面验收的状态集合,不会编译进正式版入口。
|
||||
enum DroneDockDemoScenario: String, CaseIterable {
|
||||
case standard, singleDevice, unknownTelemetry, noDevices, emptyOrders
|
||||
case navigating, arrived, shooting, shootingPaused, returning, returnPaused, unconfirmed, completedReturning
|
||||
|
||||
/// 状态选择菜单文案。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .standard: "默认数据 · 多架无人机"
|
||||
case .singleDevice: "单架无人机"
|
||||
case .unknownTelemetry: "遥测未知"
|
||||
case .noDevices: "暂无无人机"
|
||||
case .emptyOrders: "暂无订单"
|
||||
case .completedReturning: "次数用完 · 仍在返航"
|
||||
default: taskPhase?.title ?? "默认数据"
|
||||
}
|
||||
}
|
||||
|
||||
/// 该演示场景对应的未结束任务阶段。
|
||||
var taskPhase: DroneShootingTaskPhase? {
|
||||
DroneShootingTaskPhase(rawValue: rawValue)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user