feat: 完善机巢任务状态展示与景区空境库入口
拍摄任务刷新时保留上次成功数据,失败状态按产品网页展示原因和不可召唤提示;新增受权限控制的景区空境库入口,使用当前景区空态。同步测试与接口说明。 验证:模拟器机巢相关 65 项测试、空境库及首页菜单相关 30 项测试通过。
This commit is contained in:
@@ -172,13 +172,14 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
let telemetry = viewModel.telemetry
|
||||
telemetryView.apply(values: [telemetry.batteryText, telemetry.temperatureText, telemetry.windText,
|
||||
telemetry.rainText, telemetry.signalText, telemetry.satelliteText],
|
||||
isStale: loading || viewModel.isTelemetryStale, accessibilityPrefix: "drone.task.remote.metric")
|
||||
let value = loading ? DroneDockTaskPresentation(
|
||||
isStale: viewModel.isTelemetryStale, accessibilityPrefix: "drone.task.remote.metric")
|
||||
let value = loading && viewModel.response == nil ? DroneDockTaskPresentation(
|
||||
phase: .loading, title: "正在获取任务状态", message: "正在读取当前拍摄任务",
|
||||
deviceStatus: "—", action: .none, actionTitle: nil, isActionEnabled: false) : viewModel.presentation
|
||||
statusView.apply(value)
|
||||
statusView.apply(value, isRefreshing: loading)
|
||||
statusView.isUserInteractionEnabled = isPageVisible && isApplicationActive && !loading
|
||||
navigationItem.rightBarButtonItem?.isEnabled = isPageVisible && isApplicationActive && !loading
|
||||
navigationItem.rightBarButtonItem?.accessibilityValue = loading ? "正在刷新" : nil
|
||||
}
|
||||
|
||||
private func primaryActionTriggered() {
|
||||
@@ -191,7 +192,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
case .materials:
|
||||
guard let navigationController, navigationController.topViewController === self else { return }
|
||||
navigationController.pushViewController(materialsControllerFactory(viewModel.order, viewModel.context), animated: true)
|
||||
case .start, .resume, .none:
|
||||
case .start, .resume, .retry, .none:
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -199,7 +200,10 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
private func showStatusDetails() {
|
||||
guard isPageVisible, isApplicationActive, presentedViewController == nil else { return }
|
||||
let state = viewModel.presentation
|
||||
let texts = [state.title, state.message, state.deviceStatus].filter { !$0.isEmpty && $0 != "—" }
|
||||
var texts = [state.title, state.message, state.deviceStatus].filter { !$0.isEmpty && $0 != "—" }
|
||||
if viewModel.response != nil, let error = viewModel.errorMessage {
|
||||
texts.append("刷新失败,当前显示上次数据:\(error)")
|
||||
}
|
||||
var distinct: [String] = []
|
||||
for text in texts where !distinct.contains(text) { distinct.append(text) }
|
||||
let alert = UIAlertController(title: "任务状态详情", message: distinct.joined(separator: "\n\n"), preferredStyle: .alert)
|
||||
@@ -222,6 +226,9 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
self.refreshTask = nil
|
||||
self.isRequesting = false
|
||||
self.applySnapshot()
|
||||
if self.viewModel.response != nil, let error = self.viewModel.errorMessage {
|
||||
self.showToast("刷新失败,当前显示上次数据:\(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +237,7 @@ final class DroneDockShootingTaskViewController: BaseViewController {
|
||||
refreshTask?.cancel()
|
||||
refreshTask = nil
|
||||
isRequesting = false
|
||||
viewModel.invalidate()
|
||||
viewModel.invalidate(preservingSnapshot: true)
|
||||
applySnapshot()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 对齐体验网页的任务失败组合:警示、原因、排查提示、重召占位及设备提示。
|
||||
@MainActor
|
||||
final class DroneDockTaskFailureView: UIView {
|
||||
/// 点击原因区域查看完整后端说明,页面无需额外占用一个详情按钮。
|
||||
var onDetails: (() -> Void)?
|
||||
/// 内部排版参考比例,不对视图或点击区域使用整体缩放。
|
||||
private(set) var effectiveScale: CGFloat = 1
|
||||
/// 当前是否使用适配固定小高度的紧凑排版。
|
||||
private(set) var usesCompactLayout = false
|
||||
|
||||
private let content = UIStackView()
|
||||
private let notice = UIButton(type: .custom)
|
||||
private let iconBackground = UIView()
|
||||
private let icon = UIImageView(image: UIImage(systemName: "exclamationmark.circle.fill"))
|
||||
private let body = UIStackView()
|
||||
private let titleLabel = DroneDockStyle.label(size: 23, weight: .semibold)
|
||||
private let reasonContainer = UIView()
|
||||
private let reasonLabel = DroneDockStyle.label(size: 14, color: UIColor(hex: 0xF53242))
|
||||
private let adviceLabel = DroneDockStyle.label("请排查错误后再次召唤无人机。", size: 14, color: UIColor(hex: 0x6A79A0))
|
||||
private let retryButton = UIButton(type: .system)
|
||||
private let noteLabel = DroneDockStyle.label(size: 12, color: UIColor(hex: 0x7E8BA9))
|
||||
private var presentation: DroneDockTaskPresentation?
|
||||
private var contentTop: Constraint?
|
||||
private var noticeHeight: Constraint?
|
||||
private var iconSize: Constraint?
|
||||
private var bodyLeading: Constraint?
|
||||
private var titleHeight: Constraint?
|
||||
private var reasonHeight: Constraint?
|
||||
private var adviceHeight: Constraint?
|
||||
private var buttonHeight: Constraint?
|
||||
private var noteHeight: Constraint?
|
||||
|
||||
/// 建立失败态专用层级,外部任务页仍决定该区域尺寸。
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
setupConstraints()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
/// 更新真实失败原因及不可重召原因,不把开始拍摄许可当作重召许可。
|
||||
func apply(_ value: DroneDockTaskPresentation) {
|
||||
presentation = value
|
||||
titleLabel.text = value.title
|
||||
let reason = DroneDockHomeMetric.usableText(value.message).flatMap { $0 == "—" ? nil : $0 }
|
||||
?? "服务端暂未提供具体原因"
|
||||
reasonLabel.text = reason.hasPrefix("失败原因:") ? reason : "失败原因:\(reason)"
|
||||
noteLabel.text = value.actionNote ?? "暂不可重新召唤,请返回准备页确认设备状态"
|
||||
notice.accessibilityLabel = [value.title, reasonLabel.text, adviceLabel.text].compactMap { $0 }.joined(separator: "。")
|
||||
setNeedsLayout()
|
||||
}
|
||||
|
||||
/// 只收紧内部字号、行数和间距;主按钮保留至少 44 点高度。
|
||||
override func layoutSubviews() {
|
||||
updateLayout()
|
||||
super.layoutSubviews()
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
accessibilityIdentifier = "drone.task.remote.failure"
|
||||
content.axis = .vertical
|
||||
content.spacing = 10
|
||||
addSubview(content)
|
||||
content.addArrangedSubview(notice)
|
||||
content.addArrangedSubview(retryButton)
|
||||
content.addArrangedSubview(noteLabel)
|
||||
notice.accessibilityIdentifier = "drone.task.remote.failureDetails"
|
||||
notice.accessibilityHint = "查看完整失败原因"
|
||||
notice.addTarget(self, action: #selector(showDetails), for: .touchUpInside)
|
||||
notice.addSubview(iconBackground)
|
||||
iconBackground.backgroundColor = UIColor(hex: 0xFFEDED)
|
||||
iconBackground.isUserInteractionEnabled = false
|
||||
iconBackground.addSubview(icon)
|
||||
icon.tintColor = UIColor(hex: 0xFF303B)
|
||||
icon.contentMode = .scaleAspectFit
|
||||
body.axis = .vertical
|
||||
body.spacing = 5
|
||||
body.isUserInteractionEnabled = false
|
||||
notice.addSubview(body)
|
||||
body.addArrangedSubview(titleLabel)
|
||||
body.addArrangedSubview(reasonContainer)
|
||||
body.addArrangedSubview(adviceLabel)
|
||||
titleLabel.textColor = UIColor(hex: 0x101523)
|
||||
titleLabel.accessibilityIdentifier = "drone.task.remote.failureTitle"
|
||||
reasonContainer.backgroundColor = UIColor(hex: 0xFFF0F2)
|
||||
reasonContainer.layer.cornerRadius = 6
|
||||
reasonContainer.addSubview(reasonLabel)
|
||||
reasonLabel.accessibilityIdentifier = "drone.task.remote.failureReason"
|
||||
adviceLabel.accessibilityIdentifier = "drone.task.remote.failureAdvice"
|
||||
noteLabel.accessibilityIdentifier = "drone.task.remote.failureNote"
|
||||
noteLabel.textAlignment = .center
|
||||
[titleLabel, reasonLabel, adviceLabel, noteLabel].forEach { $0.lineBreakMode = .byTruncatingTail }
|
||||
|
||||
var configuration = UIButton.Configuration.filled()
|
||||
configuration.title = "重新召唤无人机"
|
||||
configuration.image = UIImage(systemName: "arrow.triangle.2.circlepath")
|
||||
configuration.imagePadding = 12
|
||||
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 21, weight: .regular)
|
||||
configuration.background.backgroundColor = UIColor(hex: 0xE8EBF1)
|
||||
configuration.background.cornerRadius = 8
|
||||
configuration.baseForegroundColor = UIColor(hex: 0x939CB0)
|
||||
configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8)
|
||||
retryButton.configuration = configuration
|
||||
retryButton.configurationUpdateHandler = { button in
|
||||
button.configuration?.baseForegroundColor = UIColor(hex: 0x939CB0)
|
||||
button.configuration?.background.backgroundColor = UIColor(hex: 0xE8EBF1)
|
||||
}
|
||||
retryButton.isEnabled = false
|
||||
retryButton.accessibilityIdentifier = "drone.task.remote.failureRetry"
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
content.snp.makeConstraints { make in
|
||||
contentTop = make.top.equalToSuperview().offset(16).constraint
|
||||
make.leading.trailing.equalToSuperview().inset(18)
|
||||
}
|
||||
notice.snp.makeConstraints { make in noticeHeight = make.height.equalTo(90).constraint }
|
||||
iconBackground.snp.makeConstraints { make in
|
||||
make.top.leading.equalToSuperview()
|
||||
iconSize = make.size.equalTo(41).constraint
|
||||
}
|
||||
icon.snp.makeConstraints { make in make.center.equalToSuperview(); make.size.equalToSuperview().multipliedBy(24.0 / 41.0) }
|
||||
body.snp.makeConstraints { make in
|
||||
make.top.trailing.equalToSuperview()
|
||||
bodyLeading = make.leading.equalToSuperview().offset(53).constraint
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in titleHeight = make.height.equalTo(30).constraint }
|
||||
reasonLabel.snp.makeConstraints { make in make.leading.trailing.equalToSuperview().inset(8); make.centerY.equalToSuperview() }
|
||||
reasonContainer.snp.makeConstraints { make in reasonHeight = make.height.equalTo(30).priority(999).constraint }
|
||||
adviceLabel.snp.makeConstraints { make in adviceHeight = make.height.equalTo(22).priority(999).constraint }
|
||||
retryButton.snp.makeConstraints { make in buttonHeight = make.height.equalTo(50).constraint }
|
||||
noteLabel.snp.makeConstraints { make in noteHeight = make.height.equalTo(18).constraint }
|
||||
}
|
||||
|
||||
private func updateLayout() {
|
||||
guard let presentation, bounds.width > 0, bounds.height > 0 else { return }
|
||||
let width = max(1, bounds.width - 36)
|
||||
let naturalReason = textHeight(reasonLabel.text, font: .systemFont(ofSize: 14), width: width - 53 - 16, lines: 3) + 10
|
||||
let naturalHeight: CGFloat = 30 + naturalReason + 22 + 10 + 50 + 18 + 14 + 32
|
||||
effectiveScale = min(1, max(0.8, bounds.height / naturalHeight))
|
||||
usesCompactLayout = bounds.height < 190
|
||||
let compact = usesCompactLayout
|
||||
let extreme = bounds.height < 120
|
||||
let scale = compact ? 0.8 : effectiveScale
|
||||
let top: CGFloat = compact ? 6 : 16 * scale
|
||||
let gap: CGFloat = compact ? 3 : 5 * scale
|
||||
let diameter: CGFloat = compact ? 32 : 41 * scale
|
||||
let iconGap: CGFloat = compact ? 8 : 12 * scale
|
||||
let textWidth = max(1, width - diameter - iconGap)
|
||||
titleLabel.font = .systemFont(ofSize: compact ? 20 : max(20, 23 * scale), weight: .semibold)
|
||||
reasonLabel.font = .systemFont(ofSize: max(12, 14 * scale))
|
||||
adviceLabel.font = .systemFont(ofSize: max(12, 14 * scale))
|
||||
titleLabel.numberOfLines = 1
|
||||
reasonLabel.numberOfLines = compact ? 1 : 3
|
||||
adviceLabel.numberOfLines = 1
|
||||
noteLabel.numberOfLines = 1
|
||||
adviceLabel.isHidden = extreme
|
||||
let title = textHeight(presentation.title, font: titleLabel.font, width: textWidth, lines: 1)
|
||||
let reasonPadding: CGFloat = compact ? 6 : 10 * scale
|
||||
var reason = textHeight(reasonLabel.text, font: reasonLabel.font, width: textWidth - 16,
|
||||
lines: reasonLabel.numberOfLines) + reasonPadding
|
||||
let advice = extreme ? 0 : textHeight(adviceLabel.text, font: adviceLabel.font, width: textWidth, lines: 1)
|
||||
let note = textHeight(noteLabel.text, font: noteLabel.font, width: width, lines: 1)
|
||||
let actionHeight: CGFloat = compact ? 44 : max(44, 50 * scale)
|
||||
let actionGap: CGFloat = compact ? 5 : 10 * scale
|
||||
let noteGap: CGFloat = compact ? 3 : 4
|
||||
var bodyHeight: CGFloat { title + reason + advice + gap * (extreme ? 1 : 2) }
|
||||
// 长原因先限制可见行数,完整文本仍可点开;不挤压固定页脚或按钮。
|
||||
while top * 2 + max(44, bodyHeight) + actionGap + actionHeight + noteGap + note > bounds.height,
|
||||
reasonLabel.numberOfLines > 1 {
|
||||
reasonLabel.numberOfLines -= 1
|
||||
reason = textHeight(reasonLabel.text, font: reasonLabel.font, width: textWidth - 16,
|
||||
lines: reasonLabel.numberOfLines) + reasonPadding
|
||||
}
|
||||
contentTop?.update(offset: top)
|
||||
noticeHeight?.update(offset: max(44, bodyHeight))
|
||||
iconSize?.update(offset: diameter)
|
||||
iconBackground.layer.cornerRadius = diameter / 2
|
||||
bodyLeading?.update(offset: diameter + iconGap)
|
||||
titleHeight?.update(offset: title)
|
||||
reasonHeight?.update(offset: reason)
|
||||
adviceHeight?.update(offset: max(1, advice))
|
||||
buttonHeight?.update(offset: actionHeight)
|
||||
noteHeight?.update(offset: note)
|
||||
body.spacing = gap
|
||||
content.setCustomSpacing(actionGap, after: notice)
|
||||
content.setCustomSpacing(noteGap, after: retryButton)
|
||||
retryButton.configuration?.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
||||
var result = attributes
|
||||
result.font = .systemFont(ofSize: compact ? 16 : max(16, 18 * scale), weight: .semibold)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
private func textHeight(_ text: String?, font: UIFont, width: CGFloat, lines: Int) -> CGFloat {
|
||||
let height = ((text ?? "") as NSString).boundingRect(
|
||||
with: CGSize(width: max(1, width), height: .greatestFiniteMagnitude),
|
||||
options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.font: font], context: nil).height
|
||||
return ceil(min(max(font.lineHeight, height), font.lineHeight * CGFloat(lines)))
|
||||
}
|
||||
|
||||
@objc private func showDetails() { onDetails?() }
|
||||
}
|
||||
@@ -22,6 +22,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
private let actionRow = UIView()
|
||||
private let primaryButton = UIButton(type: .system)
|
||||
private let detailsButton = UIButton(type: .system)
|
||||
private let failureView = DroneDockTaskFailureView()
|
||||
private var presentation: DroneDockTaskPresentation?
|
||||
private var contentTop: Constraint?
|
||||
private var contentLeading: Constraint?
|
||||
@@ -47,9 +48,17 @@ final class DroneDockTaskStatusView: UIView {
|
||||
CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
|
||||
}
|
||||
|
||||
/// 更新真实状态文案与动作许可,不补造百分比或自行推导飞行阶段。
|
||||
func apply(_ presentation: DroneDockTaskPresentation) {
|
||||
/// 更新真实状态与动作许可;刷新期间保留内容,只暂时禁用主操作。
|
||||
func apply(_ presentation: DroneDockTaskPresentation, isRefreshing: Bool = false) {
|
||||
self.presentation = presentation
|
||||
let isFailure = presentation.phase == .failed
|
||||
contentStack.isHidden = isFailure
|
||||
failureView.isHidden = !isFailure
|
||||
if isFailure {
|
||||
failureView.apply(presentation)
|
||||
setNeedsLayout()
|
||||
return
|
||||
}
|
||||
titleLabel.text = presentation.title
|
||||
messageLabel.text = presentation.message
|
||||
deviceLabel.text = presentation.deviceStatus
|
||||
@@ -59,7 +68,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
let actionTitle = DroneDockHomeMetric.usableText(presentation.actionTitle)
|
||||
primaryButton.isHidden = presentation.action == .none || actionTitle == nil
|
||||
primaryButton.setTitle(actionTitle, for: .normal)
|
||||
primaryButton.isEnabled = presentation.isActionEnabled && !primaryButton.isHidden
|
||||
primaryButton.isEnabled = presentation.isActionEnabled && !primaryButton.isHidden && !isRefreshing
|
||||
primaryButton.backgroundColor = primaryButton.isEnabled
|
||||
? DroneDockStyle.primary : DroneDockStyle.primary.withAlphaComponent(0.35)
|
||||
primaryButton.accessibilityIdentifier = presentation.action == .refresh
|
||||
@@ -69,12 +78,22 @@ final class DroneDockTaskStatusView: UIView {
|
||||
|
||||
/// 尺寸改变时仅重排内部内容,保留至少 44 点操作区域,不使用 transform 缩放。
|
||||
override func layoutSubviews() {
|
||||
if presentation?.phase == .failed {
|
||||
super.layoutSubviews()
|
||||
failureView.layoutIfNeeded()
|
||||
effectiveScale = failureView.effectiveScale
|
||||
usesCompactLayout = failureView.usesCompactLayout
|
||||
return
|
||||
}
|
||||
updateContentLayout()
|
||||
super.layoutSubviews()
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
backgroundColor = .white
|
||||
addSubview(failureView)
|
||||
failureView.isHidden = true
|
||||
failureView.onDetails = { [weak self] in self?.onDetails?() }
|
||||
contentStack.axis = .vertical
|
||||
contentStack.alignment = .fill
|
||||
contentStack.spacing = 10
|
||||
@@ -115,6 +134,7 @@ final class DroneDockTaskStatusView: UIView {
|
||||
}
|
||||
|
||||
private func setupConstraints() {
|
||||
failureView.snp.makeConstraints { make in make.edges.equalToSuperview() }
|
||||
contentStack.snp.makeConstraints { make in
|
||||
contentTop = make.top.equalToSuperview().offset(12).constraint
|
||||
contentLeading = make.leading.equalToSuperview().offset(16).constraint
|
||||
|
||||
@@ -4,7 +4,7 @@ import UIKit
|
||||
/// 空镜库独立调试入口,不伪造正式首页权限,也不创建机巢工作台或订单。
|
||||
@MainActor
|
||||
enum ScenicMaterialsPreview {
|
||||
/// 指定启动参数时展示独立素材库;正式首页入口等待实际权限 URI 配置。
|
||||
/// 指定启动参数时展示演示素材;正式首页由 sceniclibrary 权限控制入口。
|
||||
static func navigationController(arguments: [String]) -> UINavigationController? {
|
||||
guard arguments.contains("--scenic-materials-preview") else { return nil }
|
||||
let model = ScenicMaterialsViewModel()
|
||||
|
||||
@@ -37,7 +37,7 @@ final class ScenicMaterialsViewController: BaseViewController {
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
||||
|
||||
override func setupNavigationBar() {
|
||||
title = "景区素材"
|
||||
title = "景区空境库"
|
||||
navigationItem.backButtonDisplayMode = .minimal
|
||||
let appearance = UINavigationBarAppearance()
|
||||
appearance.configureWithOpaqueBackground()
|
||||
|
||||
Reference in New Issue
Block a user