fix(training): 优化答题交互并消除按钮置灰闪动
This commit is contained in:
@@ -167,19 +167,25 @@ final class TrainingRemoteExamViewModel {
|
||||
} catch { report(error) }
|
||||
}
|
||||
|
||||
/// 计算本次点击的展示选择,不提前修改已确认答案或草稿版本。
|
||||
func selectionPreview(optionID: String) -> Set<String>? {
|
||||
guard canEdit, let question = currentQuestion,
|
||||
question.options.contains(where: { $0.id == optionID }) else { return nil }
|
||||
var selected = currentSelectedIDs
|
||||
if question.type == .single { selected = [optionID] }
|
||||
else if selected.contains(optionID) { selected.remove(optionID) }
|
||||
else { selected.insert(optionID) }
|
||||
return selected
|
||||
}
|
||||
|
||||
/// 增量保存当前一题,网络结果未知时保留原 ID 和完整请求供重试。
|
||||
func select(optionID: String, service: any TrainingDataServing) async {
|
||||
guard canEdit, let question = currentQuestion, let paper,
|
||||
question.options.contains(where: { $0.id == optionID }) else { return }
|
||||
guard let selected = selectionPreview(optionID: optionID), let question = currentQuestion, let paper else { return }
|
||||
isBusy = true
|
||||
errorMessage = nil
|
||||
defer { isBusy = false }
|
||||
do {
|
||||
try await authorize()
|
||||
var selected = currentSelectedIDs
|
||||
if question.type == .single { selected = [optionID] }
|
||||
else if selected.contains(optionID) { selected.remove(optionID) }
|
||||
else { selected.insert(optionID) }
|
||||
pendingMutation = .save(TrainingDraftSaveRequest(requestID: UUID().uuidString, paperSnapshotID: paper.id,
|
||||
baseRevision: draftRevision, lastQuestionOrder: question.order,
|
||||
changes: [TrainingDraftChange(questionID: question.id, selectedOptionIDs: selected.sorted())]))
|
||||
|
||||
Reference in New Issue
Block a user