From: words Date: Tue, 11 Aug 2026 02:54:22 +0000 (+0800) Subject: feat: 测试/复习模式强制英文小写输入 X-Git-Url: http://acesimba.cloud/gitweb/?a=commitdiff_plain;h=d4ff3314441530eff8f1422a45a9388af7a97e73;p=words.git feat: 测试/复习模式强制英文小写输入 - sanitize 增加 toLowerCase: 实时压制首字母自动大写 - 输入框只显示小写英文, 中文/全角/emoji 仍被剔除 - 抄写比较改大小写不敏感(5处), 保证 Arctic 等大写词抄写匹配 - 测试答题比较本就 toLowerCase, 无需改 --- diff --git a/backend/db/bcd.db b/backend/db/bcd.db index a82b56e..8a40327 100644 Binary files a/backend/db/bcd.db and b/backend/db/bcd.db differ diff --git a/frontend/src/components/TestMode.js b/frontend/src/components/TestMode.js index 303a741..528e7d1 100644 --- a/frontend/src/components/TestMode.js +++ b/frontend/src/components/TestMode.js @@ -141,7 +141,7 @@ function TestMode() { checkAnswer(); } else if (phase === 'feedback' && isCorrect) { nextWord(); - } else if (phase === 'copy' && copyInput === currentWord.word) { + } else if (phase === 'copy' && copyInput.toLowerCase() === currentWord.word.toLowerCase()) { nextWord(); } else if (phase === 'feedback' && !isCorrect) { showCopy(); @@ -157,6 +157,10 @@ function TestMode() { // 阻止复制/剪切/粘贴/右键,防止单词被复制后粘贴作弊 const blockClipboard = (e) => e.preventDefault(); + // 只保留 ASCII 可见字符并转小写,过滤中文/全角/emoji,同时压制首字母自动大写 + // 即使中文输入法开启或系统自动大写,输入框也只显示小写英文 + const sanitize = (s) => s.replace(/[^\x20-\x7E]/g, '').toLowerCase(); + // 输入框统一属性:强制英文输入、禁用中文输入法/自动大写/自动补全/粘贴 const inputProps = { type: "text", @@ -263,7 +267,7 @@ function TestMode() { setUserInput(e.target.value)} + onChange={(e) => setUserInput(sanitize(e.target.value))} placeholder="请输入英文单词..." className="test-input" {...inputProps} @@ -324,15 +328,15 @@ function TestMode() { setCopyInput(e.target.value)} - className={`copy-input ${copyInput === currentWord.word ? 'correct' : ''}`} + onChange={(e) => setCopyInput(sanitize(e.target.value))} + className={`copy-input ${copyInput.toLowerCase() === currentWord.word.toLowerCase() ? 'correct' : ''}`} placeholder="请在此抄写正确单词..." {...inputProps} /> - - {copyInput === currentWord.word ? '✅' : '❌'} + + {copyInput.toLowerCase() === currentWord.word.toLowerCase() ? '✅' : '❌'} - {copyInput === currentWord.word && ( + {copyInput.toLowerCase() === currentWord.word.toLowerCase() && (