feat(drone-dock): 新增拍摄准备与当前任务页面

This commit is contained in:
2026-10-23 16:40:02 +08:00
parent 8072d95d3b
commit 7834b8bcbc
33 changed files with 3799 additions and 6 deletions
@@ -0,0 +1,463 @@
import SnapKit
import UIKit
/// 准备页顶部订单额度摘要,成功次数与剩余次数分别展示。
@MainActor
final class DronePreparationOrderCell: UICollectionViewCell {
private let customerLabel = DroneDockStyle.label(size: 18, weight: .semibold)
private let packageLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
private let completedLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary)
private let remainingLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
let separator = UIView()
separator.backgroundColor = DroneDockStyle.border
[customerLabel, packageLabel, completedLabel, remainingLabel, separator].forEach(contentView.addSubview)
customerLabel.adjustsFontSizeToFitWidth = true
customerLabel.minimumScaleFactor = 0.8
customerLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(18)
make.leading.equalToSuperview().offset(4)
make.trailing.lessThanOrEqualTo(separator.snp.leading).offset(-12)
}
packageLabel.snp.makeConstraints { make in
make.top.equalTo(customerLabel.snp.bottom).offset(8)
make.leading.equalTo(customerLabel)
make.bottom.equalToSuperview().inset(14)
}
separator.snp.makeConstraints { make in
make.trailing.equalToSuperview().inset(94)
make.centerY.equalToSuperview()
make.width.equalTo(1 / UIScreen.main.scale)
make.height.equalTo(54)
}
completedLabel.snp.makeConstraints { make in
make.leading.equalTo(separator.snp.trailing).offset(16)
make.top.equalTo(customerLabel)
make.trailing.lessThanOrEqualToSuperview()
}
remainingLabel.snp.makeConstraints { make in
make.leading.equalTo(completedLabel)
make.top.equalTo(completedLabel.snp.bottom).offset(3)
make.trailing.lessThanOrEqualToSuperview()
}
isAccessibilityElement = true
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 使用订单的权威计数填充摘要,不在视图层扣减额度。
func apply(order: DroneShootingOrder?) {
guard let order else {
customerLabel.text = "订单信息暂不可用"
packageLabel.text = "请返回订单列表重新进入"
completedLabel.text = "已拍摄 — 次"
remainingLabel.attributedText = remainingText("—")
accessibilityLabel = "订单信息暂不可用"
return
}
customerLabel.text = order.customerName
packageLabel.text = "含 \(order.totalShootingCount) 次拍摄"
completedLabel.text = "已拍摄 \(order.successfulShootingCount) 次"
remainingLabel.attributedText = remainingText(String(order.remainingShootingCount))
accessibilityLabel = "\(order.customerName),含\(order.totalShootingCount)次拍摄,已拍摄\(order.successfulShootingCount)次,剩余\(order.remainingShootingCount)次"
}
private func remainingText(_ value: String) -> NSAttributedString {
let text = NSMutableAttributedString(string: "剩余 ", attributes: [.font: UIFont.systemFont(ofSize: 12), .foregroundColor: DroneDockStyle.secondary])
text.append(NSAttributedString(string: value, attributes: [.font: UIFont.systemFont(ofSize: 26, weight: .medium), .foregroundColor: DroneDockStyle.primary]))
text.append(NSAttributedString(string: " 次", attributes: [.font: UIFont.systemFont(ofSize: 12), .foregroundColor: DroneDockStyle.secondary]))
return text
}
}
/// 横向点位小卡,使用原型同款本地缩略图展示演示点位。
@MainActor
final class DronePreparationPointCell: UICollectionViewCell {
private let nameLabel = DroneDockStyle.label(size: 13, weight: .semibold)
private let rangeLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
private let countLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
private let locationIcon = UIImageView(image: UIImage(systemName: "mappin.circle.fill"))
private let thumbnail = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.layer.cornerRadius = 7
contentView.layer.borderWidth = 1
contentView.layer.cornerCurve = .continuous
thumbnail.contentMode = .scaleAspectFill
thumbnail.backgroundColor = DroneDockStyle.background
thumbnail.layer.cornerRadius = 5
thumbnail.clipsToBounds = true
locationIcon.contentMode = .scaleAspectFit
[thumbnail, nameLabel, locationIcon, rangeLabel, countLabel].forEach(contentView.addSubview)
thumbnail.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(8)
make.centerY.equalToSuperview()
make.size.equalTo(48)
}
nameLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(10)
make.leading.equalTo(thumbnail.snp.trailing).offset(8)
make.trailing.equalToSuperview().inset(6)
}
locationIcon.snp.makeConstraints { make in
make.leading.equalTo(nameLabel)
make.top.equalTo(nameLabel.snp.bottom).offset(5)
make.size.equalTo(10)
}
rangeLabel.snp.makeConstraints { make in
make.leading.equalTo(locationIcon.snp.trailing).offset(3)
make.centerY.equalTo(locationIcon)
make.trailing.equalToSuperview().inset(5)
}
countLabel.snp.makeConstraints { make in
make.top.equalTo(rangeLabel.snp.bottom).offset(4)
make.leading.equalTo(nameLabel)
make.trailing.equalToSuperview().inset(5)
}
isAccessibilityElement = true
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 仅映射模型提供的范围和次数,已拍摄的点位仍保持可选择。
func apply(point: DroneShootingPoint, selected: Bool) {
nameLabel.text = point.name
thumbnail.image = UIImage(named: point.id == "point-jinque" ? "drone_demo_pagoda" : "drone_demo_mountain")
rangeLabel.text = point.range.title
switch point.range {
case .inside: rangeLabel.textColor = DroneDockStyle.success
case .outside: rangeLabel.textColor = DroneDockStyle.secondary
case .unknown: rangeLabel.textColor = DroneDockStyle.warning
}
locationIcon.tintColor = rangeLabel.textColor
countLabel.text = point.successfulCountText
contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.07) : .white
contentView.layer.borderColor = (selected ? DroneDockStyle.primary : DroneDockStyle.border).cgColor
accessibilityLabel = "\(point.name),\(point.range.title),\(point.successfulCountText)"
accessibilityTraits = selected ? [.button, .selected] : .button
accessibilityIdentifier = "drone.preparation.point.\(point.id)"
}
}
/// 纵向单选航线行,点击整行后由 ViewModel 保留有效选择。
@MainActor
final class DronePreparationRouteCell: UICollectionViewCell {
private let nameLabel = DroneDockStyle.label(size: 16, weight: .semibold)
private let routeIcon = DronePreparationRouteIconView()
private let checkmark = UIImageView()
private let separator = UIView()
override init(frame: CGRect) {
super.init(frame: frame)
contentView.layer.cornerRadius = 8
contentView.layer.cornerCurve = .continuous
checkmark.contentMode = .scaleAspectFit
separator.backgroundColor = DroneDockStyle.border
[routeIcon, nameLabel, 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
make.leading.equalTo(routeIcon.snp.trailing).offset(14)
make.centerY.equalToSuperview()
make.trailing.lessThanOrEqualTo(checkmark.snp.leading).offset(-12)
}
checkmark.snp.makeConstraints { make in
make.trailing.equalToSuperview().inset(14)
make.centerY.equalToSuperview()
make.size.equalTo(24)
}
separator.snp.makeConstraints { make in
make.leading.trailing.bottom.equalToSuperview()
make.height.equalTo(1 / UIScreen.main.scale)
}
isAccessibilityElement = true
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 选中样式仅反映现有选择,重复点击不会在视图中取消单选。
func apply(route: DroneShootingRoute, selected: Bool) {
nameLabel.text = route.name
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
accessibilityTraits = selected ? [.button, .selected] : .button
accessibilityIdentifier = "drone.preparation.route.\(route.id)"
}
}
/// 源码绘制的小航线图标,不依赖远程图片和拍摄素材。
@MainActor
final class DronePreparationRouteIconView: UIView {
private var lineColor = DroneDockStyle.secondary
override init(frame: CGRect) {
super.init(frame: frame)
layer.cornerRadius = 10
backgroundColor = UIColor(hex: 0xF0F2F6)
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 图标跟随航线选中态使用统一主色。
func apply(selected: Bool) {
lineColor = selected ? DroneDockStyle.primary : UIColor(hex: 0x697487)
backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.07) : UIColor(hex: 0xF0F2F6)
setNeedsDisplay()
}
override func draw(_ rect: CGRect) {
let scale = min(rect.width, rect.height) / 40
guard let context = UIGraphicsGetCurrentContext() else { return }
context.saveGState()
context.scaleBy(x: scale, y: scale)
lineColor.setStroke()
let path = UIBezierPath()
path.move(to: CGPoint(x: 22, y: 11))
path.addLine(to: CGPoint(x: 16, y: 11))
path.addCurve(to: CGPoint(x: 16, y: 20), controlPoint1: CGPoint(x: 8, y: 11), controlPoint2: CGPoint(x: 8, y: 20))
path.addLine(to: CGPoint(x: 24, y: 20))
path.addCurve(to: CGPoint(x: 24, y: 29), controlPoint1: CGPoint(x: 32, y: 20), controlPoint2: CGPoint(x: 32, y: 29))
path.addLine(to: CGPoint(x: 18, y: 29))
path.lineWidth = 1.8
path.lineCapStyle = .round
path.stroke()
UIBezierPath(ovalIn: CGRect(x: 25, y: 8, width: 5, height: 5)).stroke()
UIBezierPath(ovalIn: CGRect(x: 10, y: 26, width: 5, height: 5)).stroke()
context.restoreGState()
}
}
/// 点位与航线分区标题,数量来自当前点位的实际航线配置。
@MainActor
final class DronePreparationHeadingView: UICollectionReusableView {
private let titleLabel = DroneDockStyle.label(size: 18, weight: .semibold)
private let detailLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
override init(frame: CGRect) {
super.init(frame: frame)
let stack = UIStackView(arrangedSubviews: [titleLabel, detailLabel, UIView()])
stack.axis = .horizontal
stack.alignment = .firstBaseline
stack.spacing = 12
addSubview(stack)
stack.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(4)
make.trailing.equalToSuperview()
make.centerY.equalToSuperview().offset(3)
}
titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
accessibilityTraits = .header
isAccessibilityElement = true
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 分开展示标题与较浅的航线数量。
func apply(title: String, detail: String?) {
titleLabel.text = title
detailLabel.text = detail
detailLabel.isHidden = detail == nil
accessibilityLabel = [title, detail].compactMap { $0 }.joined(separator: ",")
}
}
/// 无点位或无航线时保留就地提示,不增加额外的选择弹窗。
@MainActor
final class DronePreparationEmptyCell: UICollectionViewCell {
private let titleLabel = DroneDockStyle.label(size: 15, weight: .medium, color: UIColor(hex: 0x697487))
private let detailLabel = DroneDockStyle.label(size: 13, color: DroneDockStyle.secondary)
override init(frame: CGRect) {
super.init(frame: frame)
let icon = DronePreparationRouteIconView()
icon.backgroundColor = .clear
let stack = UIStackView(arrangedSubviews: [icon, titleLabel, detailLabel])
stack.axis = .vertical
stack.alignment = .center
stack.spacing = 14
detailLabel.numberOfLines = 0
detailLabel.textAlignment = .center
contentView.addSubview(stack)
icon.snp.makeConstraints { make in make.size.equalTo(36) }
stack.snp.makeConstraints { make in
make.centerY.equalToSuperview().offset(-8)
make.leading.trailing.equalToSuperview().inset(8)
}
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 明确区分点位未配置与已选点位没有航线。
func apply(isPointEmpty: Bool) {
titleLabel.text = isPointEmpty ? "暂无可用拍摄点" : "暂无可用航线"
detailLabel.text = isPointEmpty ? "当前景区尚未配置拍摄点" : "请选择其他拍摄点,或稍后重试"
}
}
/// 固定底部许可栏,独立刷新连接、范围、设备与主按钮。
@MainActor
final class DronePreparationFooterView: UIView {
/// 工作人员主动点击主操作时通知控制器。
var onPrimaryTap: (() -> Void)?
/// 结果待确认时由工作人员主动请求同步原召唤状态。
var onRefreshTap: (() -> Void)?
private let connectionLabel = DronePreparationIndicatorView()
private let rangeLabel = DronePreparationIndicatorView()
private let selectionLabel = DroneDockStyle.label(size: 13, weight: .semibold)
private let deviceCaption = DroneDockStyle.label("无人机:", size: 11, color: DroneDockStyle.secondary)
private let deviceLabel = DroneDockStatusLabel()
private let primaryButton = UIButton(type: .system)
private let messageLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
private let refreshButton = UIButton(type: .system)
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white
let statusRow = UIStackView(arrangedSubviews: [connectionLabel, rangeLabel])
statusRow.axis = .horizontal
statusRow.distribution = .fillEqually
let divider = UIView()
divider.backgroundColor = DroneDockStyle.border
let verticalDivider = UIView()
verticalDivider.backgroundColor = DroneDockStyle.border
let deviceRow = UIStackView(arrangedSubviews: [deviceCaption, deviceLabel, UIView()])
deviceRow.axis = .horizontal
deviceRow.alignment = .center
deviceRow.spacing = 3
let summary = UIStackView(arrangedSubviews: [selectionLabel, deviceRow])
summary.axis = .vertical
summary.spacing = 7
messageLabel.textAlignment = .center
messageLabel.numberOfLines = 2
messageLabel.accessibilityIdentifier = "drone.preparation.admission"
refreshButton.setTitle("刷新状态", for: .normal)
refreshButton.setTitleColor(DroneDockStyle.primary, for: .normal)
refreshButton.titleLabel?.font = .systemFont(ofSize: 12, weight: .medium)
refreshButton.accessibilityIdentifier = "drone.preparation.refreshSummon"
refreshButton.addTarget(self, action: #selector(refreshTapped), for: .touchUpInside)
let messageRow = UIStackView(arrangedSubviews: [messageLabel, refreshButton])
messageRow.axis = .horizontal
messageRow.alignment = .center
messageRow.spacing = 6
primaryButton.layer.cornerRadius = 8
primaryButton.layer.cornerCurve = .continuous
primaryButton.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
primaryButton.titleLabel?.adjustsFontSizeToFitWidth = true
primaryButton.titleLabel?.minimumScaleFactor = 0.85
primaryButton.accessibilityIdentifier = "drone.preparation.summon"
primaryButton.addTarget(self, action: #selector(primaryTapped), for: .touchUpInside)
[statusRow, divider, summary, primaryButton, messageRow].forEach(addSubview)
statusRow.addSubview(verticalDivider)
statusRow.snp.makeConstraints { make in
make.leading.trailing.top.equalToSuperview()
make.height.equalTo(42)
}
verticalDivider.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalTo(1 / UIScreen.main.scale)
make.height.equalTo(18)
}
divider.snp.makeConstraints { make in
make.top.equalTo(statusRow.snp.bottom)
make.leading.trailing.equalToSuperview()
make.height.equalTo(1 / UIScreen.main.scale)
}
summary.snp.makeConstraints { make in
make.leading.equalToSuperview().offset(20)
make.top.equalTo(divider.snp.bottom).offset(14)
make.trailing.equalTo(primaryButton.snp.leading).offset(-10)
}
primaryButton.snp.makeConstraints { make in
make.top.equalTo(divider.snp.bottom).offset(12)
make.trailing.equalToSuperview().inset(16)
make.width.equalTo(148)
make.height.equalTo(46)
}
refreshButton.snp.makeConstraints { make in
make.width.equalTo(62).priority(999)
make.height.equalTo(26)
}
messageRow.snp.makeConstraints { make in
make.top.equalTo(summary.snp.bottom).offset(10)
make.top.greaterThanOrEqualTo(primaryButton.snp.bottom).offset(9)
make.leading.trailing.equalToSuperview().inset(16)
make.bottom.equalTo(safeAreaLayoutGuide.snp.bottom).inset(10)
}
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 只绑定 ViewModel 已计算的展示内容和许可,不按电量或连接自行判定可召唤。
func apply(viewModel: DroneShootingPreparationViewModel) {
connectionLabel.apply(title: viewModel.connectionTitle, tone: viewModel.connectionTone)
rangeLabel.apply(title: viewModel.rangeTitle, tone: viewModel.rangeTone)
selectionLabel.text = viewModel.selectionSummary
deviceLabel.apply(title: viewModel.deviceStatusText, tone: viewModel.deviceState.tone)
primaryButton.setTitle(viewModel.primaryButtonTitle, for: .normal)
primaryButton.isEnabled = viewModel.primaryButtonEnabled
primaryButton.backgroundColor = viewModel.primaryButtonEnabled ? DroneDockStyle.primary : UIColor(hex: 0xE1E7F0)
primaryButton.setTitleColor(.white, for: .normal)
primaryButton.setTitleColor(UIColor(hex: 0x8792A5), for: .disabled)
messageLabel.text = viewModel.admission.message
messageLabel.textColor = DroneDockStyle.color(for: viewModel.admission.tone)
refreshButton.isHidden = !viewModel.shouldShowSummonRefresh
}
@objc private func primaryTapped() { onPrimaryTap?() }
@objc private func refreshTapped() { onRefreshTap?() }
}
/// 连接与范围共用的小型状态图标,图标只映射语义色。
@MainActor
private final class DronePreparationIndicatorView: UIView {
private let icon = UIImageView()
private let label = DroneDockStyle.label(size: 13)
override init(frame: CGRect) {
super.init(frame: frame)
let stack = UIStackView(arrangedSubviews: [icon, label])
stack.axis = .horizontal
stack.alignment = .center
stack.spacing = 6
icon.contentMode = .scaleAspectFit
addSubview(stack)
icon.snp.makeConstraints { make in make.size.equalTo(16) }
stack.snp.makeConstraints { make in
make.center.equalToSuperview()
make.leading.greaterThanOrEqualToSuperview().offset(5)
make.trailing.lessThanOrEqualToSuperview().inset(5)
}
isAccessibilityElement = true
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 绿色为已满足状态,其他语义色保留各自的提示。
func apply(title: String, tone: DroneDockStatusTone) {
label.text = title
label.textColor = tone == .green ? DroneDockStyle.text : DroneDockStyle.color(for: tone)
icon.tintColor = DroneDockStyle.color(for: tone)
icon.image = UIImage(systemName: tone == .green ? "checkmark.circle.fill" : "exclamationmark.circle.fill")
accessibilityLabel = title
}
}