|
@@ -381,6 +381,14 @@
|
|
|
console.error('保存答案失败', e);
|
|
console.error('保存答案失败', e);
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
+ // 超时兜底:request.js 的 fail 不 reject,Promise 可能永远 pending
|
|
|
|
|
+ // 用 race 强制在 ms 后 resolve,保证 isSaving 能被 finally 释放
|
|
|
|
|
+ withTimeout(promise, ms = 12000) {
|
|
|
|
|
+ return Promise.race([
|
|
|
|
|
+ promise,
|
|
|
|
|
+ new Promise(resolve => setTimeout(resolve, ms))
|
|
|
|
|
+ ]);
|
|
|
|
|
+ },
|
|
|
async changeQuestion(targetGi, targetQi) {
|
|
async changeQuestion(targetGi, targetQi) {
|
|
|
if (this.isSaving) return;
|
|
if (this.isSaving) return;
|
|
|
if (targetGi === this.groupIndex && targetQi === this.questionIndex) return;
|
|
if (targetGi === this.groupIndex && targetQi === this.questionIndex) return;
|
|
@@ -390,10 +398,10 @@
|
|
|
const prevQi = this.questionIndex;
|
|
const prevQi = this.questionIndex;
|
|
|
this.isSaving = true;
|
|
this.isSaving = true;
|
|
|
try {
|
|
try {
|
|
|
- await this.saveCurrentAnswer();
|
|
|
|
|
|
|
+ await this.withTimeout(this.saveCurrentAnswer());
|
|
|
this.groupIndex = targetGi;
|
|
this.groupIndex = targetGi;
|
|
|
this.questionIndex = targetQi;
|
|
this.questionIndex = targetQi;
|
|
|
- await this.loadQuestion(group.questions[targetQi].snapshotQuestionId);
|
|
|
|
|
|
|
+ await this.withTimeout(this.loadQuestion(group.questions[targetQi].snapshotQuestionId));
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
this.groupIndex = prevGi;
|
|
this.groupIndex = prevGi;
|
|
|
this.questionIndex = prevQi;
|
|
this.questionIndex = prevQi;
|