feat(training): 接入真实培训接口与学习答题恢复

This commit is contained in:
2026-10-14 16:18:48 +08:00
parent 8862ae5401
commit 01068bb24e
28 changed files with 4945 additions and 238 deletions
+31
View File
@@ -199,6 +199,28 @@ final class TrainingTaskCell: UITableViewCell {
footer.axis = traitCollection.preferredContentSizeCategory.isAccessibilityCategory ? .vertical : .horizontal
}
/// 正式任务卡只展示摘要和服务端资格,不由本地时钟推断是否可交卷。
func configure(task: TrainingTaskSummary) {
titleLabel.text = task.title
deadlineLabel.text = task.endAt.map { "截止时间:\(TrainingUI.date($0))" } ?? "未设置截止时间"
statusLabel.text = task.learnerStatus.title
statusLabel.textColor = task.learnerStatus == .completed ? TrainingUI.success : TrainingUI.primary
let publisher = task.publisherName?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
publisherLabel.text = "发布人:\(publisher.isEmpty ? "未记录" : publisher)"
metaLabel.text = task.mode == .exam ? "学习 + 考试 · \(task.sectionCount) 节 · \(task.questionCount) 题 · \(task.passScore ?? 0) 分及格" : "仅学习 · \(task.sectionCount) 节"
let completed = task.learnerStatus == .completed
hintLabel.text = completed ? "已完成本次学习任务" : task.learning.canStartExam ? "课程已学完,可以开始考试" : task.learning.canStudy ? "请阅读课程,完成学习要求" : "任务暂不可提交,可回顾课程内容"
let progress = min(100, max(0, task.learning.progressPercent))
progressView.progress = Float(progress) / 100
progressLabel.text = "学习进度 \(progress)%"
var configuration = actionButton.configuration
configuration?.title = completed ? "回顾学习" : task.learning.canStartExam ? (task.learning.hasDraft ? "继续答题" : "开始考试") : task.learning.canStudy ? "去学习" : "查看课程"
actionButton.configuration = configuration
actionButton.isEnabled = task.learning.canViewCourse || task.learning.canStartExam
actionButton.accessibilityIdentifier = "training.task.action.\(task.id)"
footer.axis = traitCollection.preferredContentSizeCategory.isAccessibilityCategory ? .vertical : .horizontal
}
@objc private func actionTapped() { onAction?() }
}
@@ -245,6 +267,15 @@ final class TrainingRecordCell: UITableViewCell {
statusLabel.text = attempt.passed ? "已通过" : "未通过"
statusLabel.textColor = attempt.passed ? TrainingUI.success : .systemRed
}
/// 正式历史列表使用成绩摘要,不读取任务或完整解析。
func configure(attempt: TrainingAttemptSummary) {
titleLabel.text = attempt.taskTitle
scoreLabel.text = "\(attempt.scoreText) 分"
detailLabel.text = "\(TrainingUI.date(attempt.submittedAt)) · 答对 \(attempt.correctCount) / \(attempt.questionCount) 题"
statusLabel.text = attempt.passed ? "已通过" : "未通过"
statusLabel.textColor = attempt.passed ? TrainingUI.success : .systemRed
}
}
/// 培训页面在账号或景区切换时立即关闭,停止展示旧身份记录。