|
|
@@ -292,10 +292,15 @@
|
|
|
snapshotQuestionId: snapshotQuestionId,
|
|
|
examScene: 2,
|
|
|
})
|
|
|
- this.$set(this, 'currentQuestion', response.data.data)
|
|
|
- this.$set(this, 'viewAnswerShowType', false)
|
|
|
+ if (response.data && response.data.data) {
|
|
|
+ this.$set(this, 'currentQuestion', response.data.data)
|
|
|
+ this.$set(this, 'viewAnswerShowType', false)
|
|
|
+ } else {
|
|
|
+ throw new Error((response.data && response.data.message) || '加载题目失败')
|
|
|
+ }
|
|
|
} catch (e) {
|
|
|
- uni.showToast({ title: '题目加载失败', icon: 'none' })
|
|
|
+ console.error('加载题目失败', e)
|
|
|
+ throw e
|
|
|
}
|
|
|
},
|
|
|
// 同步剩余时间并启动倒计时
|
|
|
@@ -358,14 +363,17 @@
|
|
|
if (!q || !q.snapshotQuestionId) return Promise.resolve()
|
|
|
const tags = Array.isArray(q.answerTags) ? q.answerTags.filter(Boolean) : []
|
|
|
if (tags.length === 0) return Promise.resolve()
|
|
|
+ // 快照当前 index,避免 .then 回调时 index 已切换导致回写到错误的题
|
|
|
+ const gi = this.groupIndex
|
|
|
+ const qi = this.questionIndex
|
|
|
return examUserExamAnswerSave({
|
|
|
attemptId: this.attemptId,
|
|
|
snapshotQuestionId: q.snapshotQuestionId,
|
|
|
userAnswer: tags.join(','),
|
|
|
}).then(response => {
|
|
|
const groups = this.questionTypeGroups
|
|
|
- if (groups[this.groupIndex] && groups[this.groupIndex].questions[this.questionIndex]) {
|
|
|
- this.$set(groups[this.groupIndex].questions[this.questionIndex], 'isCorrect', response.data.data)
|
|
|
+ if (groups[gi] && groups[gi].questions[qi]) {
|
|
|
+ this.$set(groups[gi].questions[qi], 'isCorrect', response.data.data)
|
|
|
}
|
|
|
}).catch(e => {
|
|
|
console.error('保存答案失败', e)
|
|
|
@@ -377,20 +385,20 @@
|
|
|
if (targetGi === this.groupIndex && targetQi === this.questionIndex) return
|
|
|
const group = this.questionTypeGroups[targetGi]
|
|
|
if (!group || !group.questions || !group.questions[targetQi]) return
|
|
|
- this.isSaving = true
|
|
|
- await this.saveCurrentAnswer()
|
|
|
- this.isSaving = false
|
|
|
const prevGi = this.groupIndex
|
|
|
const prevQi = this.questionIndex
|
|
|
- this.groupIndex = targetGi
|
|
|
- this.questionIndex = targetQi
|
|
|
+ this.isSaving = true
|
|
|
try {
|
|
|
+ await this.saveCurrentAnswer()
|
|
|
+ this.groupIndex = targetGi
|
|
|
+ this.questionIndex = targetQi
|
|
|
await this.loadQuestion(group.questions[targetQi].snapshotQuestionId)
|
|
|
} catch (e) {
|
|
|
- // 加载失败回滚 index,避免与 currentQuestion 错位
|
|
|
this.groupIndex = prevGi
|
|
|
this.questionIndex = prevQi
|
|
|
uni.showToast({ title: '题目加载失败,请重试', icon: 'none' })
|
|
|
+ } finally {
|
|
|
+ this.isSaving = false
|
|
|
}
|
|
|
},
|
|
|
selectQuestion(gi, qi) {
|