feat(drone-dock): 展示首页真实拍摄订单

This commit is contained in:
2026-10-27 17:58:30 +08:00
parent 2db4ad8e69
commit f7a2a19dee
6 changed files with 552 additions and 42 deletions
@@ -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)