feat: update exercise manager to support multi-answer checkboxes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 02:04:07 -06:00
parent 9afb57a9ed
commit 5c9972315c

View File

@@ -24,7 +24,7 @@ const formOrder = ref(0)
const mcqQuestion = ref("") const mcqQuestion = ref("")
const mcqOptions = ref(["", ""]) const mcqOptions = ref(["", ""])
const mcqAnswer = ref(0) const mcqAnswer = ref<number[]>([])
const sortQuestion = ref("") const sortQuestion = ref("")
const sortCode = ref("") const sortCode = ref("")
@@ -44,7 +44,7 @@ function openCreate() {
formOrder.value = exercises.value.length formOrder.value = exercises.value.length
mcqQuestion.value = "" mcqQuestion.value = ""
mcqOptions.value = ["", ""] mcqOptions.value = ["", ""]
mcqAnswer.value = 0 mcqAnswer.value = []
sortQuestion.value = "" sortQuestion.value = ""
sortCode.value = "" sortCode.value = ""
fillQuestion.value = "" fillQuestion.value = ""
@@ -60,7 +60,7 @@ function openEdit(ex: Exercise) {
const d = ex.data as ExerciseMcqData const d = ex.data as ExerciseMcqData
mcqQuestion.value = d.question mcqQuestion.value = d.question
mcqOptions.value = [...d.options] mcqOptions.value = [...d.options]
mcqAnswer.value = d.answer mcqAnswer.value = [...d.answer]
} else if (ex.type === "sort") { } else if (ex.type === "sort") {
const d = ex.data as ExerciseSortData const d = ex.data as ExerciseSortData
sortQuestion.value = d.question sortQuestion.value = d.question
@@ -73,6 +73,12 @@ function openEdit(ex: Exercise) {
showForm.value = true showForm.value = true
} }
function toggleAnswer(i: number) {
const idx = mcqAnswer.value.indexOf(i)
if (idx === -1) mcqAnswer.value.push(i)
else mcqAnswer.value.splice(idx, 1)
}
async function save() { async function save() {
let data: Record<string, unknown> let data: Record<string, unknown>
if (formType.value === "mcq") { if (formType.value === "mcq") {
@@ -218,7 +224,7 @@ function typeTagType(type: string): "success" | "info" | "warning" {
placeholder="下面选项中正确是哪个?" placeholder="下面选项中正确是哪个?"
/> />
</n-form-item> </n-form-item>
<n-form-item label="选项(正确答案前选择单选按钮"> <n-form-item label="选项(勾选所有正确答案)">
<n-space vertical style="width: 100%"> <n-space vertical style="width: 100%">
<n-flex <n-flex
v-for="(opt, i) in mcqOptions" v-for="(opt, i) in mcqOptions"
@@ -226,10 +232,9 @@ function typeTagType(type: string): "success" | "info" | "warning" {
align="center" align="center"
:size="8" :size="8"
> >
<n-radio <n-checkbox
:value="i" :checked="mcqAnswer.includes(i)"
:checked="mcqAnswer === i" @update:checked="toggleAnswer(i)"
@update:checked="$event && (mcqAnswer = i)"
/> />
<n-input <n-input
v-model:value="mcqOptions[i]" v-model:value="mcqOptions[i]"
@@ -242,8 +247,9 @@ function typeTagType(type: string): "success" | "info" | "warning" {
@click=" @click="
() => { () => {
mcqOptions.splice(i, 1) mcqOptions.splice(i, 1)
if (mcqAnswer >= mcqOptions.length) mcqAnswer = mcqAnswer
mcqAnswer = mcqOptions.length - 1 .filter((a) => a !== i)
.map((a) => (a > i ? a - 1 : a))
} }
" "
> >