import SnapKit import UIKit /// 素材库的订单摘要,保留拍摄履约与素材处理相互独立的表达。 @MainActor final class DroneMaterialOrderCell: UICollectionViewCell { private let customerLabel = DroneDockStyle.label(size: 18, weight: .semibold) private let statusLabel = DroneDockStatusLabel() private let numberLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary) private let countLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary) override init(frame: CGRect) { super.init(frame: frame) let titleRow = UIStackView(arrangedSubviews: [customerLabel, statusLabel, UIView()]) titleRow.axis = .horizontal titleRow.alignment = .center titleRow.spacing = 9 let stack = UIStackView(arrangedSubviews: [titleRow, numberLabel, countLabel]) stack.axis = .vertical stack.spacing = 9 contentView.addSubview(stack) stack.snp.makeConstraints { make in make.leading.trailing.equalToSuperview() make.top.equalToSuperview().offset(16) make.bottom.equalToSuperview().inset(18) } 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 = "订单信息暂不可用" statusLabel.isHidden = true numberLabel.text = "请返回订单列表重新进入" countLabel.text = nil accessibilityLabel = "订单信息暂不可用,请返回订单列表重新进入" return } customerLabel.text = order.customerName statusLabel.isHidden = false statusLabel.apply(title: order.fulfillmentState.title, tone: order.fulfillmentState.tone) numberLabel.text = order.orderNumber countLabel.text = "含\(order.totalShootingCount)次拍摄 · 已拍摄\(order.successfulShootingCount)次 · 剩余\(order.remainingShootingCount)次" accessibilityLabel = [order.customerName, order.fulfillmentState.title, order.orderNumber, countLabel.text].compactMap { $0 }.joined(separator: ",") } } /// 可横向浏览的点位筛选标签,下载期间保留现有筛选并禁用交互。 @MainActor final class DroneMaterialFilterCell: UICollectionViewCell { private let titleLabel = DroneDockStyle.label(size: 13, weight: .medium) override init(frame: CGRect) { super.init(frame: frame) contentView.layer.cornerRadius = 7 contentView.layer.cornerCurve = .continuous contentView.layer.borderWidth = 1 titleLabel.textAlignment = .center contentView.addSubview(titleLabel) titleLabel.snp.makeConstraints { make in make.edges.equalToSuperview().inset(5) } isAccessibilityElement = true } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 映射筛选名称、选中态与交互许可。 func apply(title: String, id: String?, selected: Bool, locked: Bool) { titleLabel.text = title titleLabel.textColor = selected ? DroneDockStyle.primary : UIColor(hex: 0x677183) contentView.backgroundColor = selected ? DroneDockStyle.primary.withAlphaComponent(0.09) : .white contentView.layer.borderColor = (selected ? UIColor.clear : DroneDockStyle.border).cgColor contentView.alpha = locked ? 0.5 : 1 accessibilityIdentifier = "drone.materials.filter.\(id ?? "all")" accessibilityLabel = title var traits: UIAccessibilityTraits = .button if selected { traits.insert(.selected) } if locked { traits.insert(.notEnabled) } accessibilityTraits = traits } } /// 点位限定入口的只读提示,不将当前任务点位伪装成可切换筛选。 @MainActor final class DroneMaterialPointContextCell: UICollectionViewCell { private let icon = UIImageView(image: UIImage(systemName: "mappin.circle.fill")) private let titleLabel = DroneDockStyle.label(size: 14, weight: .semibold) private let detailLabel = DroneDockStyle.label("仅显示当前打卡点素材", size: 11, color: DroneDockStyle.secondary) override init(frame: CGRect) { super.init(frame: frame) icon.tintColor = DroneDockStyle.primary [icon, titleLabel, detailLabel].forEach(contentView.addSubview) icon.snp.makeConstraints { make in make.leading.centerY.equalToSuperview(); make.size.equalTo(16) } titleLabel.snp.makeConstraints { make in make.leading.equalTo(icon.snp.trailing).offset(6) make.centerY.equalToSuperview() make.trailing.lessThanOrEqualTo(detailLabel.snp.leading).offset(-8) } detailLabel.snp.makeConstraints { make in make.trailing.centerY.equalToSuperview() } isAccessibilityElement = true } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 展示限定点位的名称。 func apply(title: String) { titleLabel.text = title accessibilityLabel = "\(title),仅显示当前打卡点素材" } } /// 素材分组上方的数量与全选控制,数量由当前可见记录提供。 @MainActor final class DroneMaterialSelectionCell: UICollectionViewCell { /// 点击后由控制器调用 ViewModel 的全选操作。 var onSelectAllTap: (() -> Void)? private let countLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary) private let selectAllButton = UIButton(type: .system) override init(frame: CGRect) { super.init(frame: frame) selectAllButton.titleLabel?.font = .systemFont(ofSize: 12) selectAllButton.tintColor = DroneDockStyle.primary selectAllButton.accessibilityIdentifier = "drone.materials.selectAll" selectAllButton.addTarget(self, action: #selector(selectAllTapped), for: .touchUpInside) let divider = UIView() divider.backgroundColor = DroneDockStyle.border [countLabel, selectAllButton, divider].forEach(contentView.addSubview) countLabel.snp.makeConstraints { make in make.leading.centerY.equalToSuperview().offset(-2) } selectAllButton.snp.makeConstraints { make in make.trailing.equalToSuperview() make.centerY.equalTo(countLabel) make.leading.greaterThanOrEqualTo(countLabel.snp.trailing).offset(8) make.height.equalTo(44) } divider.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 全选只面向当前可下载项,上传中与失败素材不会计入。 func apply(recordCount: Int, allSelected: Bool, enabled: Bool) { countLabel.text = "\(recordCount)次拍摄 · 最新在前" var config = UIButton.Configuration.plain() config.title = "全选可下载" config.image = UIImage(systemName: allSelected ? "checkmark.circle.fill" : "circle") config.imagePadding = 6 config.contentInsets = .zero config.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 15) selectAllButton.configuration = config selectAllButton.isEnabled = enabled selectAllButton.accessibilityLabel = "全选可下载" selectAllButton.accessibilityTraits = allSelected ? [.button, .selected] : .button } @objc private func selectAllTapped() { onSelectAllTap?() } } /// 每条拍摄记录的点位、航线、时间与独立的交付入口。 @MainActor final class DroneMaterialRecordHeaderView: UICollectionReusableView { /// 交付入口目前只向上层请求展示占位说明。 var onDeliveryTap: (() -> Void)? private let titleLabel = DroneDockStyle.label(size: 17, weight: .semibold) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let deliveryButton = UIButton(type: .system) override init(frame: CGRect) { super.init(frame: frame) deliveryButton.titleLabel?.font = .systemFont(ofSize: 12) var config = UIButton.Configuration.plain() config.title = "交付成片" config.image = UIImage(systemName: "play.rectangle") config.imagePadding = 5 config.contentInsets = .zero config.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 13) deliveryButton.configuration = config deliveryButton.tintColor = DroneDockStyle.primary deliveryButton.addTarget(self, action: #selector(deliveryTapped), for: .touchUpInside) [titleLabel, detailLabel, deliveryButton].forEach(addSubview) titleLabel.snp.makeConstraints { make in make.leading.equalToSuperview() make.top.equalToSuperview().offset(20) make.trailing.lessThanOrEqualTo(deliveryButton.snp.leading).offset(-12) } deliveryButton.snp.makeConstraints { make in make.trailing.equalToSuperview() make.centerY.equalTo(titleLabel) make.height.equalTo(40) } detailLabel.snp.makeConstraints { make in make.leading.trailing.equalToSuperview() make.top.equalTo(titleLabel.snp.bottom).offset(9) make.bottom.lessThanOrEqualToSuperview().inset(10) } titleLabel.accessibilityTraits = .header } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 使用完整拍摄记录身份绑定交付入口,避免仅按同名点位匹配。 func apply(record: DroneMaterialRecord) { titleLabel.text = record.pointName detailLabel.text = record.summary deliveryButton.accessibilityLabel = "\(record.pointName)交付成片,记录\(record.sequenceNumber)" deliveryButton.accessibilityIdentifier = "drone.materials.delivery.\(record.id)" } @objc private func deliveryTapped() { onDeliveryTap?() } } /// 两列素材网格单元;缩略图预览与右上角多选按钮互不替代。 @MainActor final class DroneMaterialCell: UICollectionViewCell { /// 点击就绪缩略图时请求预览。 var onPreviewTap: (() -> Void)? /// 点击右上角选择控件时仅改变选择。 var onSelectionTap: (() -> Void)? private let thumbnail = UIImageView() private let previewButton = UIButton(type: .custom) private let selectionButton = UIButton(type: .custom) private let placeholderIcon = UIImageView() private let videoBadge = UILabel() private let nameLabel = DroneDockStyle.label(size: 12, weight: .medium) private let statusLabel = DroneDockStyle.label(size: 11) override init(frame: CGRect) { super.init(frame: frame) thumbnail.contentMode = .scaleAspectFill thumbnail.clipsToBounds = true thumbnail.layer.cornerRadius = 6 thumbnail.layer.cornerCurve = .continuous thumbnail.backgroundColor = UIColor(hex: 0xE9EDF5) thumbnail.layer.borderWidth = 2 placeholderIcon.contentMode = .scaleAspectFit placeholderIcon.tintColor = UIColor(hex: 0x9CA6B6) videoBadge.font = .systemFont(ofSize: 10, weight: .medium) videoBadge.textColor = .white videoBadge.backgroundColor = UIColor.black.withAlphaComponent(0.48) videoBadge.layer.cornerRadius = 3 videoBadge.clipsToBounds = true videoBadge.textAlignment = .center videoBadge.text = "视频" selectionButton.imageView?.contentMode = .scaleAspectFit selectionButton.addTarget(self, action: #selector(selectionTapped), for: .touchUpInside) previewButton.addTarget(self, action: #selector(previewTapped), for: .touchUpInside) [thumbnail, placeholderIcon, previewButton, videoBadge, selectionButton, nameLabel, statusLabel].forEach(contentView.addSubview) thumbnail.snp.makeConstraints { make in make.leading.trailing.top.equalToSuperview() make.height.equalTo(thumbnail.snp.width).multipliedBy(0.57) } previewButton.snp.makeConstraints { make in make.edges.equalTo(thumbnail) } placeholderIcon.snp.makeConstraints { make in make.center.equalTo(thumbnail); make.size.equalTo(29) } videoBadge.snp.makeConstraints { make in make.leading.equalTo(thumbnail).offset(6) make.bottom.equalTo(thumbnail).inset(6) make.width.equalTo(32) make.height.equalTo(18) } selectionButton.snp.makeConstraints { make in make.top.trailing.equalTo(thumbnail) make.size.equalTo(44) } nameLabel.snp.makeConstraints { make in make.leading.trailing.equalToSuperview() make.top.equalTo(thumbnail.snp.bottom).offset(7) } statusLabel.snp.makeConstraints { make in make.leading.trailing.equalToSuperview() make.top.equalTo(nameLabel.snp.bottom).offset(4) make.bottom.lessThanOrEqualToSuperview().inset(5) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 上传未就绪时显示占位且禁选,演示完成也不会标记为本机已保存。 func apply(material: DroneMaterial, selected: Bool, selectionEnabled: Bool, completed: Bool) { nameLabel.text = material.title statusLabel.text = material.statusTitle statusLabel.textColor = DroneDockStyle.color(for: material.statusTone) thumbnail.image = material.canPreview ? UIImage(named: material.previewAssetName) : nil thumbnail.layer.borderColor = selected ? DroneDockStyle.primary.cgColor : UIColor.clear.cgColor placeholderIcon.isHidden = material.canPreview placeholderIcon.image = UIImage(systemName: material.uploadState == .failed ? "exclamationmark.icloud" : "play.fill") videoBadge.isHidden = material.kind != .video || !material.canPreview previewButton.isEnabled = material.canPreview previewButton.accessibilityIdentifier = "drone.materials.preview.\(material.id)" previewButton.accessibilityLabel = "预览\(material.title)" selectionButton.isHidden = material.uploadState != .ready selectionButton.isEnabled = selectionEnabled && !completed selectionButton.accessibilityIdentifier = "drone.materials.select.\(material.id)" selectionButton.accessibilityLabel = completed ? "\(material.title),演示完成,未写入相册" : "选择\(material.title)" selectionButton.accessibilityTraits = selected || completed ? [.button, .selected] : .button let symbol = UIImage(systemName: selected || completed ? "checkmark.circle.fill" : "circle", withConfiguration: UIImage.SymbolConfiguration(pointSize: 22, weight: .regular)) let tint = completed ? DroneDockStyle.success : selected ? DroneDockStyle.primary : UIColor.white selectionButton.setImage(symbol?.withTintColor(tint, renderingMode: .alwaysOriginal), for: .normal) selectionButton.setImage(symbol?.withTintColor(tint.withAlphaComponent(0.6), renderingMode: .alwaysOriginal), for: .disabled) selectionButton.imageView?.layer.shadowColor = UIColor.black.cgColor selectionButton.imageView?.layer.shadowOpacity = 0.22 selectionButton.imageView?.layer.shadowRadius = 2 selectionButton.imageView?.layer.shadowOffset = .zero } @objc private func previewTapped() { onPreviewTap?() } @objc private func selectionTapped() { onSelectionTap?() } } /// 分组之间轻量的分隔线。 @MainActor final class DroneMaterialSeparatorView: UICollectionReusableView { override init(frame: CGRect) { super.init(frame: frame) let line = UIView() line.backgroundColor = DroneDockStyle.border addSubview(line) line.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } /// 列表加载、为空与失败时的就地说明,保留顶部订单与刷新入口。 @MainActor final class DroneMaterialMessageCell: UICollectionViewCell { private let icon = UIImageView() private let titleLabel = DroneDockStyle.label(size: 16, weight: .medium) private let detailLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary) override init(frame: CGRect) { super.init(frame: frame) icon.tintColor = DroneDockStyle.secondary icon.contentMode = .scaleAspectFit titleLabel.textAlignment = .center detailLabel.textAlignment = .center detailLabel.numberOfLines = 0 let stack = UIStackView(arrangedSubviews: [icon, titleLabel, detailLabel]) stack.axis = .vertical stack.alignment = .center stack.spacing = 13 contentView.addSubview(stack) stack.snp.makeConstraints { make in make.centerY.equalToSuperview().offset(-12); make.leading.trailing.equalToSuperview().inset(12) } icon.snp.makeConstraints { make in make.size.equalTo(38) } isAccessibilityElement = true } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 通过明确文案区分上传等待、空记录与加载异常。 func apply(title: String, detail: String, symbol: String) { titleLabel.text = title detailLabel.text = detail icon.image = UIImage(systemName: symbol) accessibilityLabel = "\(title),\(detail)" } } /// 固定底栏以同一组件呈现选择、批次进度、暂停与演示结果。 @MainActor final class DroneMaterialsFooterView: UIView { /// 执行当前状态对应的主要操作。 var onPrimaryTap: (() -> Void)? /// 返回选择状态或请求预留的交付入口。 var onSecondaryTap: (() -> Void)? private let titleLabel = DroneDockStyle.label(size: 13, weight: .medium) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let progressView = UIProgressView(progressViewStyle: .default) private let primaryButton = UIButton(type: .system) private let secondaryButton = UIButton(type: .system) private let stack = UIStackView() override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .white let divider = UIView() divider.backgroundColor = DroneDockStyle.border stack.axis = .vertical stack.spacing = 10 titleLabel.numberOfLines = 2 detailLabel.numberOfLines = 2 progressView.progressTintColor = DroneDockStyle.primary progressView.trackTintColor = UIColor(hex: 0xE8EDF7) progressView.accessibilityLabel = "本次演示下载完成项数" primaryButton.titleLabel?.font = .systemFont(ofSize: 15, weight: .medium) primaryButton.layer.cornerRadius = 7 primaryButton.layer.cornerCurve = .continuous primaryButton.tintColor = .white primaryButton.setTitleColor(.white, for: .normal) primaryButton.setTitleColor(UIColor.white.withAlphaComponent(0.85), for: .disabled) secondaryButton.titleLabel?.font = .systemFont(ofSize: 12) secondaryButton.tintColor = DroneDockStyle.secondary primaryButton.addTarget(self, action: #selector(primaryTapped), for: .touchUpInside) secondaryButton.addTarget(self, action: #selector(secondaryTapped), for: .touchUpInside) [titleLabel, progressView, detailLabel, primaryButton, secondaryButton].forEach(stack.addArrangedSubview) addSubview(divider) addSubview(stack) divider.snp.makeConstraints { make in make.leading.trailing.top.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) } stack.snp.makeConstraints { make in make.top.equalToSuperview().offset(12) make.leading.trailing.equalToSuperview().inset(16) make.bottom.equalTo(safeAreaLayoutGuide).inset(10) } primaryButton.snp.makeConstraints { make in make.height.equalTo(44) } secondaryButton.snp.makeConstraints { make in make.height.equalTo(24) } progressView.snp.makeConstraints { make in make.height.equalTo(3) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 只接受显示值,按钮语义和下载状态由控制器及 ViewModel 决定。 func apply(title: String, detail: String, primaryTitle: String, primarySymbol: String, enabled: Bool, identifier: String, progress: Double?, secondaryTitle: String? = nil, tone: DroneDockStatusTone = .gray) { titleLabel.text = title titleLabel.textColor = tone == .gray ? DroneDockStyle.text : DroneDockStyle.color(for: tone) detailLabel.text = detail detailLabel.isHidden = detail.isEmpty progressView.isHidden = progress == nil progressView.setProgress(Float(progress ?? 0), animated: true) var config = UIButton.Configuration.plain() config.title = primaryTitle config.image = UIImage(systemName: primarySymbol) config.imagePadding = 7 config.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12) config.preferredSymbolConfigurationForImage = UIImage.SymbolConfiguration(pointSize: 16) primaryButton.configuration = config primaryButton.isEnabled = enabled primaryButton.backgroundColor = enabled ? DroneDockStyle.primary : UIColor(hex: 0xCEDBFC) primaryButton.accessibilityIdentifier = identifier secondaryButton.setTitle(secondaryTitle, for: .normal) secondaryButton.isHidden = secondaryTitle == nil secondaryButton.accessibilityIdentifier = "drone.materials.continueSelecting" } @objc private func primaryTapped() { onPrimaryTap?() } @objc private func secondaryTapped() { onSecondaryTap?() } }