From 30c5236bead86952d53d550aab0769a383c9b150 Mon Sep 17 00:00:00 2001 From: yanlongqi Date: Mon, 10 Nov 2025 11:34:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A1=AB=E7=A9=BA?= =?UTF-8?q?=E9=A2=98=E7=AD=94=E6=A1=88=E5=A4=84=E7=90=86=E7=9A=84=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 自动去除填空题答案的前后空白字符,避免因空格导致判题错误 2. 修复填空题答案显示顺序问题 - 保持原顺序而非排序 问题原因: - 填空题每个空格的位置是固定的,答案顺序不能改变 - 之前对所有数组答案都进行了排序,导致填空题答案显示错位 - 用户输入的空白字符会影响答案匹配 修复方案: - 在答题输入时自动 trim() 每个答案 - 区分填空题和多选题的答案格式化逻辑 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- web/src/components/AnswerResult.tsx | 7 ++++++- web/src/components/QuestionCard.tsx | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/web/src/components/AnswerResult.tsx b/web/src/components/AnswerResult.tsx index a249f41..34582d8 100644 --- a/web/src/components/AnswerResult.tsx +++ b/web/src/components/AnswerResult.tsx @@ -119,8 +119,13 @@ const AnswerResult: React.FC = ({ } } - // 处理数组答案(多选题),按照ABCD顺序排序 + // 处理数组答案 if (Array.isArray(answer)) { + // 填空题:保持原顺序,不排序(因为每个空格的位置是固定的) + if (questionType === 'fill-in-blank') { + return answer.join(', ') + } + // 多选题:按照ABCD顺序排序 return [...answer].sort((a, b) => a.localeCompare(b)).join(', ') } diff --git a/web/src/components/QuestionCard.tsx b/web/src/components/QuestionCard.tsx index 0d61fb8..75b4adb 100644 --- a/web/src/components/QuestionCard.tsx +++ b/web/src/components/QuestionCard.tsx @@ -66,7 +66,9 @@ const QuestionCard: React.FC = ({ const newAnswers = [...fillAnswers] newAnswers[index] = e.target.value setFillAnswers(newAnswers) - onAnswerChange(newAnswers) + // 提交时去掉每个答案的前后空白字符 + const trimmedAnswers = newAnswers.map(ans => ans.trim()) + onAnswerChange(trimmedAnswers) }} disabled={showResult} style={{