fix: 修复填空题答案处理的两个问题
1. 自动去除填空题答案的前后空白字符,避免因空格导致判题错误 2. 修复填空题答案显示顺序问题 - 保持原顺序而非排序 问题原因: - 填空题每个空格的位置是固定的,答案顺序不能改变 - 之前对所有数组答案都进行了排序,导致填空题答案显示错位 - 用户输入的空白字符会影响答案匹配 修复方案: - 在答题输入时自动 trim() 每个答案 - 区分填空题和多选题的答案格式化逻辑 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
aaf1b78f3f
commit
30c5236bea
@ -119,8 +119,13 @@ const AnswerResult: React.FC<AnswerResultProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理数组答案(多选题),按照ABCD顺序排序
|
// 处理数组答案
|
||||||
if (Array.isArray(answer)) {
|
if (Array.isArray(answer)) {
|
||||||
|
// 填空题:保持原顺序,不排序(因为每个空格的位置是固定的)
|
||||||
|
if (questionType === 'fill-in-blank') {
|
||||||
|
return answer.join(', ')
|
||||||
|
}
|
||||||
|
// 多选题:按照ABCD顺序排序
|
||||||
return [...answer].sort((a, b) => a.localeCompare(b)).join(', ')
|
return [...answer].sort((a, b) => a.localeCompare(b)).join(', ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,9 @@ const QuestionCard: React.FC<QuestionCardProps> = ({
|
|||||||
const newAnswers = [...fillAnswers]
|
const newAnswers = [...fillAnswers]
|
||||||
newAnswers[index] = e.target.value
|
newAnswers[index] = e.target.value
|
||||||
setFillAnswers(newAnswers)
|
setFillAnswers(newAnswers)
|
||||||
onAnswerChange(newAnswers)
|
// 提交时去掉每个答案的前后空白字符
|
||||||
|
const trimmedAnswers = newAnswers.map(ans => ans.trim())
|
||||||
|
onAnswerChange(trimmedAnswers)
|
||||||
}}
|
}}
|
||||||
disabled={showResult}
|
disabled={showResult}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user