feat: 接入景区空境库真实素材并统一交付入口
接通场次详情、分页、视频时长与大小,修复日期筛选越界并增加脱敏日志。统一订单与素材库交付方式弹窗,保留任务预选和上传批次,补充模拟器回归测试与接口记录。
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user