feat: 完善机巢模拟调试与素材交付交互
增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
This commit is contained in:
@@ -24,6 +24,25 @@ final class DroneDockMaterialsViewModel {
|
||||
private(set) var tasksErrorMessage: String?
|
||||
/// 点位标签始终来自整单购买快照,不从当前任务推导。
|
||||
var spots: [DroneDockMaterialSpot] { detail?.spots ?? [] }
|
||||
/// 当前范围内已选择的就绪原素材,不包含独立交付成片。
|
||||
private(set) var selectedMaterialIDs: Set<DroneDockMaterialSelectionID> = []
|
||||
/// 只有完整读取成功且具备有效文件地址的原素材允许选择。
|
||||
var selectableMaterialIDs: Set<DroneDockMaterialSelectionID> {
|
||||
guard detail != nil, !isLoading, !isLoadingTasks,
|
||||
detailErrorMessage == nil, tasksErrorMessage == nil else { return [] }
|
||||
return Set(tasks.flatMap { task in
|
||||
task.materials.filter { $0.previewURL != nil }.map {
|
||||
DroneDockMaterialSelectionID(taskID: task.id, fileID: $0.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
/// 当前选择数量仅用于界面展示,不表示已经下载或保存。
|
||||
var selectedCount: Int { selectedMaterialIDs.count }
|
||||
/// 空列表不展示全选;全部当前可用原素材被选中时才标记全选。
|
||||
var allDownloadableSelected: Bool {
|
||||
let selectable = selectableMaterialIDs
|
||||
return !selectable.isEmpty && selectedMaterialIDs == selectable
|
||||
}
|
||||
|
||||
private let service: any DroneDockMaterialsServing
|
||||
private let currentContext: @MainActor @Sendable () -> DroneDockHomeContext
|
||||
@@ -39,6 +58,38 @@ final class DroneDockMaterialsViewModel {
|
||||
self.currentContext = currentContext
|
||||
}
|
||||
|
||||
/// 勾选只修改本地状态;无效、未就绪或其他任务的素材不会进入选择集合。
|
||||
@MainActor
|
||||
func toggleSelection(taskID: Int, fileID: Int) {
|
||||
guard acceptsSelectionContext() else { return }
|
||||
let identifier = DroneDockMaterialSelectionID(taskID: taskID, fileID: fileID)
|
||||
guard selectableMaterialIDs.contains(identifier) else { return }
|
||||
if selectedMaterialIDs.contains(identifier) {
|
||||
selectedMaterialIDs.remove(identifier)
|
||||
} else {
|
||||
selectedMaterialIDs.insert(identifier)
|
||||
}
|
||||
}
|
||||
|
||||
/// 全选仅覆盖当前点位可用的原素材,不跨点位、订单或成片扩大范围。
|
||||
@MainActor
|
||||
func toggleSelectAll() {
|
||||
guard acceptsSelectionContext() else { return }
|
||||
let selectable = selectableMaterialIDs
|
||||
guard !selectable.isEmpty else { return }
|
||||
selectedMaterialIDs = selectedMaterialIDs == selectable ? [] : selectable
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func acceptsSelectionContext() -> Bool {
|
||||
guard context.hasSameIdentity(as: currentContext()) else {
|
||||
invalidate()
|
||||
detailErrorMessage = "账号或景区已变化,请返回工作台重新进入"
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/// 先刷新整单摘要,再读取任务;保留仍在购买快照中的点位筛选。
|
||||
@MainActor
|
||||
func refresh() async {
|
||||
@@ -156,6 +207,7 @@ final class DroneDockMaterialsViewModel {
|
||||
@MainActor
|
||||
private func clearTasks() {
|
||||
tasks = []
|
||||
selectedMaterialIDs = []
|
||||
total = nil
|
||||
tasksErrorMessage = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user