feat: 接入景区空境库真实素材并统一交付入口

接通场次详情、分页、视频时长与大小,修复日期筛选越界并增加脱敏日志。统一订单与素材库交付方式弹窗,保留任务预选和上传批次,补充模拟器回归测试与接口记录。
This commit is contained in:
2026-10-30 12:11:48 +08:00
parent 20877b425c
commit 0bc801f399
29 changed files with 2350 additions and 203 deletions
@@ -77,7 +77,7 @@ final class ScenicMaterialClipCell: UICollectionViewCell {
statusLabel.isHidden = true
}
/// 显示片段及本机演示传输状态;首段大图额外显示分辨率和体积。
/// 显示片段及本机演示传输状态;首段大图展示时长和文件大小。
func configure(clip: ScenicMaterialClip, selected: Bool, isSelectionEnabled: Bool,
statusText: String? = nil, progress: Double? = nil, isHero: Bool = false) {
cover.kf.cancelDownloadTask()
@@ -85,7 +85,7 @@ final class ScenicMaterialClipCell: UICollectionViewCell {
cover.kf.setImage(with: clip.coverURL, placeholder: UIImage(systemName: "photo"))
} else { cover.image = UIImage(named: clip.coverAssetName) }
ordinalLabel.text = clip.fileLabel ?? String(format: "片段 %02d", clip.ordinal)
metadataLabel.text = isHero ? "\(clip.durationText) · \(clip.resolution) · \(clip.sizeText)" : clip.durationText
metadataLabel.text = isHero ? "\(clip.durationText) · \(clip.sizeText)" : clip.durationText
metadataLabel.font = .monospacedDigitSystemFont(ofSize: isHero ? 11 : 10, weight: .regular)
selectionButton.setImage(UIImage(systemName: selected ? "checkmark.circle.fill" : "circle",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 22, weight: .regular)), for: .normal)
@@ -123,6 +123,8 @@ final class ScenicMaterialDateFilterViewController: UIViewController, UIPickerVi
private var endDate: Date
private var usesAllDates: Bool
private var endpoint: Endpoint = .start
// 日列不能依赖 UIPickerView 正在切换的月份选择,UIKit 可能仍请求上一个月的行。
private var displayedMonthIndex: Int
private let allButton = UIButton(type: .system)
private let startButton = UIButton(type: .custom)
private let endButton = UIButton(type: .custom)
@@ -137,6 +139,7 @@ final class ScenicMaterialDateFilterViewController: UIViewController, UIPickerVi
let clampedEnd = options.clamped(end ?? maximumDate)
self.startDate = min(clampedStart, clampedEnd)
self.endDate = max(clampedStart, clampedEnd)
displayedMonthIndex = options.monthIndex(for: min(clampedStart, clampedEnd))
// 打开面板先编辑日期草稿;取消不会改变列表当前的“全部时间”。
usesAllDates = false
super.init(nibName: nil, bundle: nil)
@@ -270,8 +273,9 @@ final class ScenicMaterialDateFilterViewController: UIViewController, UIPickerVi
}
let value = endpoint == .start ? startDate : endDate
let monthIndex = dateOptions.monthIndex(for: value)
displayedMonthIndex = monthIndex
picker.reloadAllComponents()
picker.selectRow(monthIndex, inComponent: 0, animated: false)
picker.reloadComponent(1)
let dayIndex = dateOptions.months[monthIndex].dates.firstIndex(of: value) ?? 0
picker.selectRow(dayIndex, inComponent: 1, animated: false)
picker.accessibilityLabel = endpoint == .start ? "开始日期,月份和日期" : "结束日期,月份和日期"
@@ -289,7 +293,8 @@ final class ScenicMaterialDateFilterViewController: UIViewController, UIPickerVi
/// 首尾月份按保留期裁剪,滚轮中不会出现不可提交的日期。
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 { return dateOptions.months.count }
return dateOptions.months[max(pickerView.selectedRow(inComponent: 0), 0)].dates.count
guard component == 1, dateOptions.months.indices.contains(displayedMonthIndex) else { return 0 }
return dateOptions.months[displayedMonthIndex].dates.count
}
/// 使用与网页一致的 40 点行高。
@@ -304,12 +309,18 @@ final class ScenicMaterialDateFilterViewController: UIViewController, UIPickerVi
label.font = .systemFont(ofSize: 20, weight: .medium)
label.textColor = ScenicMaterialsStyle.text
label.textAlignment = .center
label.text = nil
label.accessibilityLabel = nil
if component == 0 {
guard dateOptions.months.indices.contains(row) else { return label }
let month = dateOptions.months[row]
label.text = dateOptions.monthTitle(at: row)
label.accessibilityLabel = "\(month.year)年\(month.number)月"
} else {
let month = dateOptions.months[max(pickerView.selectedRow(inComponent: 0), 0)]
} else if component == 1 {
guard dateOptions.months.indices.contains(displayedMonthIndex) else { return label }
let month = dateOptions.months[displayedMonthIndex]
// 切换到短月或截断末月时,UIKit 过渡帧可能仍请求旧日列的末尾行。
guard month.dates.indices.contains(row) else { return label }
label.text = "\(calendar.component(.day, from: month.dates[row]))日"
label.accessibilityLabel = label.text
}
@@ -318,15 +329,17 @@ final class ScenicMaterialDateFilterViewController: UIViewController, UIPickerVi
/// 更改月份时保留日号并收敛月末;更改端点后同步修正倒置区间。
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
usesAllDates = false
let monthIndex = max(pickerView.selectedRow(inComponent: 0), 0)
let value: Date
if component == 0 {
guard dateOptions.months.indices.contains(row) else { return }
let current = endpoint == .start ? startDate : endDate
value = dateOptions.date(inMonthAt: row, preferredDay: calendar.component(.day, from: current))
} else {
value = dateOptions.months[monthIndex].dates[row]
}
} else if component == 1 {
guard dateOptions.months.indices.contains(displayedMonthIndex),
dateOptions.months[displayedMonthIndex].dates.indices.contains(row) else { return }
value = dateOptions.months[displayedMonthIndex].dates[row]
} else { return }
usesAllDates = false
if endpoint == .start {
startDate = value
if endDate < value { endDate = value }
@@ -93,7 +93,7 @@ final class ScenicMaterialPreviewViewController: UIViewController {
progressView.accessibilityLabel = "播放进度"
playbackTime.accessibilityIdentifier = "scenic.materials.preview.playbackTime"
resetPlaybackTime()
let metadata = ScenicMaterialsStyle.label("\(clip.resolution) · \(clip.sizeText)", size: 11, color: ScenicMaterialsStyle.secondary)
let metadata = ScenicMaterialsStyle.label("\(clip.durationText) · \(clip.sizeText)", size: 11, color: ScenicMaterialsStyle.secondary)
metadata.numberOfLines = 2
metadata.textAlignment = .right
metadata.accessibilityIdentifier = "scenic.materials.preview.metadata"
@@ -11,7 +11,7 @@ final class ScenicMaterialsViewController: BaseViewController {
/// 辅助说明与每次拍摄批次分别使用稳定分区身份。
private enum Section: Hashable { case retention, group(String), end }
/// 选择与进度不参与身份,Diffable 更新时复用原有单元。
private enum Item: Hashable { case retention, clip(String), expand(String), end }
private enum Item: Hashable { case retention, clip(String), expand(String), loadMore, end }
private let filterBar = UIStackView()
private let routeButton = UIButton(type: .system)
@@ -24,6 +24,7 @@ final class ScenicMaterialsViewController: BaseViewController {
private let driver = ScenicMaterialDemoDownloadDriver()
private let downloadService = ScenicMaterialDownloadService()
private var loadTask: Task<Void, Never>?
private var isLoadingNextPage = false
private let refreshControl = UIRefreshControl()
private let retryButton = UIButton(type: .system)
private var authorizationTask: Task<Void, Never>?
@@ -50,6 +51,7 @@ final class ScenicMaterialsViewController: BaseViewController {
@objc private func reloadRemoteMaterials() {
guard viewModel.isRemote, !viewModel.isSelectionLocked else { refreshControl.endRefreshing(); return }
loadTask?.cancel()
isLoadingNextPage = false
let session = AppStore.shared.session
guard session.accountType == .storeUser, session.userId == viewModel.context.userID,
String(session.currentScenicId) == viewModel.context.scenicID else {
@@ -72,6 +74,29 @@ final class ScenicMaterialsViewController: BaseViewController {
}
}
/// 用户主动加载下一页;不把第一页误标为全部素材,失败时保留已展示内容。
private func loadMoreRemoteMaterials() {
guard viewModel.isRemote, !viewModel.isSelectionLocked, !viewModel.isLoading,
!isLoadingNextPage, viewModel.hasMoreRemoteSessions else { return }
let session = AppStore.shared.session
guard session.accountType == .storeUser, session.userId == viewModel.context.userID,
String(session.currentScenicId) == viewModel.context.scenicID else {
showToast("请使用门店账号并重新进入当前景区素材库")
return
}
isLoadingNextPage = true
refreshDisplay(animated: false)
let api = ScenicMaterialsAPI(client: NetworkServices.shared.apiClient)
loadTask = Task { @MainActor [weak self] in
guard let self else { return }
await self.viewModel.loadMoreRemoteSessions(api: api)
guard !Task.isCancelled else { return }
self.isLoadingNextPage = false
self.refreshDisplay()
if let error = self.viewModel.loadMoreError { self.showToast(error) }
}
}
override func setupNavigationBar() {
title = "景区空境库"
navigationItem.backButtonDisplayMode = .minimal
@@ -121,6 +146,7 @@ final class ScenicMaterialsViewController: BaseViewController {
collectionView.register(ScenicMaterialClipCell.self, forCellWithReuseIdentifier: "clip")
collectionView.register(ScenicMaterialExpandCell.self, forCellWithReuseIdentifier: "expand")
collectionView.register(ScenicMaterialTextCell.self, forCellWithReuseIdentifier: "text")
collectionView.register(ScenicMaterialPageFooterCell.self, forCellWithReuseIdentifier: "pageFooter")
collectionView.register(ScenicMaterialGroupHeaderView.self,
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: "group")
@@ -186,6 +212,7 @@ final class ScenicMaterialsViewController: BaseViewController {
/// 仅在确认离开页面后作废异步工作,取消返回手势继续保留原来的加载及下载。
private func finishLeaving() {
loadTask?.cancel()
isLoadingNextPage = false
viewModel.cancelRemoteLoad()
authorizationTask?.cancel()
authorizationTask = nil
@@ -197,8 +224,8 @@ final class ScenicMaterialsViewController: BaseViewController {
guard dataSource != nil else { return }
routeButton.setTitle(viewModel.routeFilterTitle, for: .normal)
dateButton.setTitle(viewModel.dateFilterTitle, for: .normal)
routeButton.isEnabled = !viewModel.isSelectionLocked && !viewModel.isLoading
dateButton.isEnabled = !viewModel.isSelectionLocked && !viewModel.isLoading
routeButton.isEnabled = !viewModel.isSelectionLocked && !viewModel.isLoading && !isLoadingNextPage
dateButton.isEnabled = !viewModel.isSelectionLocked && !viewModel.isLoading && !isLoadingNextPage
retryButton.isHidden = viewModel.loadError == nil
emptyTitle.text = viewModel.emptyTitle
emptyMessage.text = viewModel.emptyMessage
@@ -213,7 +240,8 @@ final class ScenicMaterialsViewController: BaseViewController {
if group.clips.count > 5 { snapshot.appendItems([.expand(group.id)]) }
}
if !viewModel.filteredGroups.isEmpty {
snapshot.appendSections([.end]); snapshot.appendItems([.end])
snapshot.appendSections([.end])
snapshot.appendItems([viewModel.isRemote && viewModel.hasMoreRemoteSessions ? .loadMore : .end])
}
let existing = Set(dataSource.snapshot().itemIdentifiers)
snapshot.reconfigureItems(snapshot.itemIdentifiers.filter { existing.contains($0) })
@@ -251,6 +279,7 @@ final class ScenicMaterialsViewController: BaseViewController {
button.layer.borderWidth = 1
button.layer.borderColor = ScenicMaterialsStyle.border.cgColor
button.titleLabel?.lineBreakMode = .byTruncatingTail
button.titleLabel?.numberOfLines = 1
button.accessibilityIdentifier = identifier
let chevron = UIImageView(image: UIImage(systemName: "chevron.down", withConfiguration: UIImage.SymbolConfiguration(pointSize: 10, weight: .medium)))
chevron.tintColor = ScenicMaterialsStyle.secondary
@@ -305,6 +334,13 @@ final class ScenicMaterialsViewController: BaseViewController {
self?.refreshDisplay(animated: true)
}
return cell
case .loadMore:
let cell = list.dequeueReusableCell(withReuseIdentifier: "pageFooter", for: path) as! ScenicMaterialPageFooterCell
let title = self.isLoadingNextPage ? "正在加载更多场次…" : self.viewModel.loadMoreError != nil ? "加载失败,点击重试" :
"加载更多场次(\(self.viewModel.loadedRemoteSessionCount) / \(self.viewModel.remoteTotalCount))"
cell.configure(title: title, enabled: !self.isLoadingNextPage && !self.viewModel.isSelectionLocked)
cell.onLoadMore = { [weak self] in self?.loadMoreRemoteMaterials() }
return cell
case .retention, .end:
let cell = list.dequeueReusableCell(withReuseIdentifier: "text", for: path) as! ScenicMaterialTextCell
cell.configure(item == .retention ? self.viewModel.retentionTips : (self.viewModel.isRemote ? "已显示全部素材" : "已显示保留期内的全部演示记录"), identifier: item == .retention ? "scenic.materials.retention" : "scenic.materials.end")
@@ -374,7 +410,7 @@ final class ScenicMaterialsViewController: BaseViewController {
let section = sections[index]
guard case .group(let id) = section, let group = self.viewModel.group(id: id) else {
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
let row = NSCollectionLayoutGroup.vertical(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(36)), subitems: [item])
let row = NSCollectionLayoutGroup.vertical(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(section == .end ? 48 : 36)), subitems: [item])
let layout = NSCollectionLayoutSection(group: row)
layout.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)
return layout
@@ -418,7 +454,7 @@ final class ScenicMaterialsViewController: BaseViewController {
switch viewModel.phase {
case .idle:
footer.configure(title: "已选 \(viewModel.selectedCount) 段", detail: viewModel.isRemote ? nil : "本地演示 · 不下载或保存真实文件",
primaryTitle: "下载所选", primaryEnabled: viewModel.canStartDownload)
primaryTitle: "下载所选", primaryEnabled: viewModel.canStartDownload && !isLoadingNextPage)
case .downloading:
footer.configure(title: "下载中 · \(completed)/\(total) 段", detail: "请保持页面开启,切后台将暂停",
primaryTitle: "正在下载…", primaryEnabled: false, secondaryTitle: "取消", progress: Float(viewModel.downloadProgress), layout: .progress, isBusy: true)
@@ -435,6 +471,7 @@ final class ScenicMaterialsViewController: BaseViewController {
}
private func performPrimaryAction() {
guard !isLoadingNextPage, !viewModel.isLoading, !viewModel.isLoadingMore else { return }
if viewModel.phase == .completed {
viewModel.continueSelecting(); refreshDisplay(); return
}
@@ -459,6 +496,7 @@ final class ScenicMaterialsViewController: BaseViewController {
}
private func startTransfer() {
guard !isLoadingNextPage, !viewModel.isLoading, !viewModel.isLoadingMore else { return }
let started: Bool
switch viewModel.phase {
case .idle: started = viewModel.startDownload()
@@ -554,6 +592,44 @@ final class ScenicMaterialsViewController: BaseViewController {
}
}
/// 分页末行仅负责触发用户主动加载,加载中禁用,失败后由页面设置重试文案。
@MainActor
final class ScenicMaterialPageFooterCell: UICollectionViewCell {
/// 请求下一页或重试失败页。
var onLoadMore: (() -> Void)?
private let button = UIButton(type: .system)
/// 创建完整行宽的可访问加载按钮。
override init(frame: CGRect) {
super.init(frame: frame)
button.titleLabel?.font = .systemFont(ofSize: 13)
button.tintColor = ScenicMaterialsStyle.primary
button.accessibilityIdentifier = "scenic.materials.loadMore"
button.addTarget(self, action: #selector(loadMore), for: .touchUpInside)
contentView.addSubview(button)
button.snp.makeConstraints { $0.edges.equalToSuperview() }
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override func prepareForReuse() {
super.prepareForReuse()
onLoadMore = nil
}
/// 显示数量、加载中或重试状态,避免重复触发网络请求。
func configure(title: String, enabled: Bool) {
button.setTitle(title, for: .normal)
button.isEnabled = enabled
}
@objc private func loadMore() {
guard button.isEnabled else { return }
onLoadMore?()
}
}
/// 空镜列表的保留期与末尾说明,不参与素材选择。
private final class ScenicMaterialTextCell: UICollectionViewCell {
private let label = ScenicMaterialsStyle.label(size: 12, color: ScenicMaterialsStyle.secondary)