import SnapKit import UIKit /// 交付 Sheet 的标题、订单摘要及 44 点关闭按钮。 @MainActor final class DroneDeliveryUploadHeaderView: UIView { /// 关闭当前交付流程。 var onCloseTap: (() -> Void)? private let titleLabel = DroneDockStyle.label(size: 19, weight: .semibold) private let customerLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let closeButton = UIButton(type: .system) private let debugButton = UIButton(type: .system) override init(frame: CGRect) { super.init(frame: frame) closeButton.setImage(UIImage(systemName: "xmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: 14)), for: .normal) closeButton.tintColor = DroneDockStyle.secondary closeButton.accessibilityLabel = "关闭成片交付" closeButton.accessibilityIdentifier = "drone.delivery.upload.close" closeButton.addTarget(self, action: #selector(closeTapped), for: .touchUpInside) debugButton.setImage(UIImage(systemName: "slider.horizontal.3"), for: .normal) debugButton.tintColor = DroneDockStyle.secondary debugButton.showsMenuAsPrimaryAction = true debugButton.isHidden = true debugButton.accessibilityIdentifier = "drone.delivery.upload.scenarios" debugButton.accessibilityLabel = "成片交付演示状态" [titleLabel, customerLabel, detailLabel, closeButton, debugButton].forEach(addSubview) titleLabel.accessibilityTraits = .header titleLabel.snp.makeConstraints { make in make.top.equalToSuperview().offset(16); make.leading.equalToSuperview().offset(20); make.trailing.lessThanOrEqualTo(closeButton.snp.leading) } customerLabel.snp.makeConstraints { make in make.leading.equalTo(titleLabel); make.top.equalTo(titleLabel.snp.bottom).offset(20); make.trailing.lessThanOrEqualTo(closeButton.snp.leading).offset(-4) } detailLabel.snp.makeConstraints { make in make.leading.equalTo(titleLabel); make.top.equalTo(customerLabel.snp.bottom).offset(6); make.trailing.equalToSuperview().inset(20); make.bottom.equalToSuperview().inset(12) } closeButton.snp.makeConstraints { make in make.trailing.equalToSuperview().inset(8); make.centerY.equalTo(customerLabel); make.size.equalTo(44) } debugButton.snp.makeConstraints { make in make.trailing.equalTo(closeButton); make.centerY.equalTo(titleLabel); make.size.equalTo(44) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 阶段变化时只更新标题与上下文,不修改业务状态。 func apply(title: String, customer: String, detail: String) { titleLabel.text = title customerLabel.text = customer detailLabel.text = detail } /// 在本地演示版本显示显式验收菜单。 func setDebugMenu(_ menu: UIMenu) { debugButton.menu = menu debugButton.isHidden = false } @objc private func closeTapped() { onCloseTap?() } } /// 面对面闪传或云端上传的整卡入口。 @MainActor final class DroneDeliveryUploadMethodCell: UICollectionViewCell { private let iconView = UIImageView() private let titleLabel = DroneDockStyle.label(size: 16, weight: .semibold) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let arrowView = UIImageView(image: UIImage(systemName: "chevron.right")) override init(frame: CGRect) { super.init(frame: frame) contentView.backgroundColor = UIColor(hex: 0xF9FAFD) contentView.layer.cornerRadius = 12 contentView.layer.borderWidth = 1 contentView.layer.borderColor = DroneDockStyle.border.cgColor iconView.tintColor = DroneDockStyle.primary iconView.backgroundColor = DroneDockStyle.primary.withAlphaComponent(0.06) iconView.layer.cornerRadius = 10 iconView.contentMode = .center arrowView.tintColor = DroneDockStyle.secondary arrowView.contentMode = .scaleAspectFit [iconView, titleLabel, detailLabel, arrowView].forEach(contentView.addSubview) iconView.snp.makeConstraints { make in make.leading.equalToSuperview().offset(14); make.centerY.equalToSuperview(); make.size.equalTo(44) } titleLabel.snp.makeConstraints { make in make.leading.equalTo(iconView.snp.trailing).offset(12); make.top.equalToSuperview().offset(21); make.trailing.lessThanOrEqualTo(arrowView.snp.leading).offset(-8) } detailLabel.snp.makeConstraints { make in make.leading.equalTo(titleLabel); make.top.equalTo(titleLabel.snp.bottom).offset(6); make.trailing.lessThanOrEqualTo(arrowView.snp.leading).offset(-8) } arrowView.snp.makeConstraints { make in make.trailing.equalToSuperview().inset(15); make.centerY.equalToSuperview(); make.width.equalTo(8); make.height.equalTo(13) } isAccessibilityElement = true accessibilityTraits = .button } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 展示可观察的方式说明,不暗示闪传已经接入。 func apply(title: String, detail: String, symbol: String, identifier: String) { titleLabel.text = title detailLabel.text = detail iconView.image = UIImage(systemName: symbol, withConfiguration: UIImage.SymbolConfiguration(pointSize: 23)) accessibilityLabel = "\(title),\(detail)" accessibilityIdentifier = identifier } } /// 云端交付目标点位的单选行。 @MainActor final class DroneDeliveryUploadPointCell: UICollectionViewCell { private let titleLabel = DroneDockStyle.label(size: 16) private let checkmark = UIImageView() override init(frame: CGRect) { super.init(frame: frame) checkmark.contentMode = .scaleAspectFit let line = UIView() line.backgroundColor = DroneDockStyle.border [titleLabel, checkmark, line].forEach(contentView.addSubview) titleLabel.snp.makeConstraints { make in make.leading.centerY.equalToSuperview(); make.trailing.lessThanOrEqualTo(checkmark.snp.leading).offset(-12) } checkmark.snp.makeConstraints { make in make.trailing.centerY.equalToSuperview(); make.size.equalTo(21) } line.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) } isAccessibilityElement = true } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 已选点位仍可再次点击,不通过 UI 取消单选。 func apply(point: DroneShootingPoint, selected: Bool, locked: Bool) { titleLabel.text = point.name titleLabel.textColor = selected ? DroneDockStyle.primary : DroneDockStyle.text checkmark.image = UIImage(systemName: selected ? "checkmark.circle" : "circle") checkmark.tintColor = selected ? DroneDockStyle.primary : DroneDockStyle.secondary contentView.alpha = locked ? 0.5 : 1 accessibilityIdentifier = "drone.delivery.upload.point.\(point.id)" accessibilityLabel = point.name var traits: UIAccessibilityTraits = .button if selected { traits.insert(.selected) } if locked { traits.insert(.notEnabled) } accessibilityTraits = traits } } /// 本地演示视频缩略图;整卡选择与预览按钮分开,避免打开预览时改变勾选。 @MainActor final class DroneDeliveryUploadVideoCell: UICollectionViewCell { /// 点击整卡选择区域时仅切换当前视频。 var onSelectionTap: (() -> Void)? /// 点击独立预览按钮时通知控制器。 var onPreviewTap: (() -> Void)? private let thumbnail = UIImageView() private let checkmark = UIImageView() private let durationLabel = DroneDockStyle.label(size: 10, color: .white) private let titleLabel = DroneDockStyle.label(size: 12, weight: .medium) private let previewButton = UIButton(type: .system) private let selectionButton = UIButton(type: .custom) override init(frame: CGRect) { super.init(frame: frame) thumbnail.contentMode = .scaleAspectFill thumbnail.clipsToBounds = true thumbnail.layer.cornerRadius = 7 thumbnail.layer.borderWidth = 2 checkmark.contentMode = .scaleAspectFit durationLabel.backgroundColor = UIColor.black.withAlphaComponent(0.5) durationLabel.textAlignment = .center durationLabel.layer.cornerRadius = 3 durationLabel.clipsToBounds = true previewButton.setImage(UIImage(systemName: "play.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 22)), for: .normal) previewButton.tintColor = .white previewButton.addTarget(self, action: #selector(previewTapped), for: .touchUpInside) selectionButton.addTarget(self, action: #selector(selectionTapped), for: .touchUpInside) [thumbnail, checkmark, durationLabel, titleLabel, selectionButton, previewButton].forEach(contentView.addSubview) thumbnail.snp.makeConstraints { make in make.top.leading.trailing.equalToSuperview(); make.height.equalTo(thumbnail.snp.width).multipliedBy(0.56) } checkmark.snp.makeConstraints { make in make.top.equalTo(thumbnail).offset(7); make.trailing.equalTo(thumbnail).inset(7); make.size.equalTo(22) } durationLabel.snp.makeConstraints { make in make.bottom.trailing.equalTo(thumbnail).inset(6); make.width.equalTo(44); make.height.equalTo(18) } previewButton.snp.makeConstraints { make in make.leading.bottom.equalTo(thumbnail); make.size.equalTo(44) } titleLabel.snp.makeConstraints { make in make.leading.trailing.equalToSuperview(); make.top.equalTo(thumbnail.snp.bottom).offset(8); make.bottom.lessThanOrEqualToSuperview() } selectionButton.snp.makeConstraints { make in make.edges.equalToSuperview() } contentView.isAccessibilityElement = false } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 图片及预览均来自本地示例,不读取手机文件。 func apply(video: DroneDeliveryVideo, selected: Bool) { thumbnail.image = UIImage(named: video.previewAssetName) thumbnail.layer.borderColor = selected ? DroneDockStyle.primary.cgColor : UIColor.clear.cgColor checkmark.image = UIImage(systemName: selected ? "checkmark.circle.fill" : "circle") checkmark.tintColor = selected ? DroneDockStyle.primary : .white titleLabel.text = video.title durationLabel.text = video.durationText selectionButton.accessibilityIdentifier = "drone.delivery.upload.video.\(video.id)" selectionButton.accessibilityLabel = "选择\(video.title),\(video.durationText)" selectionButton.accessibilityTraits = selected ? [.button, .selected] : .button isAccessibilityElement = false previewButton.accessibilityIdentifier = "drone.delivery.upload.preview.\(video.id)" previewButton.accessibilityLabel = "预览\(video.title)" } @objc private func previewTapped() { onPreviewTap?() } @objc private func selectionTapped() { onSelectionTap?() } } /// 上传队列的一条视频记录,文件描述、逐项进度与演示结果分别展示。 @MainActor final class DroneDeliveryUploadQueueCell: UICollectionViewCell { private let iconView = UIImageView(image: UIImage(systemName: "play.rectangle")) private let titleLabel = DroneDockStyle.label(size: 13, weight: .medium) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let statusLabel = DroneDockStyle.label(size: 11) private let progressView = UIProgressView(progressViewStyle: .default) override init(frame: CGRect) { super.init(frame: frame) iconView.tintColor = DroneDockStyle.secondary iconView.contentMode = .scaleAspectFit progressView.progressTintColor = DroneDockStyle.primary progressView.trackTintColor = UIColor(hex: 0xEDF1F8) let line = UIView() line.backgroundColor = DroneDockStyle.border [iconView, titleLabel, detailLabel, statusLabel, progressView, line].forEach(contentView.addSubview) iconView.snp.makeConstraints { make in make.leading.equalToSuperview(); make.centerY.equalToSuperview().offset(-4); make.size.equalTo(24) } statusLabel.snp.makeConstraints { make in make.trailing.equalToSuperview(); make.centerY.equalTo(iconView); make.width.lessThanOrEqualTo(100) } titleLabel.lineBreakMode = .byTruncatingMiddle titleLabel.snp.makeConstraints { make in make.leading.equalTo(iconView.snp.trailing).offset(12); make.top.equalToSuperview().offset(17); make.trailing.lessThanOrEqualTo(statusLabel.snp.leading).offset(-10) } detailLabel.snp.makeConstraints { make in make.leading.equalTo(titleLabel); make.top.equalTo(titleLabel.snp.bottom).offset(5); make.trailing.lessThanOrEqualTo(statusLabel.snp.leading).offset(-10) } progressView.snp.makeConstraints { make in make.leading.equalTo(titleLabel); make.trailing.equalToSuperview(); make.bottom.equalToSuperview().inset(9); make.height.equalTo(2) } line.snp.makeConstraints { make in make.leading.trailing.bottom.equalToSuperview(); make.height.equalTo(1 / UIScreen.main.scale) } isAccessibilityElement = true accessibilityTraits = .button } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 队列成功只展示演示交付,不向游客发送作品。 func apply(item: DroneDeliveryUploadItem) { titleLabel.text = item.video.fileName detailLabel.text = "\(item.video.durationText) · \(item.video.sizeText)" let progress: Double? switch item.state { case .uploading(let value): statusLabel.text = "上传中 \(Int(value * 100))%" statusLabel.textColor = DroneDockStyle.primary progress = value case .paused: statusLabel.text = "已暂停" statusLabel.textColor = DroneDockStyle.warning progress = nil case .failed: statusLabel.text = "上传失败" statusLabel.textColor = DroneDockStyle.color(for: .red) progress = nil case .completed: statusLabel.text = "演示交付成功" statusLabel.textColor = DroneDockStyle.success progress = nil } progressView.isHidden = progress == nil progressView.setProgress(Float(progress ?? 0), animated: true) accessibilityIdentifier = "drone.delivery.upload.item.\(item.id)" accessibilityLabel = [item.video.fileName, detailLabel.text, statusLabel.text, "点按预览"].compactMap { $0 }.joined(separator: ",") } } /// 闪传待确认、无点位与无可选视频等状态的说明。 @MainActor final class DroneDeliveryUploadMessageCell: UICollectionViewCell { private let iconView = UIImageView() private let titleLabel = DroneDockStyle.label(size: 16, weight: .semibold) private let detailLabel = DroneDockStyle.label(size: 12, color: DroneDockStyle.secondary) override init(frame: CGRect) { super.init(frame: frame) iconView.tintColor = DroneDockStyle.primary iconView.contentMode = .scaleAspectFit titleLabel.textAlignment = .center detailLabel.textAlignment = .center detailLabel.numberOfLines = 0 let stack = UIStackView(arrangedSubviews: [iconView, titleLabel, detailLabel]) stack.axis = .vertical stack.alignment = .center stack.spacing = 15 contentView.addSubview(stack) stack.snp.makeConstraints { make in make.centerY.equalToSuperview(); make.leading.trailing.equalToSuperview().inset(8) } iconView.snp.makeConstraints { make in make.size.equalTo(34) } 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 iconView.image = UIImage(systemName: symbol) accessibilityLabel = "\(title),\(detail)" } } /// 队列摘要与查看已交付作品入口。 @MainActor final class DroneDeliveryUploadSummaryCell: UICollectionViewCell { /// 查看当前订单的演示交付作品。 var onReviewTap: (() -> Void)? private let titleLabel = DroneDockStyle.label(size: 13, weight: .medium) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let reviewButton = UIButton(type: .system) override init(frame: CGRect) { super.init(frame: frame) reviewButton.setTitle("查看作品", for: .normal) reviewButton.titleLabel?.font = .systemFont(ofSize: 11) reviewButton.tintColor = DroneDockStyle.primary reviewButton.accessibilityIdentifier = "drone.delivery.upload.review" reviewButton.addTarget(self, action: #selector(reviewTapped), for: .touchUpInside) [titleLabel, detailLabel, reviewButton].forEach(contentView.addSubview) titleLabel.snp.makeConstraints { make in make.leading.equalToSuperview(); make.centerY.equalToSuperview().offset(-10) } detailLabel.snp.makeConstraints { make in make.leading.equalTo(titleLabel); make.top.equalTo(titleLabel.snp.bottom).offset(6) } reviewButton.snp.makeConstraints { make in make.trailing.centerY.equalToSuperview(); make.width.equalTo(68); make.height.equalTo(44) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 计数仅统计当前演示批次成功回执。 func apply(completed: Int, detail: String) { titleLabel.text = "本次演示交付 \(completed) 个作品" detailLabel.text = detail reviewButton.isHidden = completed == 0 } @objc private func reviewTapped() { onReviewTap?() } } /// 交付各阶段共用的主按钮、补充说明和返回或完成入口。 @MainActor final class DroneDeliveryUploadFooterView: UIView { /// 执行当前阶段的主操作。 var onPrimaryTap: (() -> Void)? /// 返回上一阶段或完成本次流程。 var onSecondaryTap: (() -> Void)? private let primaryButton = UIButton(type: .system) private let detailLabel = DroneDockStyle.label(size: 11, color: DroneDockStyle.secondary) private let secondaryButton = UIButton(type: .system) private let stack = UIStackView() override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .white stack.axis = .vertical stack.spacing = 9 primaryButton.layer.cornerRadius = 8 primaryButton.layer.cornerCurve = .continuous primaryButton.tintColor = .white primaryButton.titleLabel?.font = .systemFont(ofSize: 15, weight: .medium) primaryButton.addTarget(self, action: #selector(primaryTapped), for: .touchUpInside) detailLabel.textAlignment = .center detailLabel.numberOfLines = 2 secondaryButton.titleLabel?.font = .systemFont(ofSize: 12) secondaryButton.tintColor = DroneDockStyle.secondary secondaryButton.addTarget(self, action: #selector(secondaryTapped), for: .touchUpInside) [primaryButton, detailLabel, secondaryButton].forEach(stack.addArrangedSubview) addSubview(stack) stack.snp.makeConstraints { make in make.leading.trailing.equalToSuperview().inset(20); make.top.equalToSuperview().offset(14); make.bottom.equalTo(safeAreaLayoutGuide).inset(12) } primaryButton.snp.makeConstraints { make in make.height.equalTo(44).priority(999) } secondaryButton.snp.makeConstraints { make in make.height.equalTo(44).priority(999) } } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } /// 不同阶段提供明确动作;上传中的按钮保留可见但不可重复提交。 func apply(primaryTitle: String?, enabled: Bool, identifier: String, detail: String, secondaryTitle: String?) { UIView.performWithoutAnimation { primaryButton.setTitle(primaryTitle, for: .normal) primaryButton.setTitle(primaryTitle, for: .disabled) primaryButton.isHidden = primaryTitle == nil primaryButton.isEnabled = enabled primaryButton.backgroundColor = enabled ? DroneDockStyle.primary : UIColor(hex: 0xE7EEFF) primaryButton.setTitleColor(.white, for: .normal) primaryButton.setTitleColor(DroneDockStyle.primary.withAlphaComponent(0.6), for: .disabled) primaryButton.accessibilityIdentifier = identifier detailLabel.text = detail detailLabel.isHidden = detail.isEmpty secondaryButton.setTitle(secondaryTitle, for: .normal) secondaryButton.isHidden = secondaryTitle == nil secondaryButton.accessibilityIdentifier = "drone.delivery.upload.secondary" primaryButton.layoutIfNeeded() } } @objc private func primaryTapped() { onPrimaryTap?() } @objc private func secondaryTapped() { onSecondaryTap?() } }