|
@@ -52,6 +52,7 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
answers: string[] = [];
|
|
answers: string[] = [];
|
|
|
params!: ReadingRouteParams;
|
|
params!: ReadingRouteParams;
|
|
|
private sourceQuestions: ReadingQuestion[] = [];
|
|
private sourceQuestions: ReadingQuestion[] = [];
|
|
|
|
|
+ private latestLogId?: string;
|
|
|
private retryCount = 0;
|
|
private retryCount = 0;
|
|
|
private readonly maxRetry = 5;
|
|
private readonly maxRetry = 5;
|
|
|
private historyPageIndex = 0;
|
|
private historyPageIndex = 0;
|
|
@@ -128,7 +129,8 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
this.saving.set(true);
|
|
this.saving.set(true);
|
|
|
this.saveFailed.set(false);
|
|
this.saveFailed.set(false);
|
|
|
try {
|
|
try {
|
|
|
- await this.reading.saveLog(article, this.questions(), this.answers, score);
|
|
|
|
|
|
|
+ const saved = await this.reading.saveLog(article, this.questions(), this.answers, score);
|
|
|
|
|
+ this.latestLogId = saved.objectId;
|
|
|
this.score.set(score);
|
|
this.score.set(score);
|
|
|
this.submitted.set(true);
|
|
this.submitted.set(true);
|
|
|
this.platform.toast('答题记录已保存', 'success');
|
|
this.platform.toast('答题记录已保存', 'success');
|
|
@@ -150,7 +152,7 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
async reset(): Promise<void> {
|
|
async reset(): Promise<void> {
|
|
|
if (this.saving() || this.legacyIncomplete() || !this.article()) return;
|
|
if (this.saving() || this.legacyIncomplete() || !this.article()) return;
|
|
|
const presentationVersion = `v1-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
const presentationVersion = `v1-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
|
- const params = { ...this.params, presentationVersion };
|
|
|
|
|
|
|
+ const params = { ...this.params, presentationVersion, retryAfterLogId: this.latestLogId };
|
|
|
this.saving.set(true);
|
|
this.saving.set(true);
|
|
|
try {
|
|
try {
|
|
|
const questions = presentReadingQuestions(this.sourceQuestions, `${this.article()!.objectId}:${presentationVersion}`);
|
|
const questions = presentReadingQuestions(this.sourceQuestions, `${this.article()!.objectId}:${presentationVersion}`);
|
|
@@ -178,17 +180,17 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
|
|
|
|
|
async createNewArticle(): Promise<void> {
|
|
async createNewArticle(): Promise<void> {
|
|
|
if (this.legacyIncomplete()) {
|
|
if (this.legacyIncomplete()) {
|
|
|
- const params = { ...this.params, presentationVersion: 'v1', sid: undefined, renew: true, wordList: this.params.wordList.join(','), t: Date.now() };
|
|
|
|
|
|
|
+ const params = { ...this.params, presentationVersion: 'v1', retryAfterLogId: undefined, sid: undefined, renew: true, wordList: this.params.wordList.join(','), t: Date.now() };
|
|
|
const navigated = await this.router.navigate(['/words/reading'], { queryParams: params, replaceUrl: true });
|
|
const navigated = await this.router.navigate(['/words/reading'], { queryParams: params, replaceUrl: true });
|
|
|
if (navigated) {
|
|
if (navigated) {
|
|
|
- this.params = { ...this.params, presentationVersion: 'v1', sid: undefined, renew: true };
|
|
|
|
|
|
|
+ this.params = { ...this.params, presentationVersion: 'v1', retryAfterLogId: undefined, sid: undefined, renew: true };
|
|
|
await this.load();
|
|
await this.load();
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (!this.remainingArticles()) return;
|
|
if (!this.remainingArticles()) return;
|
|
|
await this.router.navigate(['/words/go-reading'], {
|
|
await this.router.navigate(['/words/go-reading'], {
|
|
|
- queryParams: { ...this.params, presentationVersion: 'v1', wordList: this.params.wordList.join(','), type: '随机', theme: '随机', renew: true, t: Date.now() },
|
|
|
|
|
|
|
+ queryParams: { ...this.params, presentationVersion: 'v1', retryAfterLogId: undefined, wordList: this.params.wordList.join(','), type: '随机', theme: '随机', renew: true, t: Date.now() },
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -239,7 +241,7 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
replaceUrl: true,
|
|
replaceUrl: true,
|
|
|
});
|
|
});
|
|
|
if (!navigated) return;
|
|
if (!navigated) return;
|
|
|
- this.params = { ...this.params, ...values, sid: entry.article.objectId, renew:false, presentationVersion: 'v1' };
|
|
|
|
|
|
|
+ this.params = { ...this.params, ...values, sid: entry.article.objectId, renew:false, presentationVersion: 'v1', retryAfterLogId: undefined };
|
|
|
await this.load();
|
|
await this.load();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -289,6 +291,7 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const latest = await this.reading.latestLog(article.objectId);
|
|
const latest = await this.reading.latestLog(article.objectId);
|
|
|
|
|
+ this.latestLogId = latest?.objectId;
|
|
|
let questions = await this.reading.getQuestions(article);
|
|
let questions = await this.reading.getQuestions(article);
|
|
|
if (!latest) {
|
|
if (!latest) {
|
|
|
if (!questions.length) {
|
|
if (!questions.length) {
|
|
@@ -311,7 +314,7 @@ export class ReadingExerciseComponent implements OnInit {
|
|
|
this.params.presentationVersion = normalizeReadingPresentationVersion(this.params.presentationVersion);
|
|
this.params.presentationVersion = normalizeReadingPresentationVersion(this.params.presentationVersion);
|
|
|
this.questions.set(this.legacyIncomplete() ? questions : presentReadingQuestions(questions, `${article.objectId}:${this.params.presentationVersion}`));
|
|
this.questions.set(this.legacyIncomplete() ? questions : presentReadingQuestions(questions, `${article.objectId}:${this.params.presentationVersion}`));
|
|
|
this.answers = new Array(questions.length).fill('');
|
|
this.answers = new Array(questions.length).fill('');
|
|
|
- if (latest) this.restoreAttempt(latest.answer);
|
|
|
|
|
|
|
+ if (latest && (this.legacyIncomplete() || latest.objectId !== this.params.retryAfterLogId)) this.restoreAttempt(latest.answer);
|
|
|
this.retryCount = 0;
|
|
this.retryCount = 0;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
const message = error instanceof Error ? error.message : '阅读内容加载失败';
|
|
const message = error instanceof Error ? error.message : '阅读内容加载失败';
|