合并 9.9.1 机巢工作台与拍摄交付流程 #1

Merged
lujiuyin merged 70 commits from dev_9_9_1 into main 2026-11-18 07:05:44 +00:00
4 changed files with 134 additions and 10 deletions
Showing only changes of commit aaed9da964 - Show all commits
@@ -9,7 +9,9 @@ final class TrainingCourseViewController: TrainingBaseViewController {
private let service: any TrainingDataServing
private let viewModel: TrainingRemoteReadingViewModel
private let webView: WKWebView
private let headerStack = UIStackView()
private let toolbar = UIStackView()
private let stepView = TrainingStepView(currentStep: .learning)
private let sectionsButton = TrainingUI.button("章节目录", secondary: true)
private let attachmentsButton = TrainingUI.button("课程附件", secondary: true)
private let bottomStack = UIStackView()
@@ -70,6 +72,9 @@ final class TrainingCourseViewController: TrainingBaseViewController {
toolbar.distribution = .fillEqually
toolbar.addArrangedSubview(sectionsButton)
toolbar.addArrangedSubview(attachmentsButton)
headerStack.axis = .vertical
headerStack.spacing = 20
headerStack.addArrangedSubview(toolbar)
bottomStack.axis = .vertical
bottomStack.spacing = 8
bottomStack.layoutMargins = UIEdgeInsets(top: 10, left: 12, bottom: 10, right: 12)
@@ -80,19 +85,19 @@ final class TrainingCourseViewController: TrainingBaseViewController {
actionButton.accessibilityIdentifier = "training.reading.action"
sectionsButton.accessibilityIdentifier = "training.reading.sections"
attachmentsButton.accessibilityIdentifier = "training.reading.attachments"
view.addSubview(toolbar)
view.addSubview(headerStack)
view.addSubview(webView)
view.addSubview(bottomStack)
applyState()
}
override func setupConstraints() {
toolbar.snp.makeConstraints {
headerStack.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide).offset(8)
$0.leading.trailing.equalToSuperview().inset(13)
}
webView.snp.makeConstraints {
$0.top.equalTo(toolbar.snp.bottom).offset(8)
$0.top.equalTo(headerStack.snp.bottom).offset(8)
$0.leading.trailing.equalTo(view.safeAreaLayoutGuide)
$0.bottom.equalTo(bottomStack.snp.top)
}
@@ -185,11 +190,10 @@ final class TrainingCourseViewController: TrainingBaseViewController {
<!doctype html><html lang="zh-CN"><head><meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'">
<style>
*{box-sizing:border-box}body{font:15px -apple-system,BlinkMacSystemFont,sans-serif;color:#34435b;background:#f5f8fc;margin:0;padding:14px 13px;line-height:1.95;overflow-wrap:anywhere}
*{box-sizing:border-box}body{font:15px -apple-system,BlinkMacSystemFont,sans-serif;color:#34435b;background:#f5f8fc;margin:0;padding:0 13px 14px;line-height:1.95;overflow-wrap:anywhere}
h1{font-size:17px;font-weight:600;line-height:1.6;color:#172033;margin:14px 0 6px}h2{font-size:15.5px;font-weight:600;color:#172033;margin:0 0 10px}img{max-width:100%;height:auto}table{max-width:100%;display:block;overflow:auto}a{color:#2379ff}
.step{display:flex;gap:20px;background:#edf1f7;padding:9px 12px;border-radius:8px;font-size:13px;color:#8994a6}.step b{font-weight:500;color:#2379ff}
.muted{font-size:12.5px;color:#8491a6;line-height:1.65;margin:6px 0}.reading{background:white;border:1px solid #e3ebf5;border-radius:11px;padding:14px;margin-top:14px}
</style></head><body><div class='step'><b>1 课程学习</b><span>\(task.mode == .exam ? "2 在线考试" : "完成学习")</span></div>
</style></head><body>
<h1>\(escape(task.title))</h1><p class='muted'>\(escape(course.title))</p><p class='muted'>\(metadata)</p><p class='muted'>\(escape(course.introduction))</p>
<p class='muted'>第 \(section.order) / \(course.sectionCount) 节</p><div class='reading'><h2>\(escape(section.title))</h2>\(section.contentHTML)</div></body></html>
""", baseURL: nil)
@@ -202,6 +206,10 @@ final class TrainingCourseViewController: TrainingBaseViewController {
private func applyState() {
guard !viewModel.isInvalidated else { leaveUnavailableCourse(); return }
if let task = viewModel.task?.summary {
stepView.configure(mode: task.mode)
if stepView.superview == nil { headerStack.addArrangedSubview(stepView) }
}
let canInteract = userRequestID == nil
sectionsButton.isUserInteractionEnabled = canInteract
attachmentsButton.isUserInteractionEnabled = canInteract
@@ -16,6 +16,8 @@ final class TrainingExamViewController: TrainingBaseViewController {
private var renderedQuestion: TrainingQuestionItem?
private var optionButtons: [String: UIButton] = [:]
private let scrollView = UIScrollView()
private let pageStack = UIStackView()
private let stepView = TrainingStepView(currentStep: .exam)
private let contentStack = TrainingUI.card()
private let positionLabel = TrainingUI.label(style: .subheadline, color: AppColor.primary)
private let questionLabel = TrainingUI.label(style: .title3)
@@ -46,6 +48,10 @@ final class TrainingExamViewController: TrainingBaseViewController {
override func setupUI() {
scrollView.alwaysBounceVertical = true
pageStack.axis = .vertical
pageStack.spacing = 16
pageStack.addArrangedSubview(stepView)
pageStack.addArrangedSubview(contentStack)
optionStack.axis = .vertical
optionStack.spacing = 12
navigationStack.axis = .horizontal
@@ -64,7 +70,7 @@ final class TrainingExamViewController: TrainingBaseViewController {
bottomStack.addArrangedSubview(statusLabel)
bottomStack.addArrangedSubview(submitButton)
submitButton.accessibilityIdentifier = "training.exam.submit"
scrollView.addSubview(contentStack)
scrollView.addSubview(pageStack)
view.addSubview(scrollView)
view.addSubview(bottomStack)
applyState()
@@ -75,7 +81,7 @@ final class TrainingExamViewController: TrainingBaseViewController {
$0.top.leading.trailing.equalTo(view.safeAreaLayoutGuide)
$0.bottom.equalTo(bottomStack.snp.top)
}
contentStack.snp.makeConstraints {
pageStack.snp.makeConstraints {
$0.edges.equalTo(scrollView.contentLayoutGuide).inset(16)
$0.width.equalTo(scrollView.frameLayoutGuide).offset(-32)
}
@@ -0,0 +1,53 @@
import SnapKit
import UIKit
/// 学习与考试共用的进度提示,两项等宽居中,仅突出当前步骤。
@MainActor
final class TrainingStepView: UIView {
/// 当前页面对应的学习流程阶段。
enum Step {
case learning
case exam
}
private let learningLabel: UILabel
private let nextLabel: UILabel
/// 创建只读步骤栏,任务模式可在课程详情返回后更新。
init(currentStep: Step, mode: TrainingMode = .exam) {
learningLabel = TrainingUI.text("1 课程学习", size: 13,
weight: currentStep == .learning ? .semibold : .regular,
color: currentStep == .learning ? TrainingUI.primary : TrainingUI.muted)
nextLabel = TrainingUI.text(size: 13,
weight: currentStep == .exam ? .semibold : .regular,
color: currentStep == .exam ? TrainingUI.primary : TrainingUI.muted)
super.init(frame: .zero)
backgroundColor = UIColor(red: 237/255, green: 241/255, blue: 247/255, alpha: 1)
layer.cornerRadius = 8
accessibilityIdentifier = "training.steps"
learningLabel.accessibilityIdentifier = "training.steps.learning"
nextLabel.accessibilityIdentifier = "training.steps.next"
for label in [learningLabel, nextLabel] { label.textAlignment = .center }
let currentLabel = currentStep == .learning ? learningLabel : nextLabel
currentLabel.accessibilityTraits.insert(.selected)
currentLabel.accessibilityValue = "当前步骤"
let stack = UIStackView(arrangedSubviews: [learningLabel, nextLabel])
stack.axis = .horizontal
stack.alignment = .center
stack.distribution = .fillEqually
addSubview(stack)
stack.snp.makeConstraints {
$0.edges.equalToSuperview().inset(UIEdgeInsets(top: 10, left: 12, bottom: 10, right: 12))
}
snp.makeConstraints { $0.height.greaterThanOrEqualTo(44) }
configure(mode: mode)
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
/// 仅学习任务展示完成学习,考试任务展示在线考试。
func configure(mode: TrainingMode) {
nextLabel.text = mode == .exam ? "2 在线考试" : "完成学习"
}
}
+59 -2
View File
@@ -56,6 +56,63 @@ struct TrainingUIRenderingTests {
Attachment.record(cardImage, named: "320点长标题任务卡", as: .png)
}
@Test("课程与考试步骤等宽居中,窄屏和大字体不裁切")
func learningAndExamStepLayout() async throws {
for width: CGFloat in [320, 390] {
let domain = "training_step_layout_\(UUID().uuidString)"
let defaults = try #require(UserDefaults(suiteName: domain))
defer { defaults.removePersistentDomain(forName: domain) }
let context = TrainingContext(accountScope: domain, scenicID: 1, storeID: 1)
let model = TrainingRemoteExamViewModel(taskID: "task_1", context: context,
pendingStore: TrainingPendingSubmissionStore(defaults: defaults), currentContext: { context })
let source = TrainingDataStub()
let course = TrainingCourseViewController(taskID: "task_1", service: source)
let exam = TrainingExamViewController(taskID: "task_1", service: source, viewModel: model)
for (controller, selectedTitle) in [(course as UIViewController, "1 课程学习"), (exam, "2 在线考试")] {
let navigation = UINavigationController(rootViewController: controller)
let window = try makeWindow(navigation, width: width)
defer { window.isHidden = true }
let deadline = ContinuousClock.now.advanced(by: .seconds(5))
while (!allViews(controller.view).contains { $0 is TrainingStepView }
|| (controller === exam && !model.canEdit)), ContinuousClock.now < deadline {
try await Task.sleep(for: .milliseconds(10))
}
let steps = allViews(controller.view).compactMap { $0 as? TrainingStepView }
#expect(steps.count == 1)
let step = try #require(steps.first)
navigation.view.layoutIfNeeded()
let labels = allViews(step).compactMap { $0 as? UILabel }
#expect(labels.map(\.text) == ["1 课程学习", "2 在线考试"])
let first = try #require(labels.first)
let second = try #require(labels.last)
#expect(abs(first.bounds.width - second.bounds.width) < 1)
#expect(first.convert(first.bounds, to: step).maxX <= second.convert(second.bounds, to: step).minX)
#expect(labels.allSatisfy { $0.textAlignment == .center })
#expect(labels.filter { $0.accessibilityTraits.contains(.selected) }.map(\.text) == [selectedTitle])
#expect(labels.first { $0.text == selectedTitle }?.textColor == TrainingUI.primary)
#expect(step.bounds.height >= 44)
Attachment.record(render(step), named: "\(Int(width))点-\(selectedTitle)", as: .png)
if width == 320 {
navigation.setOverrideTraitCollection(UITraitCollection(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge), forChild: controller)
navigation.view.layoutIfNeeded()
#expect(first.font.pointSize > 13)
for label in labels {
let frame = label.convert(label.bounds, to: step)
#expect(frame.minY >= 0 && frame.maxY <= step.bounds.height + 1)
#expect(label.sizeThatFits(CGSize(width: label.bounds.width, height: .greatestFiniteMagnitude)).height <= label.bounds.height + 1)
}
Attachment.record(render(step), named: "大字体-\(selectedTitle)", as: .png)
}
if controller === course {
step.configure(mode: .study)
#expect(second.text == "完成学习")
#expect(first.accessibilityTraits.contains(.selected))
}
}
}
}
@Test("未通过成绩可展开解析并返回已有课程,旧失败成绩在通过后不可重考")
func resultLearningAndReviewNavigation() async throws {
let source = TrainingDataStub()
@@ -120,10 +177,10 @@ struct TrainingUIRenderingTests {
#expect(navigation.topViewController === center)
}
private func makeWindow(_ navigation: UINavigationController) throws -> UIWindow {
private func makeWindow(_ navigation: UINavigationController, width: CGFloat = 390) throws -> UIWindow {
let scene = try #require(UIApplication.shared.connectedScenes.first as? UIWindowScene)
let window = UIWindow(windowScene: scene)
window.frame = CGRect(x: 0, y: 0, width: 390, height: 844)
window.frame = CGRect(x: 0, y: 0, width: width, height: 844)
window.rootViewController = navigation
window.makeKeyAndVisible()
navigation.view.layoutIfNeeded()