feat(drone-dock): 接入首页真实数据并完善设备卡片

通过 airport/home 读取当前景区和门店的设备与统计,隔离失效会话回包,未知遥测显示破折号。完善状态圆点、分割线和卫星图标;订单详情等待后端测试数据。

验证:iPhone 11 上 49 项相关测试、样式调整后 9 项界面回归,以及测试样例匿名化后 20 项测试均通过。真实联调响应、日志和截图仅保留在本地。
This commit is contained in:
2026-10-27 15:05:51 +08:00
parent 7862d208ce
commit 40060cd883
15 changed files with 1739 additions and 14 deletions
@@ -4,7 +4,7 @@ import UIKit
/// 设备遥测卡:只展示设备状态,横向浏览不会选择执行拍摄的无人机。
final class DroneDockDeviceCardView: UIView {
private let nameLabel = DroneDockStyle.label(size: 15, weight: .semibold)
private let statusLabel = DroneDockStatusLabel()
private let statusLabel = DroneDockDeviceStatusView()
private let batteryView = DroneDockBatteryView()
private let signalValue = DroneDockStyle.label(size: 19, weight: .semibold)
private let satelliteValue = DroneDockStyle.label(size: 19, weight: .semibold)
@@ -40,7 +40,26 @@ final class DroneDockDeviceCardView: UIView {
accessibilityLabel = "\(device.name),\(device.state.title)"
}
/// 展示 home 返回的机巢名称、工作状态及格式化读数,不根据展示状态推断起飞许可。
func apply(airport: DroneDockHomeAirport) {
nameLabel.text = airport.name
statusLabel.apply(title: airport.statusTitle, tone: airport.statusTone)
batteryView.apply(text: airport.metricText(for: "battery"), progress: airport.batteryProgress)
temperatureValue.text = airport.metricText(for: "env_temp")
windValue.text = airport.metricText(for: "wind_speed")
rainValue.text = airport.metricText(for: "rainfall")
signalValue.text = airport.metricText(for: "signal")
satelliteValue.text = airport.metricText(for: "satellite")
accessibilityIdentifier = "drone.device.\(airport.id)"
accessibilityLabel = "\(airport.name),\(airport.statusTitle)"
}
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)
nameLabel.snp.makeConstraints { make in
make.top.leading.equalToSuperview().inset(16)
@@ -57,7 +76,7 @@ final class DroneDockDeviceCardView: UIView {
}
let signal = telemetryRow(symbol: "antenna.radiowaves.left.and.right", title: "信号状态", value: signalValue)
let satellites = telemetryRow(symbol: "sparkles", title: "搜星状态", value: satelliteValue)
let satellites = telemetryRow(image: UIImage(named: "drone_telemetry_satellite"), title: "搜星状态", value: satelliteValue)
let radioStack = UIStackView(arrangedSubviews: [signal, satellites])
radioStack.axis = .vertical
radioStack.distribution = .fillEqually
@@ -77,11 +96,12 @@ final class DroneDockDeviceCardView: UIView {
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(0.5)
}
let metrics = UIStackView(arrangedSubviews: [
let metricColumns = [
metric(value: temperatureValue, symbol: "thermometer.medium", title: "环境温度"),
metric(value: windValue, symbol: "wind", title: "风速"),
metric(value: rainValue, symbol: "cloud", title: "雨量")
])
metric(value: rainValue, symbol: "cloud.rain", title: "雨量")
]
let metrics = UIStackView(arrangedSubviews: metricColumns)
metrics.axis = .horizontal
metrics.distribution = .fillEqually
addSubview(metrics)
@@ -90,10 +110,24 @@ final class DroneDockDeviceCardView: UIView {
make.leading.trailing.equalToSuperview().inset(12)
make.bottom.equalToSuperview().inset(14)
}
for column in metricColumns.dropFirst() {
let separator = UIView()
separator.backgroundColor = DroneDockStyle.border
metrics.addSubview(separator)
separator.snp.makeConstraints { make in
make.leading.equalTo(column.snp.leading)
make.top.bottom.equalToSuperview()
make.width.equalTo(0.5)
}
}
}
private func telemetryRow(symbol: String, title: String, value: UILabel) -> UIView {
let icon = UIImageView(image: UIImage(systemName: symbol))
telemetryRow(image: UIImage(systemName: symbol), title: title, value: value)
}
private func telemetryRow(image: UIImage?, title: String, value: UILabel) -> UIView {
let icon = UIImageView(image: image?.withRenderingMode(.alwaysTemplate))
icon.tintColor = DroneDockStyle.secondary
icon.contentMode = .scaleAspectFit
let label = DroneDockStyle.label(title, size: 11, color: DroneDockStyle.secondary)
@@ -128,6 +162,39 @@ final class DroneDockDeviceCardView: UIView {
}
}
/// 设备专用状态标签,圆点与文字共用语义颜色,不改变其他业务标签。
private final class DroneDockDeviceStatusView: UIView {
private let dot = UIView()
private let titleLabel = DroneDockStyle.label(size: 11, weight: .medium)
override init(frame: CGRect) {
super.init(frame: frame)
layer.cornerRadius = 6
dot.layer.cornerRadius = 3
dot.snp.makeConstraints { $0.size.equalTo(6) }
let content = UIStackView(arrangedSubviews: [dot, titleLabel])
content.axis = .horizontal
content.alignment = .center
content.spacing = 5
addSubview(content)
content.snp.makeConstraints { $0.edges.equalToSuperview().inset(UIEdgeInsets(top: 4, left: 7, bottom: 4, right: 7)) }
titleLabel.setContentHuggingPriority(.required, for: .horizontal)
titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 圆点、文字及浅色背景同步更新,复用时不残留上一设备的状态色。
func apply(title: String, tone: DroneDockStatusTone) {
let color = DroneDockStyle.color(for: tone)
titleLabel.text = title
titleLabel.textColor = color
dot.backgroundColor = color
backgroundColor = color.withAlphaComponent(0.09)
}
}
/// 环形电量组件,未知电量只显示轨道和占位读数。
private final class DroneDockBatteryView: UIView {
private let track = CAShapeLayer()
@@ -136,6 +203,7 @@ private final class DroneDockBatteryView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
valueLabel.accessibilityIdentifier = "drone.metric.battery"
for layer in [track, progress] {
layer.fillColor = UIColor.clear.cgColor
layer.lineWidth = 7
@@ -165,9 +233,14 @@ private final class DroneDockBatteryView: UIView {
}
func apply(telemetry: DroneDockTelemetry) {
valueLabel.text = telemetry.batteryText
progress.strokeEnd = telemetry.batteryProgress ?? 0
accessibilityLabel = "电池电量 \(telemetry.batteryText)"
apply(text: telemetry.batteryText, progress: telemetry.batteryProgress)
}
/// 有效电量才绘制进度;未知值只保留环形轨道与破折号。
func apply(text: String, progress value: Double?) {
valueLabel.text = text
progress.strokeEnd = value.map { CGFloat(min(1, max(0, $0))) } ?? 0
accessibilityLabel = "电池电量 \(text)"
isAccessibilityElement = true
}
}