]> acesimba.cloud Git - words.git/commitdiff
修复闪记重试输入框残留旧字符,确保所有输入框出现时为空
authorroot <root@localhost.localdomain>
Thu, 18 Jun 2026 00:15:57 +0000 (08:15 +0800)
committerroot <root@localhost.localdomain>
Thu, 18 Jun 2026 00:15:57 +0000 (08:15 +0800)
frontend/src/components/StudyMode.js
frontend/src/components/TestMode.js

index 66122d1f112f2bcbafac735b8b19cf4aa31236b8..13545a78e0983944668ef78425f64ac8fa6cd151 100644 (file)
@@ -87,6 +87,7 @@ function StudyMode() {
         if (userInput.toLowerCase().trim() === currentWord.word.toLowerCase().trim()) {
             handleNext();
         } else {
+            setUserInput("");           // 清空闪记输入框,确保回到闪记时为空
             setPhase('correction');
             setCorrectionInput("");
             // 错误时读一遍正确发音提醒
@@ -97,6 +98,12 @@ function StudyMode() {
         }
     };
 
+    // 抄写正确后回到闪记模式重试
+    const retryFlashcard = () => {
+        setUserInput("");
+        setPhase('flashcard');
+    };
+
     if (!currentWord) return <div className="loading">加载中...</div>;
 
     // 阻止复制/剪切/粘贴/右键,防止单词被复制后粘贴作弊
@@ -176,14 +183,14 @@ function StudyMode() {
                                 onChange={(e) => setCorrectionInput(e.target.value)}
                                 onKeyDown={(e) => {
                                     if (e.key === 'Enter' && correctionInput === currentWord.word) {
-                                        setPhase('flashcard');
+                                        retryFlashcard();
                                     }
                                 }}
                                 placeholder="请在此抄写..."
                                 {...inputProps}
                             />
                             {correctionInput === currentWord.word && (
-                                <button className="action-btn" onClick={() => setPhase('flashcard')}>
+                                <button className="action-btn" onClick={retryFlashcard}>
                                     重新尝试 (Enter)
                                 </button>
                             )}
index 9c255844bd3386292f66081aeef0a2e07ed141b2..5d5c52ffe2ff53e907d983e456390a52c57789eb 100644 (file)
@@ -39,6 +39,7 @@ function TestMode() {
         setTotalCount(shuffled.length);
         setPhase('testing');
         setUserInput("");
+        setCopyInput("");
         setIsRetesting(false);
     }, [words]);
 
@@ -93,6 +94,7 @@ function TestMode() {
         if (currentIndex + 1 < queue.length) {
             setCurrentIndex(prev => prev + 1);
             setUserInput("");
+            setCopyInput("");
             setPhase('testing');
         } else {
             // 本轮结束
@@ -114,6 +116,7 @@ function TestMode() {
         setCurrentIndex(0);
         setTotalCount(retestWords.length);
         setUserInput("");
+        setCopyInput("");
         setPhase('testing');
         setIsRetesting(true);
     }, [wrongQueue]);