开放 Release 真实操作并保留 Debug 拦截;恢复前台 shooting 串行轮询;统一打印机巢请求与完整原值响应;优化长点位名称、未拍摄文案、报备失败及已结束任务提示,移除成功回执 UI。补充相关测试、离线策略检查和联调说明。
596 lines
29 KiB
Swift
596 lines
29 KiB
Swift
import Kingfisher
|
||
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.trailing.lessThanOrEqualTo(separator.snp.leading).offset(-12)
|
||
make.bottom.equalToSuperview().inset(14)
|
||
}
|
||
packageLabel.numberOfLines = 2
|
||
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)次"
|
||
}
|
||
|
||
/// 使用 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 = "\(tourist),\(packageLabel.text ?? ""),已拍摄\(used.map(String.init) ?? "—")次,剩余\(remaining.map(String.init) ?? "—")次"
|
||
accessibilityIdentifier = "drone.preparation.order"
|
||
}
|
||
|
||
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 countLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||
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
|
||
nameLabel.numberOfLines = 0
|
||
nameLabel.lineBreakMode = .byWordWrapping
|
||
nameLabel.accessibilityIdentifier = "drone.preparation.point.name"
|
||
let labels = UIStackView(arrangedSubviews: [nameLabel, countLabel])
|
||
labels.axis = .vertical
|
||
labels.spacing = 6
|
||
[thumbnail, labels].forEach(contentView.addSubview)
|
||
thumbnail.snp.makeConstraints { make in
|
||
make.leading.equalToSuperview().offset(8)
|
||
make.centerY.equalToSuperview()
|
||
make.size.equalTo(48)
|
||
}
|
||
labels.snp.makeConstraints { make in
|
||
make.centerY.equalToSuperview()
|
||
make.top.greaterThanOrEqualToSuperview().offset(8)
|
||
make.bottom.lessThanOrEqualToSuperview().inset(8)
|
||
make.leading.equalTo(thumbnail.snp.trailing).offset(8)
|
||
make.trailing.equalToSuperview().inset(8)
|
||
}
|
||
isAccessibilityElement = true
|
||
}
|
||
|
||
@available(*, unavailable)
|
||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||
|
||
/// 横向同组卡片采用最长名称所需的高度,名称完整换行且不压缩字号。
|
||
static func preferredHeight(names: [String], width: CGFloat) -> CGFloat {
|
||
let label = DroneDockStyle.label(size: 13, weight: .semibold)
|
||
label.numberOfLines = 0
|
||
let nameWidth = max(1, width - 72)
|
||
let nameHeight = names.map { name -> CGFloat in
|
||
label.text = name
|
||
return label.sizeThatFits(CGSize(width: nameWidth, height: .greatestFiniteMagnitude)).height
|
||
}.max() ?? 0
|
||
return max(64, ceil(nameHeight) + 6 + ceil(UIFont.systemFont(ofSize: 11).lineHeight) + 16)
|
||
}
|
||
|
||
/// 展示点位名称与次数,已拍摄的点位仍保持可选择。
|
||
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")
|
||
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.successfulCountText)"
|
||
accessibilityTraits = selected ? [.button, .selected] : .button
|
||
accessibilityIdentifier = "drone.preparation.point.\(point.id)"
|
||
}
|
||
|
||
/// 展示已购点位与可用性;无拍摄记录时显示“未拍摄”。
|
||
func apply(spot: DroneDockPurchasedSpot, selected: Bool) {
|
||
nameLabel.text = spot.name
|
||
thumbnail.kf.cancelDownloadTask()
|
||
thumbnail.image = UIImage(systemName: "photo")
|
||
thumbnail.contentMode = .center
|
||
thumbnail.tintColor = DroneDockStyle.secondary
|
||
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: "photo"))
|
||
}
|
||
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),\(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()
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
contentView.layer.cornerRadius = 8
|
||
contentView.layer.cornerCurve = .continuous
|
||
checkmark.contentMode = .scaleAspectFit
|
||
separator.backgroundColor = DroneDockStyle.border
|
||
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)
|
||
}
|
||
labels.snp.makeConstraints { make in
|
||
make.leading.equalTo(routeIcon.snp.trailing).offset(14)
|
||
make.centerY.equalToSuperview()
|
||
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)
|
||
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") }
|
||
|
||
/// 航线原因允许换行,自适应高度时保持列表提供的整行宽度。
|
||
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)
|
||
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)"
|
||
}
|
||
|
||
/// 展示当前真实点位的航线选择,不从行点击发起任何飞行操作。
|
||
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.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)"
|
||
}
|
||
}
|
||
|
||
/// 源码绘制的小航线图标,不依赖远程图片和拍摄素材。
|
||
@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
|
||
titleLabel.numberOfLines = 0
|
||
titleLabel.accessibilityIdentifier = "drone.preparation.heading.title"
|
||
addSubview(stack)
|
||
stack.snp.makeConstraints { make in
|
||
make.leading.equalToSuperview().offset(4)
|
||
make.trailing.equalToSuperview()
|
||
make.centerY.equalToSuperview().offset(3)
|
||
}
|
||
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
||
detailLabel.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: ",")
|
||
}
|
||
|
||
/// 为长点位名称预留完整标题高度,右侧航线数量保持可见。
|
||
static func preferredHeight(title: String, detail: String, width: CGFloat) -> CGFloat {
|
||
let label = DroneDockStyle.label(size: 18, weight: .semibold)
|
||
label.numberOfLines = 0
|
||
label.text = title
|
||
let detailWidth = (detail as NSString).size(withAttributes: [.font: UIFont.systemFont(ofSize: 13)]).width
|
||
let titleWidth = max(1, width - 4 - ceil(detailWidth) - 24)
|
||
return max(64, ceil(label.sizeThatFits(CGSize(width: titleWidth, height: .greatestFiniteMagnitude)).height) + 26)
|
||
}
|
||
}
|
||
|
||
/// 无点位或无航线时保留就地提示,不增加额外的选择弹窗。
|
||
@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 ? "当前景区尚未配置拍摄点" : "请选择其他拍摄点,或稍后重试"
|
||
}
|
||
|
||
/// 展示真实页面的加载、失败或未配置状态,不将请求失败描述为空数据。
|
||
func apply(title: String, detail: String) {
|
||
titleLabel.text = title
|
||
detailLabel.text = detail
|
||
}
|
||
}
|
||
|
||
/// 固定底部许可栏,独立刷新连接、设备与主按钮。
|
||
@MainActor
|
||
final class DronePreparationFooterView: UIView {
|
||
/// 工作人员主动点击主操作时通知控制器。
|
||
var onPrimaryTap: (() -> Void)?
|
||
/// 结果待确认时由工作人员主动请求同步原召唤状态。
|
||
var onRefreshTap: (() -> Void)?
|
||
|
||
private let connectionLabel = 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 divider = UIView()
|
||
divider.backgroundColor = DroneDockStyle.border
|
||
let deviceRow = UIStackView(arrangedSubviews: [deviceCaption, deviceLabel, UIView()])
|
||
deviceLabel.accessibilityIdentifier = "drone.preparation.planeStatus"
|
||
deviceLabel.numberOfLines = 2
|
||
deviceLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||
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)
|
||
[connectionLabel, divider, summary, primaryButton, messageRow].forEach(addSubview)
|
||
connectionLabel.snp.makeConstraints { make in
|
||
make.leading.trailing.top.equalToSuperview()
|
||
make.height.equalTo(42)
|
||
}
|
||
divider.snp.makeConstraints { make in
|
||
make.top.equalTo(connectionLabel.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)
|
||
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)
|
||
switch viewModel.admission {
|
||
case .outOfRange, .unknownRange:
|
||
messageLabel.text = "当前暂不可召唤,请稍后重试"
|
||
default:
|
||
messageLabel.text = viewModel.admission.message
|
||
}
|
||
messageLabel.textColor = DroneDockStyle.color(for: viewModel.admission.tone)
|
||
refreshButton.isHidden = !viewModel.shouldShowSummonRefresh
|
||
}
|
||
|
||
/// 绑定准备页提交许可;模拟来源仅影响文案,不改变业务权限或真实传输保护。
|
||
func apply(preparationViewModel viewModel: DroneDockPreparationViewModel, isRefreshing: Bool = false,
|
||
isLocalSimulation: Bool = false) {
|
||
connectionLabel.apply(title: viewModel.connectionTitle, tone: viewModel.connectionTone)
|
||
selectionLabel.text = viewModel.selectionSummary
|
||
selectionLabel.numberOfLines = 2
|
||
deviceLabel.apply(title: viewModel.deviceStatusText, tone: viewModel.deviceTone)
|
||
let title = isLocalSimulation && viewModel.canCreateTask ? "确认并召唤(模拟)" : viewModel.primaryButtonTitle
|
||
primaryButton.setTitle(title, for: .normal)
|
||
primaryButton.isEnabled = (viewModel.isPrimaryActionEnabled || viewModel.canOpenShootingTask) && !isRefreshing
|
||
primaryButton.backgroundColor = primaryButton.isEnabled ? DroneDockStyle.primary : UIColor(hex: 0xE1E7F0)
|
||
primaryButton.setTitleColor(.white, for: .normal)
|
||
primaryButton.setTitleColor(UIColor(hex: 0x8792A5), for: .disabled)
|
||
if viewModel.isTaskSelectionLocked || viewModel.taskCreationErrorMessage != nil {
|
||
messageLabel.text = viewModel.admissionMessage
|
||
} else {
|
||
messageLabel.text = viewModel.planeStatusErrorMessage.map { "无人机状态获取失败:\($0)" } ?? viewModel.admissionMessage
|
||
}
|
||
if isLocalSimulation {
|
||
messageLabel.text = "本地模拟,不会向无人机发送指令\n" + (messageLabel.text ?? "")
|
||
}
|
||
messageLabel.textColor = DroneDockStyle.secondary
|
||
refreshButton.isHidden = false
|
||
refreshButton.isEnabled = !viewModel.isLoading && !viewModel.isCreatingTask && !viewModel.isSummoning && !isRefreshing
|
||
}
|
||
|
||
@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
|
||
}
|
||
}
|