feat(training): 支持课程附件预览与整页阅读

This commit is contained in:
2026-10-20 13:36:58 +08:00
parent 091d17ff21
commit b149295e66
53 changed files with 4233 additions and 632 deletions
+11 -5
View File
@@ -20,6 +20,11 @@ enum TrainingRemoteFixtures {
static func progress(seconds: Int = 20, completed: Bool = false) -> TrainingProgressSnapshot {
TrainingProgressSnapshot(taskID: "task_1", readingSeconds: seconds, requiredReadingSeconds: 20, completedSectionCount: seconds >= 20 ? 2 : 0, sectionCount: 2, progressPercent: seconds >= 20 ? 100 : 0, readingCompleted: seconds >= 20, learnerStatus: completed ? .completed : .pendingExam, completedAt: completed ? now : nil, hasDraft: false, canViewCourse: true, canStudy: seconds < 20 && !completed, canStartExam: seconds >= 20 && !completed, canRetry: !completed, blockReason: completed ? "completed" : seconds < 20 ? "reading_required" : nil, serverTime: now)
}
/// 轻量课程文档,默认使用可由本地替身稳定预览的纯文本。
static func attachment(id: String = "file_1", name: String = "培训资料.txt", mimeType: String = "text/plain") -> TrainingAttachmentInfo {
TrainingAttachmentInfo(id: id, name: name, mimeType: mimeType, sizeBytes: 1024,
fileID: id, downloadURL: nil, expiresAt: nil)
}
/// 单次已提交成绩。
static func attempt(id: String = "attempt_1", passed: Bool = true, questionCount: Int = 30, reviewAvailable: Bool = true) -> TrainingAttemptSummary {
TrainingAttemptSummary(id: id, taskID: "task_1", taskTitle: "一线服务规范学习", courseSnapshotID: "course_1", courseTitle: "景区服务规范", paperSnapshotID: "paper_1", submittedAt: now, scoreHundredths: passed ? 10000 : 5000, correctCount: passed ? questionCount : questionCount / 2, questionCount: questionCount, passScore: 80, passed: passed, reviewAvailable: reviewAvailable)
@@ -44,6 +49,7 @@ actor TrainingDataStub: TrainingDataServing {
var cursor: String? = nil
var offset: Int? = nil
var limit: Int? = nil
var resourceID: String? = nil
}
/// 心跳的固定幂等负载。
struct HeartbeatCall: Equatable, Sendable {
@@ -129,7 +135,7 @@ actor TrainingDataStub: TrainingDataServing {
func course(id: String, taskID: String) async throws -> TrainingCourseInfo {
calls.append(Call(name: "course", taskID: taskID))
if let handler = configuration.courseHandler { return try await handler() }
return TrainingCourseInfo(id: id, title: "景区服务规范", introduction: "正式课程简介", sectionCount: 2, attachmentCount: 0)
return TrainingCourseInfo(id: id, title: "景区服务规范", introduction: "正式课程简介", sectionCount: 2, attachmentCount: 1)
}
/// 小节目录,仅含标题与序号。
func sections(courseID: String, taskID: String, cursor: String?, limit: Int) async throws -> TrainingCursorPage<TrainingSectionInfo> {
@@ -147,13 +153,13 @@ actor TrainingDataStub: TrainingDataServing {
func attachments(courseID: String, taskID: String, cursor: String?, limit: Int) async throws -> TrainingCursorPage<TrainingAttachmentInfo> {
calls.append(Call(name: "attachments", taskID: taskID, cursor: cursor, limit: limit))
if let handler = configuration.attachmentsHandler { return try await handler(cursor) }
return TrainingCursorPage(items: [], nextCursor: nil, hasMore: false, serverTime: nil)
return TrainingCursorPage(items: [TrainingRemoteFixtures.attachment()], nextCursor: nil, hasMore: false, serverTime: nil)
}
/// 返回用于 Safari 的授权 HTTPS URL。
/// 返回供文档加载替身读取的授权 HTTPS URL。
func attachmentURL(courseID: String, attachmentID: String, taskID: String) async throws -> TrainingAttachmentLink {
calls.append(Call(name: "attachmentURL", taskID: taskID))
calls.append(Call(name: "attachmentURL", taskID: taskID, resourceID: attachmentID))
if let handler = configuration.attachmentURLHandler { return try await handler(attachmentID) }
return TrainingAttachmentLink(id: attachmentID, name: "培训附件", url: URL(string: "https://example.test/training.pdf")!, expiresAt: TrainingRemoteFixtures.now.addingTimeInterval(3600))
return TrainingAttachmentLink(id: attachmentID, name: "培训资料.txt", url: URL(string: "https://example.test/training.txt")!, expiresAt: TrainingRemoteFixtures.now.addingTimeInterval(3600))
}
/// 只返回权威读时。
func progress(taskID: String) async throws -> TrainingProgressSnapshot {