feat(drone-dock): 接入已购套餐快照并固定首页无人机占位
准备页改用 project-info 购买快照,校验订单与项目身份,并按可用性选择已购点位和航线。首页在加载、空数据及失败时保留等高无人机卡片。同步相关测试与接口联调记录、响应和截图。 验证:iPhone 18 Pro 模拟器上 81 项相关测试通过。
This commit is contained in:
@@ -2,12 +2,12 @@ import Foundation
|
||||
|
||||
/// 拍摄准备页只读数据源,不创建订单任务或发送飞行控制指令。
|
||||
protocol DroneDockPreparationServing: Sendable {
|
||||
/// 获取指定订单的点位、航线与召唤门禁;无有效定位时省略坐标。
|
||||
/// 读取该订单实际购买的套餐、点位和航线,不使用当前上架项目替代购买快照。
|
||||
@MainActor
|
||||
func workbench(scenicID: Int, orderNumber: String, coordinate: DroneDockPreparationCoordinate?) async throws -> DroneDockPreparationResponse
|
||||
func projectInfo(scenicID: Int, projectID: Int, orderNumber: String) async throws -> DroneDockProjectInfoResponse
|
||||
}
|
||||
|
||||
/// 朱工的拍摄准备接口,登录凭证由统一客户端注入。
|
||||
/// 张工购买快照的只读接口,登录凭证由统一客户端注入。
|
||||
@MainActor
|
||||
final class DroneDockPreparationAPI: DroneDockPreparationServing {
|
||||
private let client: APIClient
|
||||
@@ -15,18 +15,23 @@ final class DroneDockPreparationAPI: DroneDockPreparationServing {
|
||||
/// 注入统一客户端,正式页面和测试使用相同请求构造。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 只读取准备快照,未知位置不会补零或替换成景区坐标。
|
||||
func workbench(scenicID: Int, orderNumber: String, coordinate: DroneDockPreparationCoordinate?) async throws -> DroneDockPreparationResponse {
|
||||
guard scenicID > 0, !orderNumber.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
||||
throw APIError.networkFailed("缺少当前景区或订单信息,请返回重试")
|
||||
/// 订单号必传;响应必须属于请求的订单与项目,避免展示其他购买范围。
|
||||
func projectInfo(scenicID: Int, projectID: Int, orderNumber: String) async throws -> DroneDockProjectInfoResponse {
|
||||
let trimmedNumber = orderNumber.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard scenicID > 0, projectID > 0, !trimmedNumber.isEmpty,
|
||||
trimmedNumber == orderNumber, orderNumber.count <= 128 else {
|
||||
throw APIError.networkFailed("缺少有效景区、项目或订单信息,请返回工作台重新进入")
|
||||
}
|
||||
var query = [URLQueryItem(name: "scenic_id", value: String(scenicID)),
|
||||
URLQueryItem(name: "order_number", value: orderNumber)]
|
||||
if let coordinate {
|
||||
guard coordinate.isValid else { throw APIError.networkFailed("定位结果无效,请重新定位") }
|
||||
query.append(URLQueryItem(name: "lat", value: String(coordinate.latitude)))
|
||||
query.append(URLQueryItem(name: "lng", value: String(coordinate.longitude)))
|
||||
let response: DroneDockProjectInfoResponse = try await client.send(APIRequest(
|
||||
method: .get, path: "/api/yf-handset-app/photog/multi-plane/project-info",
|
||||
queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicID)),
|
||||
URLQueryItem(name: "project_id", value: String(projectID)),
|
||||
URLQueryItem(name: "order_number", value: orderNumber)]
|
||||
))
|
||||
guard response.order.orderNumber == orderNumber, response.order.projectID == projectID else {
|
||||
throw APIError.decodeFailed("套餐信息与当前订单或项目不一致,请刷新重试")
|
||||
}
|
||||
return try await client.send(APIRequest(method: .get, path: "/api/app/airport/workbench", queryItems: query))
|
||||
return response
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
import Foundation
|
||||
|
||||
/// 张工 project-info 的订单购买快照,权威提供次数、可选点位与航线。
|
||||
struct DroneDockProjectInfoResponse: Decodable, Equatable, Sendable {
|
||||
/// 根级订单摘要,与首页 orders 使用同一业务字段和权限口径。
|
||||
let order: DroneDockHomeOrder
|
||||
/// 购买快照中的点位,保持服务端顺序,不拼入其他来源的额外点位。
|
||||
let spots: [DroneDockPurchasedSpot]
|
||||
|
||||
/// 购买点位数组使用单数 spot 字段。
|
||||
private enum CodingKeys: String, CodingKey { case spots = "spot" }
|
||||
|
||||
/// 要求项目身份和点位数组存在,空数组才表示真实空态。
|
||||
init(from decoder: Decoder) throws {
|
||||
order = try DroneDockHomeOrder(from: decoder)
|
||||
guard order.projectID != nil else {
|
||||
throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath,
|
||||
debugDescription: "购买快照缺少项目 ID"))
|
||||
}
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
spots = try container.decode([DroneDockPurchasedSpot].self, forKey: .spots)
|
||||
guard Set(spots.map(\.id)).count == spots.count else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .spots, in: container, debugDescription: "购买点位 ID 重复")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 订单购买范围内的拍摄点;是否可选由 available 明确返回,不由位置或次数推导。
|
||||
struct DroneDockPurchasedSpot: Decodable, Equatable, Sendable {
|
||||
/// 拍摄点稳定 ID。
|
||||
let id: Int
|
||||
/// 购买快照的点位名称。
|
||||
let name: String
|
||||
/// 当前点位是否可用;缺失保留未知。
|
||||
let available: Bool?
|
||||
/// 点位封面地址,可缺失或为空。
|
||||
let coverURL: String?
|
||||
/// 购买范围内的航线,按服务端顺序展示。
|
||||
let airLines: [DroneDockPurchasedAirLine]
|
||||
|
||||
/// 张工购买点位字段,不接收 workbench 的 name 作为替代。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id = "scenic_spot_id", name = "scenic_spot_name", available
|
||||
case coverURL = "cover_url", airLines = "air_lines"
|
||||
}
|
||||
|
||||
/// 点位与本点位航线身份必须有效且唯一,空航线数组保留为空。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try container.positivePurchasedID(forKey: .id)
|
||||
name = try container.decode(String.self, forKey: .name)
|
||||
available = try container.decodeIfPresent(Bool.self, forKey: .available)
|
||||
coverURL = try container.decodeIfPresent(String.self, forKey: .coverURL)
|
||||
airLines = try container.decode([DroneDockPurchasedAirLine].self, forKey: .airLines)
|
||||
guard Set(airLines.map(\.id)).count == airLines.count else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .airLines, in: container, debugDescription: "购买点位内航线 ID 重复")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 订单已购航线及样片配置;不可用原因直接用于页面说明。
|
||||
struct DroneDockPurchasedAirLine: Decodable, Equatable, Sendable {
|
||||
/// 航线稳定 ID。
|
||||
let id: Int
|
||||
/// 航线名称。
|
||||
let name: String
|
||||
/// 当前航线是否可用,未知不自动视为可用。
|
||||
let available: Bool?
|
||||
/// 后端说明当前不可用的原因。
|
||||
let unavailableReason: String?
|
||||
/// 与该购买航线关联的样片,缺失或 null 表示没有可展示样片。
|
||||
let samples: [DroneDockPurchasedSample]
|
||||
|
||||
/// 张工购买航线字段。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id = "air_line_id", name = "air_line_name", available
|
||||
case unavailableReason = "unavailable_reason", samples
|
||||
}
|
||||
|
||||
/// 不替换未知可用状态或缺失样片地址,也不使用旧接口名称字段。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try container.positivePurchasedID(forKey: .id)
|
||||
name = try container.decode(String.self, forKey: .name)
|
||||
available = try container.decodeIfPresent(Bool.self, forKey: .available)
|
||||
unavailableReason = try container.decodeIfPresent(String.self, forKey: .unavailableReason)
|
||||
samples = try container.decodeIfPresent([DroneDockPurchasedSample].self, forKey: .samples) ?? []
|
||||
guard Set(samples.map(\.id)).count == samples.count else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .samples, in: container, debugDescription: "航线内样片 ID 重复")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 航线样片的服务端展示信息,不自行拼接预览或封面地址。
|
||||
struct DroneDockPurchasedSample: Decodable, Equatable, Sendable {
|
||||
/// 样片稳定 ID。
|
||||
let id: Int
|
||||
/// 样片名称,缺失时保留未知。
|
||||
let name: String?
|
||||
/// 样片封面地址。
|
||||
let coverURL: String?
|
||||
/// 样片视频预览地址。
|
||||
let previewURL: String?
|
||||
|
||||
/// 样片字段名。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id, name, coverURL = "cover_url", previewURL = "preview_url"
|
||||
}
|
||||
|
||||
/// 校验样片身份并兼容缺失、null 与空字符串的展示字段。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try container.positivePurchasedID(forKey: .id)
|
||||
name = try container.decodeIfPresent(String.self, forKey: .name)
|
||||
coverURL = try container.decodeIfPresent(String.self, forKey: .coverURL)
|
||||
previewURL = try container.decodeIfPresent(String.self, forKey: .previewURL)
|
||||
}
|
||||
}
|
||||
|
||||
/// 购买配置 ID 的整数读取器,兼容整数字符串但拒绝布尔、分数和任意文本。
|
||||
private struct DroneDockPurchasedInteger: Decodable {
|
||||
let value: Int
|
||||
|
||||
/// 读取确定的整数值,正数约束由字段读取处校验。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
if let number = try? container.decode(Int.self) { value = number }
|
||||
else if let text = try? container.decode(String.self), let number = Int(text) { value = number }
|
||||
else { throw DecodingError.dataCorruptedError(in: container, debugDescription: "需要整数或整数字符串") }
|
||||
}
|
||||
}
|
||||
|
||||
private extension KeyedDecodingContainer {
|
||||
/// 用于点位、航线、样片稳定身份的正整数。
|
||||
func positivePurchasedID(forKey key: Key) throws -> Int {
|
||||
let value = try decode(DroneDockPurchasedInteger.self, forKey: key).value
|
||||
guard value > 0 else {
|
||||
throw DecodingError.dataCorruptedError(forKey: key, in: self, debugDescription: "购买配置 ID 必须为正整数")
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
@@ -1,187 +1,154 @@
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
/// 真实拍摄准备状态:读取订单、定位和点位航线,选择过程不创建或执行飞行任务。
|
||||
/// 拍摄准备状态:只读取张工的已购配置,不创建飞行任务。
|
||||
final class DroneDockPreparationViewModel {
|
||||
/// 页面进入时固定的账号、景区及门店范围。
|
||||
let context: DroneDockHomeContext
|
||||
/// 首页选中的真实订单,仅用于身份及进入时的摘要展示。
|
||||
/// 首页订单仅提供身份和初次加载时的摘要。
|
||||
let order: DroneDockHomeOrder
|
||||
/// 最新通过身份校验的准备信息。
|
||||
private(set) var response: DroneDockPreparationResponse?
|
||||
/// 是否正在定位或读取准备信息。
|
||||
/// 张工返回的订单购买范围及最新次数。
|
||||
private(set) var projectInfo: DroneDockProjectInfoResponse?
|
||||
/// 购买配置是否尚未读取完成。
|
||||
private(set) var isLoading = false
|
||||
/// 加载失败或身份改变时的提示。
|
||||
/// 购买配置或请求身份错误。
|
||||
private(set) var errorMessage: String?
|
||||
/// 没有取得有效位置时的说明,不使用后端无坐标时返回的距离。
|
||||
private(set) var locationMessage: String?
|
||||
/// 当前响应是否基于本次成功定位的坐标。
|
||||
private(set) var hasLocation = false
|
||||
/// 当前点位与航线的稳定身份。
|
||||
/// 已购且可用的当前点位。
|
||||
private(set) var selectedSpotID: Int?
|
||||
/// 航线只属于当前选中的点位。
|
||||
/// 当前点位下已购且可用的航线。
|
||||
private(set) var selectedRouteID: Int?
|
||||
|
||||
private let service: any DroneDockPreparationServing
|
||||
private let locationProvider: any LocationProviding
|
||||
private let currentContext: @MainActor @Sendable () -> DroneDockHomeContext
|
||||
private var generation = 0
|
||||
|
||||
/// 注入真实只读接口、可替换定位服务和最新登录范围。
|
||||
/// 注入只读接口及最新会话,不绑定默认 MainActor。
|
||||
init(context: DroneDockHomeContext, order: DroneDockHomeOrder,
|
||||
service: any DroneDockPreparationServing, locationProvider: any LocationProviding,
|
||||
service: any DroneDockPreparationServing,
|
||||
currentContext: @escaping @MainActor @Sendable () -> DroneDockHomeContext) {
|
||||
self.context = context
|
||||
self.order = order
|
||||
self.service = service
|
||||
self.locationProvider = locationProvider
|
||||
self.currentContext = currentContext
|
||||
}
|
||||
|
||||
/// 当前订单的点位,保持服务端顺序。
|
||||
var spots: [DroneDockPreparationSpot] { response?.spots ?? [] }
|
||||
/// 当前选中点位,刷新后不再存在时会重新选择。
|
||||
var selectedSpot: DroneDockPreparationSpot? { spots.first { $0.id == selectedSpotID } }
|
||||
/// 只展示当前点位所属的航线。
|
||||
var routes: [DroneDockPreparationAirLine] { selectedSpot?.airLines ?? [] }
|
||||
/// 当前选中航线,不跨点位保留旧选择。
|
||||
var selectedRoute: DroneDockPreparationAirLine? { routes.first { $0.id == selectedRouteID } }
|
||||
|
||||
/// 获取一次位置和准备快照;定位失败仍可浏览点位航线,但范围保持未知。
|
||||
/// 只展示购买快照中的点位,保持张工返回顺序。
|
||||
var spots: [DroneDockPurchasedSpot] { projectInfo?.spots ?? [] }
|
||||
/// 当前有效点位。
|
||||
var selectedSpot: DroneDockPurchasedSpot? { spots.first { $0.id == selectedSpotID } }
|
||||
/// 只展示当前已购点位中的航线。
|
||||
var routes: [DroneDockPurchasedAirLine] { selectedSpot?.airLines ?? [] }
|
||||
/// 当前有效航线。
|
||||
var selectedRoute: DroneDockPurchasedAirLine? { routes.first { $0.id == selectedRouteID } }
|
||||
/// 进入页面后直接请求购买快照,不等待定位或设备接口。
|
||||
func refresh() async {
|
||||
generation &+= 1
|
||||
let requestGeneration = generation
|
||||
isLoading = true
|
||||
errorMessage = nil
|
||||
locationMessage = nil
|
||||
hasLocation = false
|
||||
defer { if generation == requestGeneration { isLoading = false } }
|
||||
guard await accepts(requestGeneration) else { return }
|
||||
guard context.canLoad, let number = DroneDockHomeMetric.usableText(order.orderNumber) else {
|
||||
clearResponse()
|
||||
errorMessage = "缺少当前景区或订单信息,请返回工作台重新进入"
|
||||
guard context.canLoad, let number = DroneDockHomeMetric.usableText(order.orderNumber),
|
||||
let projectID = order.projectID, projectID > 0 else {
|
||||
clearProject()
|
||||
errorMessage = "缺少当前景区、订单或套餐信息,请返回工作台重新进入"
|
||||
return
|
||||
}
|
||||
|
||||
var coordinate: DroneDockPreparationCoordinate?
|
||||
let projectResult: Result<DroneDockProjectInfoResponse, Error>
|
||||
do {
|
||||
let result = try await locationProvider.requestCoordinate(desiredAccuracy: kCLLocationAccuracyBest)
|
||||
let value = DroneDockPreparationCoordinate(latitude: result.latitude, longitude: result.longitude)
|
||||
guard value.isValid else { throw LocationProviderError.locationFailed }
|
||||
coordinate = value
|
||||
projectResult = .success(try await service.projectInfo(scenicID: context.scenicID, projectID: projectID, orderNumber: number))
|
||||
} catch {
|
||||
guard await accepts(requestGeneration) else { return }
|
||||
locationMessage = "\(error.localizedDescription),距离和拍摄范围待确认"
|
||||
projectResult = .failure(error)
|
||||
}
|
||||
guard await accepts(requestGeneration) else { return }
|
||||
do {
|
||||
let result = try await service.workbench(scenicID: context.scenicID, orderNumber: number, coordinate: coordinate)
|
||||
guard await accepts(requestGeneration) else { return }
|
||||
guard result.scenicID == context.scenicID, result.orderNumber == number,
|
||||
result.orderProgress?.orderNumber == nil || result.orderProgress?.orderNumber == number else {
|
||||
clearResponse()
|
||||
errorMessage = "接口返回的景区或订单与当前订单不一致,请刷新重试"
|
||||
return
|
||||
}
|
||||
response = result
|
||||
hasLocation = coordinate != nil
|
||||
if !spots.contains(where: { $0.id == selectedSpotID }) { selectedSpotID = spots.first?.id }
|
||||
if !routes.contains(where: { $0.id == selectedRouteID }) { selectedRouteID = routes.first?.id }
|
||||
} catch {
|
||||
guard await accepts(requestGeneration) else { return }
|
||||
clearResponse()
|
||||
errorMessage = error.localizedDescription
|
||||
switch projectResult {
|
||||
case .success(let value) where value.order.orderNumber == number && value.order.projectID == projectID:
|
||||
projectInfo = value
|
||||
restoreValidSelection()
|
||||
case .success:
|
||||
clearProject()
|
||||
errorMessage = "接口返回的订单或套餐与当前订单不一致,请刷新重试"
|
||||
case .failure(let error):
|
||||
clearProject()
|
||||
errorMessage = Self.message(for: error)
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择现有点位,切点后航线重置为该点位的第一条,不复用另一点位的航线。
|
||||
/// 不可用或可用性未知的点位不能选中,切点后选择首条明确可用的已购航线。
|
||||
func selectSpot(id: Int) {
|
||||
guard !isLoading, spots.contains(where: { $0.id == id }), selectedSpotID != id else { return }
|
||||
guard !isLoading, spots.contains(where: { $0.id == id && $0.available == true }), selectedSpotID != id else { return }
|
||||
selectedSpotID = id
|
||||
selectedRouteID = routes.first?.id
|
||||
selectedRouteID = routes.first(where: { $0.available == true })?.id
|
||||
}
|
||||
|
||||
/// 选择当前点位中的航线,忽略过期或不属于该点位的点击。
|
||||
/// 忽略其他点位、不可用及身份不明的航线选择。
|
||||
func selectRoute(id: Int) {
|
||||
guard !isLoading, routes.contains(where: { $0.id == id }) else { return }
|
||||
guard !isLoading, selectedSpot?.available == true,
|
||||
routes.contains(where: { $0.id == id && $0.available == true }) else { return }
|
||||
selectedRouteID = id
|
||||
}
|
||||
|
||||
/// 页面离开后使定位和网络的迟到结果失效。
|
||||
/// 离开后使购买快照请求失效,避免旧响应回填。
|
||||
func invalidate() {
|
||||
generation &+= 1
|
||||
isLoading = false
|
||||
errorMessage = nil
|
||||
locationMessage = nil
|
||||
clearResponse()
|
||||
clearProject()
|
||||
}
|
||||
|
||||
/// 根据实际机巢摘要展示连接状态,不将 can_shoot 当作设备连接证明。
|
||||
var connectionTitle: String {
|
||||
guard let airports = response?.airports, !airports.isEmpty else { return "机巢连接待确认" }
|
||||
if airports.contains(where: { $0.onlineStatus == 1 }) { return "有机巢在线" }
|
||||
if airports.allSatisfy({ $0.onlineStatus == 2 }) { return "机巢未连接" }
|
||||
return "机巢连接待确认"
|
||||
}
|
||||
/// 只为明确在线的设备摘要显示绿色状态。
|
||||
var connectionTone: DroneDockStatusTone {
|
||||
response?.airports.contains(where: { $0.onlineStatus == 1 }) == true ? .green : .gray
|
||||
}
|
||||
/// 只有请求携带有效定位时才采用服务端范围结论。
|
||||
var rangeTitle: String {
|
||||
guard hasLocation else { return "位置待确认" }
|
||||
guard let selectedSpot else { return "请选择拍摄点" }
|
||||
switch selectedSpot.inRange {
|
||||
case true: return "在拍摄范围内"
|
||||
case false: return "不在拍摄范围内"
|
||||
default: return "拍摄范围待确认"
|
||||
}
|
||||
}
|
||||
/// 未知位置或范围不显示绿色。
|
||||
var rangeTone: DroneDockStatusTone { hasLocation && selectedSpot?.inRange == true ? .green : .gray }
|
||||
/// 当前航线选择的展示摘要。
|
||||
/// 当前接口没有机巢连接信息,不能由购买权限推导设备状态。
|
||||
var connectionTitle: String { "机巢连接待确认" }
|
||||
/// 设备连接未知时使用中性色。
|
||||
var connectionTone: DroneDockStatusTone { .gray }
|
||||
/// 当前未读取位置与范围数据。
|
||||
var rangeTitle: String { "位置待确认" }
|
||||
/// 范围未知时使用中性色。
|
||||
var rangeTone: DroneDockStatusTone { .gray }
|
||||
/// 以购买快照中的名称展示当前选择。
|
||||
var selectionSummary: String {
|
||||
guard let selectedSpot else { return "请选择拍摄点" }
|
||||
guard let selectedRoute else { return "\(selectedSpot.name) · 未选航线" }
|
||||
return "\(selectedSpot.name) · \(selectedRoute.name)"
|
||||
}
|
||||
/// 多机状态一致时展示该状态,不假定某台机巢已被选派。
|
||||
var deviceStatusText: String {
|
||||
let labels = Set(response?.airports.map(\.statusTitle) ?? [])
|
||||
return labels.count == 1 ? labels.first! : "状态待确认"
|
||||
}
|
||||
/// 准备阶段尚未派机,状态标签使用中性色。
|
||||
/// 当前未读取设备状态,也尚未派机。
|
||||
var deviceStatusText: String { "状态待确认" }
|
||||
/// 准备阶段尚未派机。
|
||||
var deviceTone: DroneDockStatusTone { .gray }
|
||||
/// 保留后端明确的阻止原因,允许准备时展示下一步按钮标题。
|
||||
/// 文案反映购买权限,不开放实际召唤操作。
|
||||
var primaryButtonTitle: String {
|
||||
if let gate = response?.shootGate, gate.canShoot == false {
|
||||
return DroneDockHomeMetric.usableText(gate.primaryActionLabel) ?? "暂不可召唤"
|
||||
}
|
||||
if projectInfo?.order.shotRemain == 0 { return "拍摄次数已用完" }
|
||||
if let info = projectInfo, info.order.canCreateTask != true { return "暂不可召唤" }
|
||||
return "确认并召唤"
|
||||
}
|
||||
/// 展示当前阻止原因;本阶段仅对接准备信息,不发送召唤指令。
|
||||
/// 检查购买范围与额度;条件有效后仍提示召唤尚未开放。
|
||||
var admissionMessage: String {
|
||||
if isLoading { return "正在获取位置和拍摄准备信息" }
|
||||
if isLoading { return "正在获取拍摄准备信息" }
|
||||
if let errorMessage { return errorMessage }
|
||||
guard let response else { return "正在加载拍摄准备信息" }
|
||||
if let gate = response.shootGate, gate.canShoot == false {
|
||||
return DroneDockHomeMetric.usableText(gate.message)
|
||||
?? DroneDockHomeMetric.usableText(gate.primaryActionLabel) ?? "当前暂不可召唤,请刷新状态"
|
||||
}
|
||||
if let locationMessage { return locationMessage }
|
||||
guard let info = projectInfo else { return "正在加载拍摄准备信息" }
|
||||
if info.order.shotRemain == 0 { return "当前订单拍摄次数已用完" }
|
||||
guard let remaining = info.order.shotRemain, remaining > 0, info.order.shotTotal != nil else { return "拍摄次数待确认,请刷新状态" }
|
||||
guard info.order.canCreateTask == true else { return "当前订单暂不可新增拍摄任务,请刷新状态" }
|
||||
if spots.isEmpty { return "当前暂无可用拍摄点" }
|
||||
guard let spot = selectedSpot, spot.available == true else { return "请选择可用拍摄点" }
|
||||
if routes.isEmpty { return "当前拍摄点暂无可用航线" }
|
||||
if !hasLocation || selectedSpot?.inRange == nil { return "拍摄范围待确认,请重新定位" }
|
||||
if selectedSpot?.inRange == false { return "请前往所选拍摄点的拍摄范围内" }
|
||||
guard response.shootGate?.canShoot == true else { return "拍摄条件待确认,请刷新状态" }
|
||||
guard selectedRoute?.available == true else { return "请选择可用航线" }
|
||||
return "召唤功能暂未开放"
|
||||
}
|
||||
|
||||
private func clearResponse() {
|
||||
response = nil
|
||||
private func restoreValidSelection() {
|
||||
if !spots.contains(where: { $0.id == selectedSpotID && $0.available == true }) {
|
||||
selectedSpotID = spots.first(where: { $0.available == true })?.id
|
||||
selectedRouteID = nil
|
||||
}
|
||||
if !routes.contains(where: { $0.id == selectedRouteID && $0.available == true }) {
|
||||
selectedRouteID = routes.first(where: { $0.available == true })?.id
|
||||
}
|
||||
}
|
||||
|
||||
private func clearProject() {
|
||||
projectInfo = nil
|
||||
selectedSpotID = nil
|
||||
selectedRouteID = nil
|
||||
hasLocation = false
|
||||
}
|
||||
|
||||
private func accepts(_ requestGeneration: Int) async -> Bool {
|
||||
@@ -189,12 +156,15 @@ final class DroneDockPreparationViewModel {
|
||||
let latest = await currentContext()
|
||||
guard generation == requestGeneration, !Task.isCancelled else { return false }
|
||||
guard context.hasSameIdentity(as: latest) else {
|
||||
generation &+= 1
|
||||
isLoading = false
|
||||
clearResponse()
|
||||
invalidate()
|
||||
errorMessage = "账号或景区已变化,请返回工作台重新进入"
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private static func message(for error: Error) -> String? {
|
||||
error is CancellationError ? nil : error.localizedDescription
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import UIKit
|
||||
final class DroneDockDeviceCardView: UIView {
|
||||
private let nameLabel = DroneDockStyle.label(size: 15, weight: .semibold)
|
||||
private let statusLabel = DroneDockDeviceStatusView()
|
||||
private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||||
private let batteryView = DroneDockBatteryView()
|
||||
private let signalValue = DroneDockStyle.label(size: 19, weight: .semibold)
|
||||
private let satelliteValue = DroneDockStyle.label(size: 19, weight: .semibold)
|
||||
@@ -28,6 +29,7 @@ final class DroneDockDeviceCardView: UIView {
|
||||
|
||||
/// 未知读数由模型提供破折号,不以零代替未知。
|
||||
func apply(device: DroneDockDevice) {
|
||||
detailLabel.isHidden = true
|
||||
nameLabel.text = device.name
|
||||
statusLabel.apply(title: device.state.title, tone: device.state.tone)
|
||||
batteryView.apply(telemetry: device.telemetry)
|
||||
@@ -42,6 +44,7 @@ final class DroneDockDeviceCardView: UIView {
|
||||
|
||||
/// 展示 home 返回的机巢名称、工作状态及格式化读数,不根据展示状态推断起飞许可。
|
||||
func apply(airport: DroneDockHomeAirport) {
|
||||
detailLabel.isHidden = true
|
||||
nameLabel.text = airport.name
|
||||
statusLabel.apply(title: airport.statusTitle, tone: airport.statusTone)
|
||||
batteryView.apply(text: airport.metricText(for: "battery"), progress: airport.batteryProgress)
|
||||
@@ -54,13 +57,31 @@ final class DroneDockDeviceCardView: UIView {
|
||||
accessibilityLabel = "\(airport.name),\(airport.statusTitle)"
|
||||
}
|
||||
|
||||
/// 没有设备快照时保留完整遥测卡,读数保持未知并展示当前加载结果。
|
||||
func applyPlaceholder(status: String, detail: String) {
|
||||
nameLabel.text = "暂无无人机"
|
||||
statusLabel.apply(title: status, tone: .gray)
|
||||
detailLabel.text = detail
|
||||
detailLabel.isHidden = false
|
||||
batteryView.apply(telemetry: .unknown)
|
||||
signalValue.text = "—"
|
||||
satelliteValue.text = "—"
|
||||
temperatureValue.text = "—"
|
||||
windValue.text = "—"
|
||||
rainValue.text = "—"
|
||||
accessibilityIdentifier = "drone.device.empty"
|
||||
accessibilityLabel = "暂无无人机,\(status),\(detail)"
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
temperatureValue.accessibilityIdentifier = "drone.metric.env_temp"
|
||||
windValue.accessibilityIdentifier = "drone.metric.wind_speed"
|
||||
rainValue.accessibilityIdentifier = "drone.metric.rainfall"
|
||||
signalValue.accessibilityIdentifier = "drone.metric.signal"
|
||||
satelliteValue.accessibilityIdentifier = "drone.metric.satellite"
|
||||
[nameLabel, statusLabel, batteryView].forEach(addSubview)
|
||||
detailLabel.isHidden = true
|
||||
detailLabel.lineBreakMode = .byTruncatingMiddle
|
||||
[nameLabel, statusLabel, detailLabel, batteryView].forEach(addSubview)
|
||||
nameLabel.snp.makeConstraints { make in
|
||||
make.top.leading.equalToSuperview().inset(16)
|
||||
make.trailing.lessThanOrEqualTo(statusLabel.snp.leading).offset(-8)
|
||||
@@ -69,6 +90,10 @@ final class DroneDockDeviceCardView: UIView {
|
||||
make.centerY.equalTo(nameLabel)
|
||||
make.trailing.equalToSuperview().inset(16)
|
||||
}
|
||||
detailLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(nameLabel.snp.bottom).offset(2)
|
||||
make.leading.trailing.equalToSuperview().inset(16)
|
||||
}
|
||||
batteryView.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().inset(20)
|
||||
make.top.equalTo(nameLabel.snp.bottom).offset(16)
|
||||
|
||||
@@ -131,6 +131,18 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
private func configureDataSource() {
|
||||
dataSource = UICollectionViewDiffableDataSource<Section, Item>(collectionView: collectionView) { [weak self] collection, path, item in
|
||||
guard let self else { return nil }
|
||||
if item == .devices {
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "device", for: path) as! DroneDockDeviceCell
|
||||
let error = self.viewModel.deviceErrorMessage ?? self.viewModel.errorMessage
|
||||
if self.isRefreshing || error == nil && self.viewModel.response == nil {
|
||||
cell.cardView.applyPlaceholder(status: "正在加载", detail: "正在获取最新数据")
|
||||
} else if let error {
|
||||
cell.cardView.applyPlaceholder(status: "设备加载失败", detail: error + ",请下拉重试")
|
||||
} else {
|
||||
cell.cardView.applyPlaceholder(status: "暂无数据", detail: "当前景区暂无设备数据")
|
||||
}
|
||||
return cell
|
||||
}
|
||||
if case .device(let id) = item {
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "device", for: path) as! DroneDockDeviceCell
|
||||
if let airport = self.viewModel.response?.airports.first(where: { $0.id == id }) {
|
||||
@@ -162,9 +174,9 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
cell.applyLoadMore(isLoading: self.isLoadingOrdersPage,
|
||||
error: self.viewModel.ordersLoadMoreErrorMessage,
|
||||
enabled: !self.isRefreshing) { [weak self] in self?.loadMoreOrders() }
|
||||
case .devices, .orders:
|
||||
self.applyDataState(to: cell, isDevice: item == .devices)
|
||||
case .device, .order: break
|
||||
case .orders:
|
||||
self.applyOrderState(to: cell)
|
||||
case .devices, .device, .order: break
|
||||
}
|
||||
return cell
|
||||
}
|
||||
@@ -183,15 +195,15 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private func applyDataState(to cell: DroneDockHomeContentCell, isDevice: Bool) {
|
||||
let hasResponse = isDevice ? viewModel.response != nil : viewModel.ordersResponse != nil
|
||||
let error = (isDevice ? viewModel.deviceErrorMessage : viewModel.ordersErrorMessage) ?? viewModel.errorMessage
|
||||
private func applyOrderState(to cell: DroneDockHomeContentCell) {
|
||||
let hasResponse = viewModel.ordersResponse != nil
|
||||
let error = viewModel.ordersErrorMessage ?? viewModel.errorMessage
|
||||
if isRefreshing, !hasResponse {
|
||||
cell.applyMessage(symbol: "arrow.triangle.2.circlepath", title: "正在加载", detail: "正在获取最新数据")
|
||||
return
|
||||
}
|
||||
if let error {
|
||||
cell.applyMessage(symbol: "wifi.exclamationmark", title: isDevice ? "设备加载失败" : "订单加载失败",
|
||||
cell.applyMessage(symbol: "wifi.exclamationmark", title: "订单加载失败",
|
||||
detail: error + ",请下拉重试")
|
||||
return
|
||||
}
|
||||
@@ -199,9 +211,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
cell.applyMessage(symbol: "arrow.triangle.2.circlepath", title: "正在加载", detail: "正在获取最新数据")
|
||||
return
|
||||
}
|
||||
cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text",
|
||||
title: isDevice ? "暂无无人机" : "暂无拍摄订单",
|
||||
detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据")
|
||||
cell.applyMessage(symbol: "doc.text", title: "暂无拍摄订单", detail: "当前景区暂无拍摄订单数据")
|
||||
}
|
||||
|
||||
private func applySnapshot(animated: Bool, completion: (() -> Void)? = nil) {
|
||||
@@ -244,9 +254,8 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
UICollectionViewCompositionalLayout { [weak self] index, environment in
|
||||
guard let section = Section(rawValue: index) else { return nil }
|
||||
let deviceCount = self?.viewModel.response?.airports.count ?? 0
|
||||
let hasDevices = section == .devices && deviceCount > 0
|
||||
let multipleDevices = section == .devices && deviceCount > 1
|
||||
let height: NSCollectionLayoutDimension = hasDevices ? .absolute(248) : section == .context ? .estimated(40) : .estimated(132)
|
||||
let height: NSCollectionLayoutDimension = section == .devices ? .absolute(248) : section == .context ? .estimated(40) : .estimated(132)
|
||||
let item = NSCollectionLayoutItem(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: height))
|
||||
let width: NSCollectionLayoutDimension = multipleDevices ? .absolute(environment.container.effectiveContentSize.width - 48) : .fractionalWidth(1)
|
||||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: width, heightDimension: height), subitems: [item])
|
||||
@@ -295,7 +304,6 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
viewModel: DroneDockPreparationViewModel(
|
||||
context: context, order: order,
|
||||
service: DroneDockPreparationAPI(client: NetworkServices.shared.apiClient),
|
||||
locationProvider: LocationProvider.shared,
|
||||
currentContext: { Self.currentContext() }
|
||||
))
|
||||
navigationController?.pushViewController(controller, animated: true)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 读取 workbench 的真实拍摄准备页,点位和航线选择只影响页面展示。
|
||||
/// 进入页面后通过 project-info 读取已购套餐、点位和航线。
|
||||
@MainActor
|
||||
final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
/// 当前订单与准备页的真实读取状态。
|
||||
let viewModel: DroneDockPreparationViewModel
|
||||
|
||||
/// 点位与航线沿用原准备页顺序,状态区单独承载加载、错误和定位说明。
|
||||
/// 点位与航线沿用原准备页顺序,状态区单独承载加载和错误说明。
|
||||
private enum Section: Int, CaseIterable { case order, points, routes, status }
|
||||
/// 点位与航线使用后端稳定 ID,刷新时保留有效选择。
|
||||
private enum Item: Hashable { case order, point(Int), route(Int), emptyPoints, emptyRoutes, status }
|
||||
@@ -90,7 +90,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
isRefreshing = true
|
||||
refreshTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
let isInitialLoad = self.viewModel.response == nil
|
||||
let isInitialLoad = self.viewModel.projectInfo == nil
|
||||
self.applySnapshot(animated: false)
|
||||
await self.viewModel.refresh()
|
||||
guard !Task.isCancelled else { return }
|
||||
@@ -115,13 +115,13 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
switch item {
|
||||
case .order:
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "order", for: path) as! DronePreparationOrderCell
|
||||
cell.apply(homeOrder: self.viewModel.order, progress: self.viewModel.response?.orderProgress,
|
||||
usesHomeSnapshot: self.viewModel.response == nil && self.viewModel.errorMessage == nil)
|
||||
cell.apply(homeOrder: self.viewModel.order, summary: self.viewModel.projectInfo?.order,
|
||||
usesHomeSnapshot: self.viewModel.projectInfo == nil && self.viewModel.errorMessage == nil)
|
||||
return cell
|
||||
case .point(let id):
|
||||
let cell = list.dequeueReusableCell(withReuseIdentifier: "point", for: path) as! DronePreparationPointCell
|
||||
if let spot = self.viewModel.spots.first(where: { $0.id == id }) {
|
||||
cell.apply(spot: spot, selected: self.viewModel.selectedSpotID == id, hasLocation: self.viewModel.hasLocation)
|
||||
cell.apply(spot: spot, selected: self.viewModel.selectedSpotID == id)
|
||||
}
|
||||
return cell
|
||||
case .route(let id):
|
||||
@@ -135,7 +135,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
if item == .status {
|
||||
self.applyStatus(to: cell)
|
||||
} else if item == .emptyPoints {
|
||||
cell.apply(title: "暂无可用拍摄点", detail: "当前订单暂无拍摄点配置,请刷新重试")
|
||||
cell.apply(title: "暂无可用拍摄点", detail: "当前套餐暂无已购拍摄点,请刷新重试")
|
||||
} else if self.viewModel.selectedSpot == nil {
|
||||
cell.apply(title: "请选择拍摄点", detail: "选择拍摄点后查看对应航线")
|
||||
} else {
|
||||
@@ -153,12 +153,10 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
}
|
||||
|
||||
private func applyStatus(to cell: DronePreparationEmptyCell) {
|
||||
if isRefreshing, viewModel.response == nil {
|
||||
cell.apply(title: "正在加载", detail: "正在获取拍摄点、航线和设备状态")
|
||||
if isRefreshing, viewModel.projectInfo == nil {
|
||||
cell.apply(title: "正在加载", detail: "正在获取已购套餐、拍摄点和航线")
|
||||
} else if let error = viewModel.errorMessage {
|
||||
cell.apply(title: "准备信息加载失败", detail: error + ",请下拉或点击刷新状态重试")
|
||||
} else if let message = viewModel.locationMessage, viewModel.response != nil {
|
||||
cell.apply(title: "位置待确认", detail: message)
|
||||
} else {
|
||||
cell.apply(title: "正在加载", detail: "正在获取拍摄准备信息")
|
||||
}
|
||||
@@ -171,12 +169,11 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||
snapshot.appendSections(Section.allCases)
|
||||
snapshot.appendItems([.order], toSection: .order)
|
||||
if viewModel.response != nil, viewModel.errorMessage == nil {
|
||||
if viewModel.projectInfo != nil, viewModel.errorMessage == nil {
|
||||
snapshot.appendItems(viewModel.spots.isEmpty ? [.emptyPoints] : viewModel.spots.map { .point($0.id) }, toSection: .points)
|
||||
if !viewModel.spots.isEmpty {
|
||||
snapshot.appendItems(viewModel.routes.isEmpty ? [.emptyRoutes] : viewModel.routes.map { .route($0.id) }, toSection: .routes)
|
||||
}
|
||||
if viewModel.locationMessage != nil { snapshot.appendItems([.status], toSection: .status) }
|
||||
} else {
|
||||
snapshot.appendItems([.status], toSection: .status)
|
||||
}
|
||||
@@ -212,7 +209,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
height = .absolute(self.viewModel.spots.isEmpty ? 150 : 80)
|
||||
width = self.viewModel.spots.isEmpty ? .fractionalWidth(1) : .absolute(160)
|
||||
case .routes:
|
||||
height = .absolute(self.viewModel.routes.isEmpty ? 160 : 64)
|
||||
height = self.viewModel.routes.isEmpty ? .absolute(160) : .estimated(64)
|
||||
width = .fractionalWidth(1)
|
||||
case .status: height = .absolute(160); width = .fractionalWidth(1)
|
||||
}
|
||||
@@ -224,7 +221,7 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
layout.orthogonalScrollingBehavior = .continuous
|
||||
layout.interGroupSpacing = 8
|
||||
}
|
||||
let showsHeading = self.viewModel.response != nil && self.viewModel.errorMessage == nil
|
||||
let showsHeading = self.viewModel.projectInfo != nil && self.viewModel.errorMessage == nil
|
||||
&& (section == .points || (section == .routes && !self.viewModel.spots.isEmpty))
|
||||
if showsHeading {
|
||||
layout.boundarySupplementaryItems = [NSCollectionLayoutBoundarySupplementaryItem(
|
||||
@@ -268,7 +265,13 @@ final class DroneDockRemotePreparationViewController: BaseViewController {
|
||||
extension DroneDockRemotePreparationViewController: UICollectionViewDelegate {
|
||||
/// 点位和航线只在当前成功快照中选择,刷新期间不切换旧配置。
|
||||
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||
!isRefreshing && viewModel.response != nil && viewModel.errorMessage == nil
|
||||
guard !isRefreshing, viewModel.projectInfo != nil, viewModel.errorMessage == nil,
|
||||
let item = dataSource.itemIdentifier(for: indexPath) else { return false }
|
||||
switch item {
|
||||
case .point(let id): return viewModel.spots.first { $0.id == id }?.available == true
|
||||
case .route(let id): return viewModel.routes.first { $0.id == id }?.available == true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新本地点位、航线及底部摘要,不创建拍摄任务。
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Kingfisher
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
@@ -67,17 +68,19 @@ final class DronePreparationOrderCell: UICollectionViewCell {
|
||||
accessibilityLabel = "\(order.customerName),含\(order.totalShootingCount)次拍摄,已拍摄\(order.successfulShootingCount)次,剩余\(order.remainingShootingCount)次"
|
||||
}
|
||||
|
||||
/// 使用真实首页游客信息与准备页最新次数;准备响应中的未知次数不回填成旧值。
|
||||
func apply(homeOrder: DroneDockHomeOrder, progress: DroneDockPreparationOrderProgress?, usesHomeSnapshot: Bool = false) {
|
||||
let total = usesHomeSnapshot ? homeOrder.shotTotal : progress?.shotTotal
|
||||
let used = usesHomeSnapshot ? homeOrder.shotUsed : progress?.shotUsed
|
||||
let remaining = usesHomeSnapshot ? homeOrder.shotRemain : progress?.shotRemain
|
||||
let package = progress == nil ? homeOrder.packageTitle : progress?.packageName
|
||||
customerLabel.text = homeOrder.touristTitle
|
||||
/// 使用 project-info 的最新购买摘要;缺失次数不回退旧订单或 workbench 统计。
|
||||
func apply(homeOrder: DroneDockHomeOrder, summary: DroneDockHomeOrder?, usesHomeSnapshot: Bool = false) {
|
||||
let snapshot = usesHomeSnapshot ? homeOrder : summary
|
||||
let total = snapshot?.shotTotal
|
||||
let used = snapshot?.shotUsed
|
||||
let remaining = snapshot?.shotRemain
|
||||
let package = snapshot?.packageName
|
||||
let tourist = summary?.touristTitle ?? homeOrder.touristTitle
|
||||
customerLabel.text = tourist
|
||||
packageLabel.text = package?.isEmpty == false ? package : "含 \(total.map(String.init) ?? "—") 次拍摄"
|
||||
completedLabel.text = "已拍摄 \(used.map(String.init) ?? "—") 次"
|
||||
remainingLabel.attributedText = remainingText(remaining.map(String.init) ?? "—")
|
||||
accessibilityLabel = "\(homeOrder.touristTitle),\(packageLabel.text ?? ""),已拍摄\(used.map(String.init) ?? "—")次,剩余\(remaining.map(String.init) ?? "—")次"
|
||||
accessibilityLabel = "\(tourist),\(packageLabel.text ?? ""),已拍摄\(used.map(String.init) ?? "—")次,剩余\(remaining.map(String.init) ?? "—")次"
|
||||
accessibilityIdentifier = "drone.preparation.order"
|
||||
}
|
||||
|
||||
@@ -142,6 +145,8 @@ final class DronePreparationPointCell: UICollectionViewCell {
|
||||
|
||||
/// 仅映射模型提供的范围和次数,已拍摄的点位仍保持可选择。
|
||||
func apply(point: DroneShootingPoint, selected: Bool) {
|
||||
thumbnail.kf.cancelDownloadTask()
|
||||
contentView.alpha = 1
|
||||
nameLabel.text = point.name
|
||||
thumbnail.contentMode = .scaleAspectFill
|
||||
thumbnail.image = UIImage(named: point.id == "point-jinque" ? "drone_demo_pagoda" : "drone_demo_mountain")
|
||||
@@ -160,39 +165,47 @@ final class DronePreparationPointCell: UICollectionViewCell {
|
||||
accessibilityIdentifier = "drone.preparation.point.\(point.id)"
|
||||
}
|
||||
|
||||
/// 距离只在请求携带有效定位时展示,服务端未提供点位图片时不使用演示山景。
|
||||
func apply(spot: DroneDockPreparationSpot, selected: Bool, hasLocation: Bool) {
|
||||
/// 展示已购点位;当前接口未提供距离与点位已拍次数,保持未知占位。
|
||||
func apply(spot: DroneDockPurchasedSpot, selected: Bool) {
|
||||
nameLabel.text = spot.name
|
||||
thumbnail.kf.cancelDownloadTask()
|
||||
thumbnail.image = UIImage(systemName: "mappin.and.ellipse")
|
||||
thumbnail.contentMode = .center
|
||||
thumbnail.tintColor = DroneDockStyle.secondary
|
||||
if hasLocation {
|
||||
rangeLabel.text = spot.distanceLabel?.isEmpty == false ? spot.distanceLabel : "距离待确认"
|
||||
rangeLabel.textColor = spot.inRange == true ? DroneDockStyle.success : DroneDockStyle.secondary
|
||||
} else {
|
||||
rangeLabel.text = "待定位"
|
||||
rangeLabel.textColor = DroneDockStyle.warning
|
||||
if let text = spot.coverURL, let url = URL(string: text),
|
||||
let scheme = url.scheme?.lowercased(), ["https", "http"].contains(scheme), url.host != nil {
|
||||
thumbnail.contentMode = .scaleAspectFill
|
||||
thumbnail.kf.setImage(with: url, placeholder: UIImage(systemName: "mappin.and.ellipse"))
|
||||
}
|
||||
rangeLabel.text = "距离待确认"
|
||||
rangeLabel.textColor = DroneDockStyle.secondary
|
||||
locationIcon.tintColor = rangeLabel.textColor
|
||||
if let status = spot.shotStatusLabel, !status.isEmpty {
|
||||
countLabel.text = status
|
||||
} else if let count = spot.shotCount {
|
||||
countLabel.text = count == 0 ? "未拍摄" : "已拍摄 \(count) 次"
|
||||
if spot.available != true {
|
||||
countLabel.text = spot.available == false ? "拍摄点不可用" : "可用性待确认"
|
||||
} else {
|
||||
countLabel.text = "已拍摄 — 次"
|
||||
}
|
||||
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.07) : .white
|
||||
contentView.layer.borderColor = (selected ? DroneDockStyle.primary : DroneDockStyle.border).cgColor
|
||||
contentView.alpha = spot.available == true ? 1 : 0.55
|
||||
accessibilityLabel = "\(spot.name),\(rangeLabel.text ?? ""),\(countLabel.text ?? "")"
|
||||
accessibilityTraits = selected ? [.button, .selected] : .button
|
||||
if spot.available != true { accessibilityTraits.insert(.notEnabled) }
|
||||
accessibilityIdentifier = "drone.preparation.point.\(spot.id)"
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
thumbnail.kf.cancelDownloadTask()
|
||||
thumbnail.image = nil
|
||||
}
|
||||
}
|
||||
|
||||
/// 纵向单选航线行,点击整行后由 ViewModel 保留有效选择。
|
||||
@MainActor
|
||||
final class DronePreparationRouteCell: UICollectionViewCell {
|
||||
private let nameLabel = DroneDockStyle.label(size: 16, weight: .semibold)
|
||||
private let unavailableLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
|
||||
private let routeIcon = DronePreparationRouteIconView()
|
||||
private let checkmark = UIImageView()
|
||||
private let separator = UIView()
|
||||
@@ -203,16 +216,24 @@ final class DronePreparationRouteCell: UICollectionViewCell {
|
||||
contentView.layer.cornerCurve = .continuous
|
||||
checkmark.contentMode = .scaleAspectFit
|
||||
separator.backgroundColor = DroneDockStyle.border
|
||||
[routeIcon, nameLabel, checkmark, separator].forEach(contentView.addSubview)
|
||||
nameLabel.numberOfLines = 0
|
||||
unavailableLabel.numberOfLines = 0
|
||||
unavailableLabel.isHidden = true
|
||||
let labels = UIStackView(arrangedSubviews: [nameLabel, unavailableLabel])
|
||||
labels.axis = .vertical
|
||||
labels.spacing = 5
|
||||
[routeIcon, labels, checkmark, separator].forEach(contentView.addSubview)
|
||||
routeIcon.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(12)
|
||||
make.centerY.equalToSuperview()
|
||||
make.size.equalTo(40)
|
||||
}
|
||||
nameLabel.snp.makeConstraints { make in
|
||||
labels.snp.makeConstraints { make in
|
||||
make.leading.equalTo(routeIcon.snp.trailing).offset(14)
|
||||
make.centerY.equalToSuperview()
|
||||
make.trailing.lessThanOrEqualTo(checkmark.snp.leading).offset(-12)
|
||||
make.top.greaterThanOrEqualToSuperview().offset(12)
|
||||
make.bottom.lessThanOrEqualToSuperview().inset(12)
|
||||
make.trailing.equalTo(checkmark.snp.leading).offset(-12)
|
||||
}
|
||||
checkmark.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().inset(14)
|
||||
@@ -229,8 +250,21 @@ final class DronePreparationRouteCell: UICollectionViewCell {
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 航线原因允许换行,自适应高度时保持列表提供的整行宽度。
|
||||
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
let width = layoutAttributes.size.width
|
||||
let attributes = layoutAttributes.copy() as! UICollectionViewLayoutAttributes
|
||||
let size = contentView.systemLayoutSizeFitting(
|
||||
CGSize(width: width, height: 0),
|
||||
withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||
attributes.size = CGSize(width: width, height: max(64, ceil(size.height)))
|
||||
return attributes
|
||||
}
|
||||
|
||||
/// 选中样式仅反映现有选择,重复点击不会在视图中取消单选。
|
||||
func apply(route: DroneShootingRoute, selected: Bool) {
|
||||
unavailableLabel.isHidden = true
|
||||
contentView.alpha = 1
|
||||
nameLabel.text = route.name
|
||||
nameLabel.textColor = selected ? DroneDockStyle.primary : DroneDockStyle.text
|
||||
routeIcon.apply(selected: selected)
|
||||
@@ -244,16 +278,23 @@ final class DronePreparationRouteCell: UICollectionViewCell {
|
||||
}
|
||||
|
||||
/// 展示当前真实点位的航线选择,不从行点击发起任何飞行操作。
|
||||
func apply(route: DroneDockPreparationAirLine, selected: Bool) {
|
||||
func apply(route: DroneDockPurchasedAirLine, selected: Bool) {
|
||||
nameLabel.text = route.name
|
||||
let reason = route.available == false
|
||||
? DroneDockHomeMetric.usableText(route.unavailableReason) ?? "航线暂不可用"
|
||||
: "可用性待确认"
|
||||
unavailableLabel.text = reason
|
||||
unavailableLabel.isHidden = route.available == true
|
||||
contentView.alpha = route.available == true ? 1 : 0.55
|
||||
nameLabel.textColor = selected ? DroneDockStyle.primary : DroneDockStyle.text
|
||||
routeIcon.apply(selected: selected)
|
||||
checkmark.image = UIImage(systemName: selected ? "checkmark.circle.fill" : "circle")
|
||||
checkmark.tintColor = selected ? DroneDockStyle.primary : UIColor(hex: 0xA4ABB8)
|
||||
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.08) : .white
|
||||
separator.isHidden = selected
|
||||
accessibilityLabel = route.name
|
||||
accessibilityLabel = route.available == true ? route.name : "\(route.name),\(reason)"
|
||||
accessibilityTraits = selected ? [.button, .selected] : .button
|
||||
if route.available != true { accessibilityTraits.insert(.notEnabled) }
|
||||
accessibilityIdentifier = "drone.preparation.route.\(route.id)"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user