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