feat: 完善机巢任务安全控制与状态诊断

同步新版飞控与 WebSocket 回执合同,完善独立指令等待、暂停继续和返航状态;增加真机诊断并优化倒计时与素材库展示。
This commit is contained in:
2026-11-04 17:34:28 +08:00
parent 1c766ff12f
commit e3979e9e32
44 changed files with 4575 additions and 581 deletions
@@ -279,6 +279,14 @@ final class DroneShootingTaskSafetyButton: UIButton {
private let controlTitleLabel = DroneDockStyle.label(size: 15, weight: .semibold)
private let controlSubtitleLabel = DroneDockStyle.label(size: 10)
private let controlIconView: UIImageView
private let activityIndicator = UIActivityIndicatorView(style: .medium)
/// 输出实际呈现的控件状态,供页面按变化记录;不推导业务许可。
var diagnosticFields: [String: Any] {
["title": controlTitleLabel.text ?? "", "subtitle": controlSubtitleLabel.text ?? "",
"enabled": isEnabled, "loading": activityIndicator.isAnimating,
"accessibility_value": accessibilityValue ?? ""]
}
/// 创建暂停或返航按钮;返回状态只由 ViewModel 决定。
init(symbol: String, color: UIColor, filled: Bool) {
@@ -292,6 +300,9 @@ final class DroneShootingTaskSafetyButton: UIButton {
controlSubtitleLabel.textColor = filled ? UIColor.white.withAlphaComponent(0.85) : DroneDockStyle.secondary
controlIconView.tintColor = filled ? .white : color
controlIconView.contentMode = .scaleAspectFit
activityIndicator.color = filled ? .white : color
activityIndicator.hidesWhenStopped = true
activityIndicator.isUserInteractionEnabled = false
let titles = UIStackView(arrangedSubviews: [controlTitleLabel, controlSubtitleLabel])
titles.axis = .vertical
titles.spacing = 3
@@ -308,6 +319,11 @@ final class DroneShootingTaskSafetyButton: UIButton {
make.trailing.lessThanOrEqualToSuperview().offset(-9)
}
controlIconView.snp.makeConstraints { make in make.size.equalTo(27) }
addSubview(activityIndicator)
activityIndicator.snp.makeConstraints { make in
make.center.equalTo(controlIconView)
make.size.equalTo(27)
}
controlTitleLabel.adjustsFontSizeToFitWidth = true
controlTitleLabel.minimumScaleFactor = 0.8
controlSubtitleLabel.adjustsFontSizeToFitWidth = true
@@ -317,14 +333,18 @@ final class DroneShootingTaskSafetyButton: UIButton {
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 应用语义明确的按钮标题、辅助说明及防重复点击状态。
func apply(title: String, subtitle: String, enabled: Bool) {
/// 应用独立操作许可和加载状态;加载时仅替换本按钮图标,不改变布局或其他按钮。
func apply(title: String, subtitle: String, enabled: Bool, isLoading: Bool = false) {
controlTitleLabel.text = title
controlSubtitleLabel.text = subtitle
isEnabled = enabled
alpha = enabled ? 1 : 0.42
isEnabled = enabled && !isLoading
alpha = enabled || isLoading ? 1 : 0.42
controlIconView.alpha = isLoading ? 0 : 1
if isLoading { activityIndicator.startAnimating() }
else { activityIndicator.stopAnimating() }
activityIndicator.accessibilityIdentifier = accessibilityIdentifier.map { "\($0).loading" }
accessibilityLabel = title
accessibilityValue = subtitle
accessibilityValue = isLoading ? "处理中,\(subtitle)" : subtitle
}
/// 切换同一位置的暂停/继续或返航/取消图标,不改变按钮布局。