dedsudiyu 12 hours ago
parent
commit
ed69eca7d7

+ 16 - 2
pages_safetyEducationExamination/views/exam/mockExamPlay.vue

@@ -100,7 +100,8 @@
 						:key="oi"
 						:key="oi"
 						class="q-option"
 						class="q-option"
 						:class="{ selected: isSelected(opt.optionLabel) }"
 						:class="{ selected: isSelected(opt.optionLabel) }"
-						@click="selectAnswer(oi)"
+						:data-oi="oi"
+						@click="onOptionTap"
 					>
 					>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-content">
 						<view class="q-option-content">
@@ -343,6 +344,10 @@
 				}
 				}
 				this.$set(this.currentQuestion, 'answerTags', tags)
 				this.$set(this.currentQuestion, 'answerTags', tags)
 			},
 			},
+			onOptionTap(e) {
+				const oi = Number(e.currentTarget.dataset.oi)
+				this.selectAnswer(oi)
+			},
 			isSelected(label) {
 			isSelected(label) {
 				const tags = this.currentQuestion.answerTags
 				const tags = this.currentQuestion.answerTags
 				return Array.isArray(tags) && tags.indexOf(label) !== -1
 				return Array.isArray(tags) && tags.indexOf(label) !== -1
@@ -375,9 +380,18 @@
 				this.isSaving = true
 				this.isSaving = true
 				await this.saveCurrentAnswer()
 				await this.saveCurrentAnswer()
 				this.isSaving = false
 				this.isSaving = false
+				const prevGi = this.groupIndex
+				const prevQi = this.questionIndex
 				this.groupIndex = targetGi
 				this.groupIndex = targetGi
 				this.questionIndex = targetQi
 				this.questionIndex = targetQi
-				await this.loadQuestion(group.questions[targetQi].snapshotQuestionId)
+				try {
+					await this.loadQuestion(group.questions[targetQi].snapshotQuestionId)
+				} catch (e) {
+					// 加载失败回滚 index,避免与 currentQuestion 错位
+					this.groupIndex = prevGi
+					this.questionIndex = prevQi
+					uni.showToast({ title: '题目加载失败,请重试', icon: 'none' })
+				}
 			},
 			},
 			selectQuestion(gi, qi) {
 			selectQuestion(gi, qi) {
 				this.changeQuestion(gi, qi)
 				this.changeQuestion(gi, qi)

+ 16 - 2
pages_safetyEducationExamination/views/exam/onlineExamPlay.vue

@@ -80,7 +80,8 @@
 						:key="oi"
 						:key="oi"
 						class="q-option"
 						class="q-option"
 						:class="{ selected: isSelected(opt.optionLabel) }"
 						:class="{ selected: isSelected(opt.optionLabel) }"
-						@click="selectAnswer(oi)"
+						:data-oi="oi"
+						@click="onOptionTap"
 					>
 					>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-label">{{ opt.optionLabel }}</view>
 						<view class="q-option-content">
 						<view class="q-option-content">
@@ -346,6 +347,10 @@
 				}
 				}
 				this.$set(this.currentQuestion, 'answerTags', tags);
 				this.$set(this.currentQuestion, 'answerTags', tags);
 			},
 			},
+			onOptionTap(e) {
+				const oi = Number(e.currentTarget.dataset.oi);
+				this.selectAnswer(oi);
+			},
 			isSelected(label) {
 			isSelected(label) {
 				const tags = this.currentQuestion.answerTags;
 				const tags = this.currentQuestion.answerTags;
 				return Array.isArray(tags) && tags.indexOf(label) !== -1;
 				return Array.isArray(tags) && tags.indexOf(label) !== -1;
@@ -378,9 +383,18 @@
 				this.isSaving = true;
 				this.isSaving = true;
 				await this.saveCurrentAnswer();
 				await this.saveCurrentAnswer();
 				this.isSaving = false;
 				this.isSaving = false;
+				const prevGi = this.groupIndex;
+				const prevQi = this.questionIndex;
 				this.groupIndex = targetGi;
 				this.groupIndex = targetGi;
 				this.questionIndex = targetQi;
 				this.questionIndex = targetQi;
-				await this.loadQuestion(group.questions[targetQi].snapshotQuestionId);
+				try {
+					await this.loadQuestion(group.questions[targetQi].snapshotQuestionId);
+				} catch (e) {
+					// 加载失败则回滚 index,避免 index 与 currentQuestion 错位
+					this.groupIndex = prevGi;
+					this.questionIndex = prevQi;
+					uni.showToast({ title: '题目加载失败,请重试', icon: 'none' });
+				}
 			},
 			},
 			selectQuestion(gi, qi) {
 			selectQuestion(gi, qi) {
 				this.changeQuestion(gi, qi);
 				this.changeQuestion(gi, qi);