From f00dab9c6d90f0cf01e04ccfabc2ebeeb2c59209 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Thu, 23 Apr 2026 06:35:45 -0600 Subject: [PATCH] fix: address code review issues in interactive exercises - ExerciseSort: replace unbounded shuffle recursion with deterministic swap - ExerciseManager: add sortQuestion field so sort exercises have custom questions - index.vue: use Promise.allSettled so exercise fetch failure doesn't break lesson content - ExerciseManager: guard mcqAnswer index after option deletion Co-Authored-By: Claude Sonnet 4.6 --- src/admin/tutorial/components/ExerciseManager.vue | 10 ++++++++-- src/oj/learn/components/ExerciseSort.vue | 3 ++- src/oj/learn/index.vue | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/admin/tutorial/components/ExerciseManager.vue b/src/admin/tutorial/components/ExerciseManager.vue index b41572c..c538ca3 100644 --- a/src/admin/tutorial/components/ExerciseManager.vue +++ b/src/admin/tutorial/components/ExerciseManager.vue @@ -21,6 +21,7 @@ const mcqQuestion = ref("") const mcqOptions = ref(["", ""]) const mcqAnswer = ref(0) +const sortQuestion = ref("") const sortCode = ref("") async function load() { @@ -36,6 +37,7 @@ function openCreate() { mcqQuestion.value = "" mcqOptions.value = ["", ""] mcqAnswer.value = 0 + sortQuestion.value = "" sortCode.value = "" showForm.value = true } @@ -51,6 +53,7 @@ function openEdit(ex: Exercise) { mcqAnswer.value = d.answer } else { const d = ex.data as ExerciseSortData + sortQuestion.value = d.question sortCode.value = d.lines.join("\n") } showForm.value = true @@ -61,7 +64,7 @@ async function save() { formType.value === "mcq" ? { question: mcqQuestion.value, options: mcqOptions.value, answer: mcqAnswer.value } : { - question: "将下列代码行排列为正确顺序", + question: sortQuestion.value || "将下列代码行排列为正确顺序", lines: sortCode.value.split("\n").filter((l) => l.trim() !== ""), } @@ -179,7 +182,7 @@ function typeName(type: string) { @@ -190,6 +193,9 @@ function typeName(type: string) {