diff --git a/frontend/src/views/exam/practice.vue b/frontend/src/views/exam/practice.vue index cb39519..bc70dfd 100644 --- a/frontend/src/views/exam/practice.vue +++ b/frontend/src/views/exam/practice.vue @@ -1184,10 +1184,15 @@ const formatCorrectAnswer = (question: any) => { if (question.type === 'single' || question.type === 'multiple') { // 如果有correctAnswer字段(来自Dify的原始correct) if (question.correctAnswer) { - // 多选题格式优化:将 "A:xxx,B:xxx" 改为换行显示 - // 匹配 ",A:" 或 ",B:" 等格式,在逗号后的选项字母前换行 - const formatted = question.correctAnswer.replace(/,([A-Za-z][::])/g, '\n$1') - return formatted + // 多选题格式优化:将 "A:xxx、B:xxx" 或 "A:xxx,B:xxx" 改为换行显示 + // 使用更精确的匹配:提取完整的选项格式 X:内容 + const optionPattern = /([A-Za-z][::])([^A-Za-z]*?)(?=(?:[,、]?[A-Za-z][::])|$)/g + const matches = [...question.correctAnswer.matchAll(optionPattern)] + if (matches.length > 1) { + // 多个选项,换行显示 + return matches.map(m => m[1] + m[2].trim()).join('\n') + } + return question.correctAnswer } // 否则从options中提取 return question.options