feat(drone-dock): 展示首页真实拍摄订单
This commit is contained in:
@@ -10,6 +10,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
|
||||
private let customerLabel = DroneDockStyle.label(size: 16, weight: .bold)
|
||||
private let statusLabel = DroneDockStatusLabel()
|
||||
private let orderNumberLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||||
private let packageLabel = DroneDockStyle.label(size: 13, color: UIColor(hex: 0x666E7C))
|
||||
private let countsLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary)
|
||||
private let actionButton = UIButton(type: .system)
|
||||
@@ -29,19 +30,54 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
/// 应用数据,不展示具体点位或航线,也不在卡片自行扣次。
|
||||
func apply(order: DroneShootingOrder) {
|
||||
customerLabel.text = order.customerName
|
||||
orderNumberLabel.isHidden = true
|
||||
statusLabel.apply(title: order.statusTitle, tone: order.statusTone)
|
||||
packageLabel.text = order.packageSummary
|
||||
packageLabel.numberOfLines = 1
|
||||
countsLabel.numberOfLines = 1
|
||||
actionButton.titleLabel?.numberOfLines = 1
|
||||
countsLabel.text = "已拍摄 \(order.successfulShootingCount)/\(order.totalShootingCount) 次 · 剩余 \(order.remainingShootingCount) 次"
|
||||
actionButton.setTitle(order.primaryAction.title, for: .normal)
|
||||
actionButton.isHidden = false
|
||||
actionButton.isEnabled = order.primaryActionEnabled
|
||||
actionButton.backgroundColor = DroneDockStyle.primary
|
||||
actionButton.accessibilityIdentifier = "drone.home.\(order.id).primary"
|
||||
footer.isHidden = !order.hasMaterials
|
||||
applyMaterial(title: order.materialState.title, symbol: order.materialState.systemImageName,
|
||||
tone: order.materialState.tone)
|
||||
accessibilityIdentifier = "drone.home.\(order.id)"
|
||||
}
|
||||
|
||||
/// 展示 home 的真实订单快照,缺失字段保持未知,按钮只向页面报告点击。
|
||||
func apply(homeOrder order: DroneDockHomeOrder) {
|
||||
customerLabel.text = order.touristTitle
|
||||
orderNumberLabel.isHidden = false
|
||||
orderNumberLabel.text = "订单号 \(order.orderNumberText)"
|
||||
statusLabel.apply(title: order.statusTitle, tone: order.statusTitle == "待拍摄" ? .blue : .gray)
|
||||
packageLabel.text = order.packageTitle
|
||||
packageLabel.numberOfLines = 0
|
||||
countsLabel.numberOfLines = 0
|
||||
actionButton.titleLabel?.numberOfLines = 2
|
||||
countsLabel.text = order.progressTitle
|
||||
actionButton.setTitle(order.actionTitle, for: .normal)
|
||||
actionButton.isHidden = order.actionTitle == nil
|
||||
actionButton.isEnabled = order.actionTitle != nil && order.primaryAction != "blocked"
|
||||
actionButton.backgroundColor = actionButton.isEnabled ? DroneDockStyle.primary : DroneDockStyle.secondary
|
||||
actionButton.accessibilityIdentifier = "drone.home.order.\(order.orderID).primary"
|
||||
let materialTitle = order.mediaStatusTitle ?? ""
|
||||
let materialStatus = order.mediaStatus?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||
footer.isHidden = materialStatus.isEmpty || materialStatus == "none" || materialTitle.isEmpty
|
||||
applyMaterial(title: materialTitle, symbol: "photo.on.rectangle.angled", tone: .gray)
|
||||
accessibilityIdentifier = "drone.home.order.\(order.orderID)"
|
||||
}
|
||||
|
||||
private func applyMaterial(title: String, symbol: String, tone: DroneDockStatusTone) {
|
||||
var configuration = UIButton.Configuration.plain()
|
||||
configuration.image = UIImage(systemName: order.materialState.systemImageName)
|
||||
configuration.image = UIImage(systemName: symbol)
|
||||
configuration.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 15)
|
||||
configuration.imagePadding = 6
|
||||
configuration.title = order.materialState.title
|
||||
configuration.baseForegroundColor = DroneDockStyle.color(for: order.materialState.tone)
|
||||
configuration.title = title
|
||||
configuration.baseForegroundColor = DroneDockStyle.color(for: tone)
|
||||
configuration.contentInsets = .zero
|
||||
configuration.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { attributes in
|
||||
var attributes = attributes
|
||||
@@ -49,8 +85,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
return attributes
|
||||
}
|
||||
materialButton.configuration = configuration
|
||||
materialButton.accessibilityLabel = "查看素材,\(order.materialState.title)"
|
||||
accessibilityIdentifier = "drone.home.\(order.id)"
|
||||
materialButton.accessibilityLabel = "查看素材,\(title)"
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
@@ -66,6 +101,8 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
let titleRow = UIStackView(arrangedSubviews: [customerLabel, statusLabel])
|
||||
titleRow.alignment = .center
|
||||
titleRow.spacing = 8
|
||||
orderNumberLabel.isHidden = true
|
||||
orderNumberLabel.numberOfLines = 0
|
||||
let labels = UIStackView(arrangedSubviews: [packageLabel, countsLabel])
|
||||
labels.axis = .vertical
|
||||
labels.spacing = 9
|
||||
@@ -78,12 +115,18 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
actionButton.titleLabel?.font = .systemFont(ofSize: 13, weight: .medium)
|
||||
actionButton.titleLabel?.adjustsFontSizeToFitWidth = true
|
||||
actionButton.titleLabel?.minimumScaleFactor = 0.8
|
||||
actionButton.titleLabel?.textAlignment = .center
|
||||
actionButton.layer.cornerRadius = 8
|
||||
actionButton.addTarget(self, action: #selector(shootingTapped), for: .touchUpInside)
|
||||
actionButton.snp.makeConstraints { make in make.width.equalTo(106); make.height.equalTo(42) }
|
||||
actionButton.snp.makeConstraints { make in
|
||||
make.width.equalTo(106).priority(999)
|
||||
make.height.equalTo(42)
|
||||
}
|
||||
let body = UIStackView(arrangedSubviews: [labels, actionButton])
|
||||
body.spacing = 10
|
||||
body.alignment = .center
|
||||
// 让内容行紧贴文字;按钮的固有高度仍可撑高整行,避免自适应高度的舍入余量在两行间游移。
|
||||
body.snp.makeConstraints { make in make.height.equalTo(labels).priority(249) }
|
||||
|
||||
let divider = UIView()
|
||||
divider.backgroundColor = DroneDockStyle.border
|
||||
@@ -106,7 +149,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
make.trailing.lessThanOrEqualTo(viewButton.snp.leading).offset(-8)
|
||||
}
|
||||
viewButton.snp.makeConstraints { make in make.centerY.equalTo(materialButton); make.trailing.equalToSuperview() }
|
||||
let stack = UIStackView(arrangedSubviews: [titleRow, body, footer])
|
||||
let stack = UIStackView(arrangedSubviews: [titleRow, orderNumberLabel, body, footer])
|
||||
stack.axis = .vertical
|
||||
stack.spacing = 12
|
||||
contentView.addSubview(stack)
|
||||
|
||||
@@ -11,10 +11,10 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
private var devicePage = 0
|
||||
private let pageControl = UIPageControl()
|
||||
|
||||
/// 首页固定分区;设备与订单的数据结构以实际联调结果为准。
|
||||
/// 首页按当前身份、设备、订单与统计展示服务端快照。
|
||||
private enum Section: Int, CaseIterable { case context, devices, orders, statistics }
|
||||
/// 稳定身份确保刷新使用 Diffable 更新。
|
||||
private enum Item: Hashable { case context, devices, device(Int), orders, statistics }
|
||||
private enum Item: Hashable { case context, devices, device(Int), orders, order(Int), statistics }
|
||||
private lazy var collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeLayout())
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
|
||||
|
||||
@@ -56,6 +56,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
collectionView.accessibilityIdentifier = "drone.home.remote.list"
|
||||
collectionView.register(DroneDockHomeContentCell.self, forCellWithReuseIdentifier: "content")
|
||||
collectionView.register(DroneDockDeviceCell.self, forCellWithReuseIdentifier: "device")
|
||||
collectionView.register(DroneDockCompactOrderCell.self, forCellWithReuseIdentifier: "order")
|
||||
collectionView.register(DroneDockHomeHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
|
||||
withReuseIdentifier: "header")
|
||||
collectionView.register(DroneDockHomePageFooter.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter,
|
||||
@@ -97,12 +98,17 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
isRefreshing = true
|
||||
refreshTask = Task { @MainActor [weak self] in
|
||||
guard let self else { return }
|
||||
let isInitialLoad = self.viewModel.response == nil
|
||||
self.applySnapshot(animated: false)
|
||||
await self.viewModel.refresh()
|
||||
guard !Task.isCancelled else { return }
|
||||
self.isRefreshing = false
|
||||
self.collectionView.refreshControl?.endRefreshing()
|
||||
self.applySnapshot(animated: true) { [weak self] in
|
||||
if isInitialLoad, let self {
|
||||
self.collectionView.layoutIfNeeded()
|
||||
self.collectionView.setContentOffset(CGPoint(x: 0, y: -self.collectionView.adjustedContentInset.top), animated: false)
|
||||
}
|
||||
#if DEBUG
|
||||
Task { @MainActor [weak self] in await self?.captureHomeIfRequested() }
|
||||
#endif
|
||||
@@ -120,6 +126,17 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
}
|
||||
return cell
|
||||
}
|
||||
if case .order(let id) = item {
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "order", for: path) as! DroneDockCompactOrderCell
|
||||
if let order = self.viewModel.response?.orders.first(where: { $0.orderID == id }) {
|
||||
cell.apply(homeOrder: order)
|
||||
cell.onShootingTap = { [weak self] in
|
||||
self?.showAlert(title: order.actionTitle ?? "拍摄订单", message: "拍摄流程暂未接入,请稍后再试")
|
||||
}
|
||||
cell.onMaterialsTap = { [weak self] in self?.showUnavailable("订单素材") }
|
||||
}
|
||||
return cell
|
||||
}
|
||||
let cell = collection.dequeueReusableCell(withReuseIdentifier: "content", for: path) as! DroneDockHomeContentCell
|
||||
switch item {
|
||||
case .context:
|
||||
@@ -130,7 +147,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
cell.applyStatistics(self.viewModel.response?.today)
|
||||
case .devices, .orders:
|
||||
self.applyDataState(to: cell, isDevice: item == .devices)
|
||||
case .device: break
|
||||
case .device, .order: break
|
||||
}
|
||||
return cell
|
||||
}
|
||||
@@ -158,20 +175,13 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
cell.applyMessage(symbol: "wifi.exclamationmark", title: "首页加载失败", detail: error + ",请下拉重试")
|
||||
return
|
||||
}
|
||||
guard let response = viewModel.response else {
|
||||
guard viewModel.response != nil else {
|
||||
cell.applyMessage(symbol: "arrow.triangle.2.circlepath", title: "正在加载", detail: "正在获取最新数据")
|
||||
return
|
||||
}
|
||||
let recordCount = isDevice ? response.airports.count : response.orders.count
|
||||
if recordCount == 0 {
|
||||
cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text",
|
||||
title: isDevice ? "暂无无人机" : "暂无待拍摄订单",
|
||||
detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据")
|
||||
} else {
|
||||
// 订单仍等待真实非空样例,不影响已接入的设备卡片。
|
||||
cell.applyMessage(symbol: "exclamationmark.circle", title: "订单信息暂不可用",
|
||||
detail: "已获取 \(recordCount) 条数据,暂时无法展示详情")
|
||||
}
|
||||
cell.applyMessage(symbol: isDevice ? "airplane" : "doc.text",
|
||||
title: isDevice ? "暂无无人机" : "暂无待拍摄订单",
|
||||
detail: isDevice ? "当前景区暂无设备数据" : "当前景区暂无拍摄订单数据")
|
||||
}
|
||||
|
||||
private func applySnapshot(animated: Bool, completion: (() -> Void)? = nil) {
|
||||
@@ -181,7 +191,8 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
snapshot.appendItems([.context], toSection: .context)
|
||||
let airports = viewModel.response?.airports ?? []
|
||||
snapshot.appendItems(airports.isEmpty ? [.devices] : airports.map { .device($0.id) }, toSection: .devices)
|
||||
snapshot.appendItems([.orders], toSection: .orders)
|
||||
let orders = viewModel.response?.orders ?? []
|
||||
snapshot.appendItems(orders.isEmpty ? [.orders] : orders.map { .order($0.orderID) }, toSection: .orders)
|
||||
snapshot.appendItems([.statistics], toSection: .statistics)
|
||||
let old = Set(dataSource.snapshot().itemIdentifiers)
|
||||
let previousDeviceCount = old.filter { if case .device = $0 { return true }; return false }.count
|
||||
@@ -207,6 +218,7 @@ final class DroneDockHomeViewController: BaseViewController {
|
||||
let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: width, heightDimension: height), subitems: [item])
|
||||
let layout = NSCollectionLayoutSection(group: group)
|
||||
layout.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: section == .statistics ? 24 : 0, trailing: 16)
|
||||
if section == .orders { layout.interGroupSpacing = 12 }
|
||||
if multipleDevices {
|
||||
layout.interGroupSpacing = 12
|
||||
layout.orthogonalScrollingBehavior = .groupPaging
|
||||
|
||||
Reference in New Issue
Block a user