]> acesimba.cloud Git - words.git/commitdiff
feat: 测试/复习模式强制英文小写输入
authorwords <words@local>
Tue, 11 Aug 2026 02:54:22 +0000 (10:54 +0800)
committerwords <words@local>
Tue, 11 Aug 2026 02:54:22 +0000 (10:54 +0800)
- sanitize 增加 toLowerCase: 实时压制首字母自动大写
- 输入框只显示小写英文, 中文/全角/emoji 仍被剔除
- 抄写比较改大小写不敏感(5处), 保证 Arctic 等大写词抄写匹配
- 测试答题比较本就 toLowerCase, 无需改

backend/db/bcd.db
frontend/src/components/TestMode.js

index a82b56e446dd1fdac4193cad89740d988a88082c..8a40327e441909e8a9060075f4217e7c1e97d254 100644 (file)
Binary files a/backend/db/bcd.db and b/backend/db/bcd.db differ
index 303a741bf9d5c048b8f4741de8e1fae58c181cc5..528e7d19baa5cff13380fa4dda0ba1f4121d42b7 100644 (file)
@@ -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() {
                                 <input
                                     ref={inputRef}
                                     value={userInput}
-                                    onChange={(e) => setUserInput(e.target.value)}
+                                    onChange={(e) => setUserInput(sanitize(e.target.value))}
                                     placeholder="请输入英文单词..."
                                     className="test-input"
                                     {...inputProps}
@@ -324,15 +328,15 @@ function TestMode() {
                             <input
                                 ref={copyRef}
                                 value={copyInput}
-                                onChange={(e) => 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}
                             />
-                            <span className={`copy-check ${copyInput === currentWord.word ? 'ok' : ''}`}>
-                                {copyInput === currentWord.word ? '✅' : '❌'}
+                            <span className={`copy-check ${copyInput.toLowerCase() === currentWord.word.toLowerCase() ? 'ok' : ''}`}>
+                                {copyInput.toLowerCase() === currentWord.word.toLowerCase() ? '✅' : '❌'}
                             </span>
-                            {copyInput === currentWord.word && (
+                            {copyInput.toLowerCase() === currentWord.word.toLowerCase() && (
                                 <button className="action-btn" onClick={nextWord}>
                                     下一词 (Enter)
                                 </button>