feat: 接入景区空境库真实素材并统一交付入口
接通场次详情、分页、视频时长与大小,修复日期筛选越界并增加脱敏日志。统一订单与素材库交付方式弹窗,保留任务预选和上传批次,补充模拟器回归测试与接口记录。
This commit is contained in:
@@ -39,10 +39,10 @@ final class DroneDeliveryUploadViewController: BaseViewController {
|
||||
private var uploadItemsByID: [String: DroneDeliveryUploadItem] = [:]
|
||||
private var didRequestFinish = false
|
||||
|
||||
/// 重新进入有未完成批次时直接恢复队列展示,仍需手动继续上传。
|
||||
/// 每次从外部进入均先选择交付方式,已有批次在选择云端后恢复。
|
||||
init(viewModel: DroneDeliveryViewModel) {
|
||||
self.viewModel = viewModel
|
||||
phase = viewModel.batch == nil ? .method : .queue
|
||||
phase = .method
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
modalPresentationStyle = .pageSheet
|
||||
}
|
||||
@@ -320,7 +320,7 @@ final class DroneDeliveryUploadViewController: BaseViewController {
|
||||
private func primaryTapped() {
|
||||
switch phase {
|
||||
case .method: break
|
||||
case .nearby: showPhase(.point)
|
||||
case .nearby: openCloudFlow()
|
||||
case .point: if viewModel.selectedPoint != nil { showPhase(.picker) }
|
||||
case .picker:
|
||||
if viewModel.startUpload() { showPhase(.queue); startDemoUpload() }
|
||||
@@ -338,6 +338,11 @@ final class DroneDeliveryUploadViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
/// 选择云端仅恢复原队列或进入选点,不清除批次,也不自动继续上传。
|
||||
private func openCloudFlow() {
|
||||
showPhase(viewModel.batch == nil ? .point : .queue)
|
||||
}
|
||||
|
||||
private func secondaryTapped() {
|
||||
switch phase {
|
||||
case .method: break
|
||||
@@ -353,6 +358,7 @@ final class DroneDeliveryUploadViewController: BaseViewController {
|
||||
|
||||
private func pauseForLeaving() {
|
||||
uploadDriver.stop()
|
||||
guard phase == .queue else { return }
|
||||
viewModel.pauseUpload(reason: .leavingPage)
|
||||
}
|
||||
|
||||
@@ -397,7 +403,7 @@ extension DroneDeliveryUploadViewController: UICollectionViewDelegate {
|
||||
guard let item = dataSource.itemIdentifier(for: indexPath) else { return }
|
||||
switch item {
|
||||
case .nearbyMethod: showPhase(.nearby)
|
||||
case .cloudMethod: showPhase(.point)
|
||||
case .cloudMethod: openCloudFlow()
|
||||
case .point(let id): viewModel.selectPoint(id: id); applySnapshot(animated: true)
|
||||
case .upload(let id):
|
||||
if let item = uploadItemsByID[id] { delegate?.deliveryUploadViewController(self, didRequestPreview: item.video) }
|
||||
|
||||
@@ -3,8 +3,9 @@ import UIKit
|
||||
/// 订单列表与素材库共用的真实成片交付页面工厂。
|
||||
@MainActor
|
||||
enum DroneDockDeliveryEntry {
|
||||
/// 订单列表先展示方式选择,云端页面在同一弹窗内继续,关闭后再通知列表刷新。
|
||||
/// 所有交付入口先选择方式;素材入口保留任务预选,云端页面在同一弹窗内继续。
|
||||
static func makeMethodSheet(order: DroneDockHomeOrder, context: DroneDockHomeContext,
|
||||
taskID: Int? = nil,
|
||||
controllerFactory: @escaping (DroneDockHomeOrder, DroneDockHomeContext, Int?) -> UIViewController,
|
||||
onDidCloseCloud: @escaping () -> Void = {}) -> UINavigationController {
|
||||
let methods = DroneDockDeliveryMethodViewController(customerTitle: order.touristTitle)
|
||||
@@ -14,7 +15,7 @@ enum DroneDockDeliveryEntry {
|
||||
methods.onClose = { [weak navigation] in navigation?.dismiss(animated: true) }
|
||||
methods.onCloudUpload = { [weak navigation, weak methods] in
|
||||
guard let navigation, let methods, navigation.topViewController === methods else { return }
|
||||
let cloud = controllerFactory(order, context, nil)
|
||||
let cloud = controllerFactory(order, context, taskID)
|
||||
if let cloud = cloud as? DroneDockDeliveryViewController {
|
||||
cloud.configureSheetPresentation { [weak navigation] in navigation?.dismiss(animated: true) }
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ final class DroneDockDeliveryViewController: BaseViewController {
|
||||
ownedVideoURLs.forEach(DroneDockDeliveryVideoLoader.discard)
|
||||
}
|
||||
|
||||
/// 订单列表以弹窗展示时复用上传流程,并将关闭动作纳入处理中退出确认。
|
||||
/// 交付入口以弹窗展示时复用上传流程,并将关闭动作纳入处理中退出确认。
|
||||
func configureSheetPresentation(onClose: @escaping () -> Void) {
|
||||
onCloseSheet = onClose
|
||||
}
|
||||
|
||||
@@ -301,10 +301,17 @@ final class DroneDockMaterialsViewController: BaseViewController {
|
||||
private func task(_ id: Int) -> DroneDockMaterialTask? { viewModel.tasks.first { $0.id == id } }
|
||||
|
||||
private func openDelivery(taskID: Int) {
|
||||
guard operation == nil, let order = viewModel.detail?.order, order.canUploadFilm == true,
|
||||
task(taskID) != nil, let navigationController else { return }
|
||||
refreshAfterDelivery = true
|
||||
navigationController.pushViewController(deliveryControllerFactory(order, viewModel.context, taskID), animated: true)
|
||||
guard operation == nil, presentedViewController == nil,
|
||||
let order = viewModel.detail?.order, order.canUploadFilm == true, task(taskID) != nil else { return }
|
||||
let sheet = DroneDockDeliveryEntry.makeMethodSheet(order: order, context: viewModel.context,
|
||||
taskID: taskID, controllerFactory: deliveryControllerFactory) { [weak self] in
|
||||
guard let self else { return }
|
||||
self.refreshAfterDelivery = true
|
||||
guard self.viewIfLoaded?.window != nil else { return }
|
||||
self.refreshAfterDelivery = false
|
||||
self.load(.refresh)
|
||||
}
|
||||
present(sheet, animated: true)
|
||||
}
|
||||
|
||||
private func downloadTapped() {
|
||||
|
||||
@@ -382,8 +382,8 @@ extension DroneDockWorkbenchViewController: DroneMaterialsViewControllerDelegate
|
||||
controller.present(preview, animated: true)
|
||||
}
|
||||
|
||||
func materialsViewController(_ controller: DroneMaterialsViewController, didRequestDelivery record: DroneMaterialRecord) {
|
||||
openDelivery(orderID: controller.viewModel.orderID, pointID: record.pointID, from: controller)
|
||||
func materialsViewController(_ controller: DroneMaterialsViewController, didRequestDelivery record: DroneMaterialRecord?) {
|
||||
openDelivery(orderID: controller.viewModel.orderID, pointID: record?.pointID, from: controller)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import UIKit
|
||||
protocol DroneMaterialsViewControllerDelegate: AnyObject {
|
||||
/// 预览单项素材,保持素材库现有选择与下载批次。
|
||||
func materialsViewController(_ controller: DroneMaterialsViewController, didRequestPreview material: DroneMaterial)
|
||||
/// 请求交付成片,并由当前拍摄记录预选点位。
|
||||
func materialsViewController(_ controller: DroneMaterialsViewController, didRequestDelivery record: DroneMaterialRecord)
|
||||
/// 请求先选择交付方式;指定拍摄记录时保留点位预选,整批入口不猜测目标点位。
|
||||
func materialsViewController(_ controller: DroneMaterialsViewController, didRequestDelivery record: DroneMaterialRecord?)
|
||||
}
|
||||
|
||||
/// 订单素材库:按拍摄记录分组,支持点位筛选、独立预览选择与前台演示下载。
|
||||
@@ -453,22 +453,11 @@ final class DroneMaterialsViewController: BaseViewController {
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
/// 完成底栏的交付入口先明确拍摄记录,不根据下载批次猜测目标点位。
|
||||
/// 完成底栏也先选交付方式;多记录批次在选择云端后再由用户选点位。
|
||||
private func chooseCompletedDelivery() {
|
||||
guard delegate != nil, !viewModel.sections.isEmpty else { return }
|
||||
if viewModel.sections.count == 1, let record = viewModel.sections.first {
|
||||
delegate?.materialsViewController(self, didRequestDelivery: record)
|
||||
return
|
||||
}
|
||||
let sheet = UIAlertController(title: "选择拍摄记录", message: "选择需要交付成片的拍摄记录", preferredStyle: .actionSheet)
|
||||
for record in viewModel.sections {
|
||||
sheet.addAction(UIAlertAction(title: "\(record.pointName) · 记录\(record.sequenceNumber)", style: .default) { [weak self] _ in
|
||||
guard let self else { return }
|
||||
self.delegate?.materialsViewController(self, didRequestDelivery: record)
|
||||
})
|
||||
}
|
||||
sheet.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||
present(sheet, animated: true)
|
||||
let record = viewModel.sections.count == 1 ? viewModel.sections.first : nil
|
||||
delegate?.materialsViewController(self, didRequestDelivery: record)
|
||||
}
|
||||
|
||||
private func updateInteractivePopGesture() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user