feat(training): 新增已结束筛选并精简课程展示

新增已结束任务筛选与只读回顾资格,保留搜索和游标分页。移除任务小节数量及课程附件文件名、切换入口,并更新接口和界面回归测试。
This commit is contained in:
2026-10-20 14:04:25 +08:00
parent b149295e66
commit 27be1f30ed
14 changed files with 227 additions and 77 deletions
@@ -16,7 +16,6 @@ final class TrainingCourseViewController: TrainingBaseViewController {
private let courseNameLabel = TrainingUI.text(size: 12.5, color: TrainingUI.muted)
private let examInfoLabel = TrainingUI.text(size: 12.5, color: TrainingUI.muted)
private let introductionLabel = TrainingUI.text(size: 12.5, color: TrainingUI.muted)
private let attachmentButton = TrainingUI.button("", plain: true)
private let previewView = TrainingDocumentPreviewView()
private var previewHeightConstraint: Constraint?
private var localDocument: TrainingLocalDocument?
@@ -84,12 +83,7 @@ final class TrainingCourseViewController: TrainingBaseViewController {
courseNameLabel.accessibilityIdentifier = "training.reading.courseName"
examInfoLabel.accessibilityIdentifier = "training.reading.examInfo"
introductionLabel.accessibilityIdentifier = "training.reading.introduction"
attachmentButton.contentHorizontalAlignment = .leading
attachmentButton.accessibilityIdentifier = "training.reading.documentPicker"
attachmentButton.showsMenuAsPrimaryAction = true
attachmentButton.isHidden = true
contentStack.addArrangedSubview(metadataStack)
contentStack.addArrangedSubview(attachmentButton)
contentStack.addArrangedSubview(previewView)
stepView.isHidden = true
bottomStack.axis = .vertical
@@ -289,37 +283,6 @@ final class TrainingCourseViewController: TrainingBaseViewController {
examInfoLabel.text = task.mode == .exam ? "学习 + 考试 · \(task.questionCount) 题 · \(task.passScore ?? 0) 分及格" : "仅学习"
introductionLabel.text = course.introduction
introductionLabel.isHidden = course.introduction.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
attachmentButton.isHidden = viewModel.currentAttachment == nil
var configuration = attachmentButton.configuration
configuration?.title = viewModel.currentAttachment?.name
let canSwitch = viewModel.attachments.count > 1 || viewModel.hasMoreAttachments
configuration?.image = canSwitch ? UIImage(systemName: "chevron.down") : nil
configuration?.imagePlacement = .trailing
configuration?.imagePadding = 8
configuration?.contentInsets = .zero
configuration?.titleLineBreakMode = .byWordWrapping
attachmentButton.configuration = configuration
attachmentButton.isUserInteractionEnabled = canSwitch && userRequestID == nil
var actions = viewModel.attachments.map { attachment in
UIAction(title: attachment.name, state: attachment.id == viewModel.currentAttachmentID ? .on : .off) { [weak self] _ in
guard attachment.id != self?.viewModel.currentAttachmentID else { return }
self?.selectAttachment(attachment.id)
}
}
if viewModel.hasMoreAttachments {
actions.append(UIAction(title: "加载更多附件") { [weak self] _ in self?.loadMoreAttachments() })
}
attachmentButton.menu = UIMenu(children: actions)
}
private func loadMoreAttachments() {
guard let request = beginUserRequest(showsLoading: true) else { return }
Task { @MainActor [weak self] in
guard let self else { return }
await performUserRequest(request) { await self.viewModel.loadAttachments(loadMore: true) }
applyMetadata()
if let message = viewModel.attachmentListErrorMessage { showToast(message) }
}
}
private func applyState() {
@@ -330,7 +293,6 @@ final class TrainingCourseViewController: TrainingBaseViewController {
}
let canInteract = userRequestID == nil
actionButton.isUserInteractionEnabled = canInteract
attachmentButton.isUserInteractionEnabled = canInteract && (viewModel.attachments.count > 1 || viewModel.hasMoreAttachments)
guard canInteract else { return }
if contentLoadFailed || viewModel.attachmentErrorMessage != nil || viewModel.task == nil {
noticeLabel.text = viewModel.errorMessage ?? "正在加载课程…"
@@ -344,9 +306,18 @@ final class TrainingCourseViewController: TrainingBaseViewController {
actionButton.isEnabled = true
return
}
if viewModel.progress?.learnerStatus == .ended {
noticeLabel.text = "任务已结束,仅可回顾课程内容"
setActionTitle("返回培训中心")
actionButton.isEnabled = true
readingTimer?.invalidate()
readingTimer = nil
return
}
if let progress = viewModel.progress, progress.readingCompleted {
noticeLabel.text = viewModel.readingErrorMessage ?? "课程阅读已完成"
if viewModel.task?.summary.mode == .exam && progress.canStartExam { setActionTitle("开始考试") }
if viewModel.task?.summary.mode == .exam && viewModel.task?.summary.learnerStatus == .pendingExam
&& progress.learnerStatus == .pendingExam && progress.canStartExam { setActionTitle("开始考试") }
else { setActionTitle("返回培训中心") }
actionButton.isEnabled = true
readingTimer?.invalidate()
@@ -487,7 +458,8 @@ final class TrainingCourseViewController: TrainingBaseViewController {
} else if viewModel.attachments.isEmpty { returnToCenter() }
else if let progress = viewModel.progress, progress.readingCompleted {
pauseReading()
if viewModel.task?.summary.mode == .exam && progress.canStartExam {
if viewModel.task?.summary.mode == .exam && viewModel.task?.summary.learnerStatus == .pendingExam
&& progress.learnerStatus == .pendingExam && progress.canStartExam {
navigationController?.pushViewController(TrainingExamViewController(taskID: taskID, service: service), animated: true)
} else { returnToCenter() }
} else if !viewModel.canStudy { returnToCenter() }