dedsudiyu 1 semana atrás
pai
commit
ebd435e4f0

+ 9 - 3
pages_safetyEducationExamination/views/exam/mockExamPlay.vue

@@ -379,14 +379,20 @@
 					console.error('保存答案失败', e)
 				})
 			},
-			// 超时兜底:request.js 的 fail 不 reject,Promise 可能永远 pending
-			// 用 race 强制在 ms 后 resolve,保证 isSaving 能被 finally 释放
+			// saveCurrentAnswer 超时:静默继续,不阻止切题
 			withTimeout(promise, ms = 12000) {
 				return Promise.race([
 					promise,
 					new Promise(resolve => setTimeout(resolve, ms))
 				]);
 			},
+			// loadQuestion 超时:reject,让 catch 回滚 index
+			withTimeoutReject(promise, ms = 12000) {
+				return Promise.race([
+					promise,
+					new Promise((_, reject) => setTimeout(() => reject(new Error('网络超时')), ms))
+				]);
+			},
 			// 切换题目(先保存当前答案)
 			async changeQuestion(targetGi, targetQi) {
 				if (this.isSaving) return
@@ -400,7 +406,7 @@
 					await this.withTimeout(this.saveCurrentAnswer())
 					this.groupIndex = targetGi
 					this.questionIndex = targetQi
-					await this.withTimeout(this.loadQuestion(group.questions[targetQi].snapshotQuestionId))
+					await this.withTimeoutReject(this.loadQuestion(group.questions[targetQi].snapshotQuestionId))
 				} catch (e) {
 					this.groupIndex = prevGi
 					this.questionIndex = prevQi

+ 9 - 3
pages_safetyEducationExamination/views/exam/onlineExamPlay.vue

@@ -381,14 +381,20 @@
 					console.error('保存答案失败', e);
 				});
 			},
-			// 超时兜底:request.js 的 fail 不 reject,Promise 可能永远 pending
-			// 用 race 强制在 ms 后 resolve,保证 isSaving 能被 finally 释放
+			// saveCurrentAnswer 超时:静默继续,不阻止切题
 			withTimeout(promise, ms = 12000) {
 				return Promise.race([
 					promise,
 					new Promise(resolve => setTimeout(resolve, ms))
 				]);
 			},
+			// loadQuestion 超时:reject,让 catch 回滚 index
+			withTimeoutReject(promise, ms = 12000) {
+				return Promise.race([
+					promise,
+					new Promise((_, reject) => setTimeout(() => reject(new Error('网络超时')), ms))
+				]);
+			},
 			async changeQuestion(targetGi, targetQi) {
 				if (this.isSaving) return;
 				if (targetGi === this.groupIndex && targetQi === this.questionIndex) return;
@@ -401,7 +407,7 @@
 					await this.withTimeout(this.saveCurrentAnswer());
 					this.groupIndex = targetGi;
 					this.questionIndex = targetQi;
-					await this.withTimeout(this.loadQuestion(group.questions[targetQi].snapshotQuestionId));
+					await this.withTimeoutReject(this.loadQuestion(group.questions[targetQi].snapshotQuestionId));
 				} catch (e) {
 					this.groupIndex = prevGi;
 					this.questionIndex = prevQi;