feat(training): 为请求操作接入通用Loading

This commit is contained in:
2026-10-14 18:07:55 +08:00
parent 8c8ba00778
commit ce6cccf2b7
12 changed files with 1396 additions and 44 deletions
@@ -11,6 +11,7 @@ final class TrainingExamViewController: TrainingBaseViewController {
private var navigationIsScheduled = false
private var hasAppeared = false
private var isPerformingOperation = false
private var requestLoadingToken: UUID?
private var needsReloadOnReturn = false
private var renderedQuestion: TrainingQuestionItem?
private var optionButtons: [String: UIButton] = [:]
@@ -100,7 +101,7 @@ final class TrainingExamViewController: TrainingBaseViewController {
hasAppeared = true
guard !isPerformingOperation, !viewModel.isBusy else { return }
if viewModel.submittedAttempt != nil || viewModel.shouldReturnToCenter {
beginOperation(message: "正在确认考试状态…")
beginOperation(message: "正在确认考试状态…", showsLoading: false)
Task { @MainActor in await viewModel.validateIdentity(); finishOperation() }
return
}
@@ -206,14 +207,19 @@ final class TrainingExamViewController: TrainingBaseViewController {
for button in buttons { button.isUserInteractionEnabled = enabled }
}
private func beginOperation(message: String) {
private func beginOperation(message: String, showsLoading: Bool = true) {
isPerformingOperation = true
if showsLoading { requestLoadingToken = beginRequestLoading() }
setOperationInteractionEnabled(false)
statusLabel.text = message
statusLabel.textColor = AppColor.textSecondary
}
private func finishOperation() {
if let requestLoadingToken {
endRequestLoading(requestLoadingToken)
self.requestLoadingToken = nil
}
isPerformingOperation = false
applyState()
scheduleNavigationIfNeeded()