feat: 完善机巢模拟调试与素材交付交互
增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
This commit is contained in:
@@ -43,6 +43,7 @@ final class DroneDockPreparationViewModel {
|
||||
private let planeStatusService: any DroneDockPlaneStatusServing
|
||||
private let taskCreationService: any DroneDockTaskCreating
|
||||
private let shootService: any DroneDockShootServing
|
||||
private let allowsTaskSubmission: Bool
|
||||
private let currentContext: @MainActor @Sendable () -> DroneDockHomeContext
|
||||
private var generation = 0
|
||||
private var planeStatusGeneration = 0
|
||||
@@ -62,6 +63,7 @@ final class DroneDockPreparationViewModel {
|
||||
planeStatusService: any DroneDockPlaneStatusServing,
|
||||
taskCreationService: any DroneDockTaskCreating,
|
||||
shootService: any DroneDockShootServing,
|
||||
allowsTaskSubmission: Bool = true,
|
||||
currentContext: @escaping @MainActor @Sendable () -> DroneDockHomeContext) {
|
||||
self.context = context
|
||||
self.order = order
|
||||
@@ -69,12 +71,13 @@ final class DroneDockPreparationViewModel {
|
||||
self.planeStatusService = planeStatusService
|
||||
self.taskCreationService = taskCreationService
|
||||
self.shootService = shootService
|
||||
self.allowsTaskSubmission = allowsTaskSubmission
|
||||
self.currentContext = currentContext
|
||||
}
|
||||
|
||||
/// 当前阶段只创建待飞任务,不以设备电量或位置作为创建任务条件。
|
||||
var canCreateTask: Bool {
|
||||
guard context.canLoad, !creationContextInvalidated, !isLoading, !isCreatingTask,
|
||||
guard allowsTaskSubmission, context.canLoad, !creationContextInvalidated, !isLoading, !isCreatingTask,
|
||||
!hasCreatedTask, !taskCreationOutcomeUnknown, errorMessage == nil,
|
||||
let info = projectInfo, info.order.canCreateTask == true,
|
||||
let total = info.order.shotTotal, total > 0,
|
||||
@@ -86,6 +89,9 @@ final class DroneDockPreparationViewModel {
|
||||
return info.order.orderNumber == number && info.order.projectID == projectID
|
||||
}
|
||||
|
||||
/// 当前入口是否被禁飞限制禁止提交,用于提供独立模拟入口而不放开真实写入。
|
||||
var isTaskSubmissionBlocked: Bool { !allowsTaskSubmission }
|
||||
|
||||
/// 提交中和已有回执/不确定结果时冻结点位航线,避免显示与任务归属不一致。
|
||||
var isTaskSelectionLocked: Bool {
|
||||
isCreatingTask || isSummoning || isPerformingPrimaryAction || hasCreatedTask || taskCreationOutcomeUnknown
|
||||
@@ -107,7 +113,7 @@ final class DroneDockPreparationViewModel {
|
||||
|
||||
/// 首次允许创建再召唤;明确业务拒绝后可对同任务重试,成功和未知结果锁定。
|
||||
var isPrimaryActionEnabled: Bool {
|
||||
guard context.canLoad, !creationContextInvalidated, !isLoading, !isCreatingTask,
|
||||
guard allowsTaskSubmission, context.canLoad, !creationContextInvalidated, !isLoading, !isCreatingTask,
|
||||
!isSummoning, !isPerformingPrimaryAction, !taskCreationOutcomeUnknown,
|
||||
!hasSubmittedSummon, !summonOutcomeUnknown else { return false }
|
||||
if let createdTask { return createdTask.taskID > 0 }
|
||||
@@ -117,7 +123,8 @@ final class DroneDockPreparationViewModel {
|
||||
/// 主按钮串接创建与召唤;已有任务跳过创建,成功后的导航由页面处理。
|
||||
@MainActor
|
||||
func prepareAndSummon(onStateChange: @escaping @MainActor () -> Void = {}) async {
|
||||
guard isPrimaryActionEnabled else { return }
|
||||
// 禁飞调试在整条链开始前阻断,避免先残留真实待飞任务再拦截召唤。
|
||||
guard allowsTaskSubmission, isPrimaryActionEnabled else { return }
|
||||
primaryActionGeneration &+= 1
|
||||
let actionGeneration = primaryActionGeneration
|
||||
isPerformingPrimaryAction = true
|
||||
@@ -136,7 +143,7 @@ final class DroneDockPreparationViewModel {
|
||||
/// 对明确创建成功的任务发送一次召唤;只有明确业务拒绝允许之后再次提交。
|
||||
@MainActor
|
||||
private func summonCreatedTask(onStateChange: @escaping @MainActor () -> Void) async {
|
||||
guard !isCreatingTask, !isSummoning, !taskCreationOutcomeUnknown,
|
||||
guard allowsTaskSubmission, !isCreatingTask, !isSummoning, !taskCreationOutcomeUnknown,
|
||||
!hasSubmittedSummon, !summonOutcomeUnknown,
|
||||
let taskID = createdTask?.taskID, taskID > 0 else { return }
|
||||
summonGeneration &+= 1
|
||||
@@ -162,8 +169,13 @@ final class DroneDockPreparationViewModel {
|
||||
hasSubmittedSummon = true
|
||||
summonOutcomeUnknown = false
|
||||
} catch {
|
||||
if error is DeviceCommandDebugBlockedError, summonGeneration == requestGeneration {
|
||||
didSendSummon = false
|
||||
}
|
||||
guard acceptsSummon(requestGeneration, taskID: taskID) else { return }
|
||||
if case APIError.serverCode = error {
|
||||
if error is DeviceCommandDebugBlockedError {
|
||||
shootErrorMessage = DeviceCommandDebugPolicy.blockedMessage
|
||||
} else if case APIError.serverCode = error {
|
||||
shootErrorMessage = error.localizedDescription
|
||||
} else {
|
||||
markSummonUnknown(reason: error.localizedDescription)
|
||||
@@ -189,7 +201,7 @@ final class DroneDockPreparationViewModel {
|
||||
/// 点击后先校验最新购买配置,再发送一次创建请求;成功留在准备页供核对。
|
||||
@MainActor
|
||||
func createTask(onStateChange: @escaping @MainActor () -> Void = {}) async {
|
||||
guard canCreateTask, let spotID = selectedSpotID, let routeID = selectedRouteID,
|
||||
guard allowsTaskSubmission, canCreateTask, let spotID = selectedSpotID, let routeID = selectedRouteID,
|
||||
let number = order.orderNumber, let projectID = order.projectID else { return }
|
||||
taskCreationGeneration &+= 1
|
||||
let requestGeneration = taskCreationGeneration
|
||||
@@ -238,8 +250,13 @@ final class DroneDockPreparationViewModel {
|
||||
hasCreatedTask = true
|
||||
taskCreationOutcomeUnknown = false
|
||||
} catch {
|
||||
if error is DeviceCommandDebugBlockedError, taskCreationGeneration == requestGeneration {
|
||||
didSendTaskCreation = false
|
||||
}
|
||||
guard acceptsTaskCreation(requestGeneration) else { return }
|
||||
if didSendTaskCreation {
|
||||
if error is DeviceCommandDebugBlockedError {
|
||||
taskCreationErrorMessage = DeviceCommandDebugPolicy.blockedMessage
|
||||
} else if didSendTaskCreation {
|
||||
if case APIError.serverCode = error {
|
||||
taskCreationErrorMessage = error.localizedDescription
|
||||
} else {
|
||||
@@ -414,6 +431,7 @@ final class DroneDockPreparationViewModel {
|
||||
if isCreatingTask { return "正在创建任务…" }
|
||||
if isSummoning { return "正在召唤无人机…" }
|
||||
if hasSubmittedSummon { return "查看拍摄任务" }
|
||||
if !allowsTaskSubmission { return "仅限模拟调试" }
|
||||
if summonOutcomeUnknown { return "召唤结果待核对" }
|
||||
if hasCreatedTask { return shootErrorMessage == nil ? "确认并召唤" : "重试召唤" }
|
||||
if taskCreationOutcomeUnknown { return "结果待核对" }
|
||||
@@ -426,6 +444,7 @@ final class DroneDockPreparationViewModel {
|
||||
if isCreatingTask { return "正在创建待飞任务,请勿重复点击" }
|
||||
if isSummoning { return "任务已创建,正在提交召唤请求" }
|
||||
if creationContextInvalidated, let errorMessage { return errorMessage }
|
||||
if !allowsTaskSubmission && !hasSubmittedSummon { return DeviceCommandDebugPolicy.blockedMessage }
|
||||
if let createdTask {
|
||||
if hasSubmittedSummon { return "任务 \(createdTask.taskID) 的召唤请求已提交,请等待任务状态更新" }
|
||||
if let shootErrorMessage { return shootErrorMessage }
|
||||
|
||||
Reference in New Issue
Block a user