diff --git a/src/App.vue b/src/App.vue index 9ed555e3..f946a5db 100644 --- a/src/App.vue +++ b/src/App.vue @@ -14,10 +14,19 @@ const word: Word = $computed(() => { return wordList[chapterIndex][wordIndex] }) let input = $ref('') +let wrong = $ref('') function onKeyDown(e: KeyboardEvent) { if (e.keyCode >= 65 && e.keyCode <= 90) { - input += e.key.toLowerCase() + let letter = e.key.toLowerCase() + if (input + letter === word.name.slice(0, input.length + 1)) { + input += letter + } else { + wrong = letter + setTimeout(() => { + wrong = input = '' + }, 1000) + } } } @@ -52,8 +61,9 @@ function playAudio() {
- {{ input }} - {{ word.name.slice(input.length) }} + {{ input }} + {{ wrong }} + {{ word.name.slice(input.length + wrong.length) }}
播放
@@ -75,7 +85,6 @@ function playAudio() { font-size: 14rem; color: gray; - .word-wrapper { display: flex; align-items: center; @@ -86,6 +95,14 @@ function playAudio() { line-height: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace; letter-spacing: 2rem; + + .input { + color: rgba(74, 222, 128, 0.8); + } + + .wrong { + color: rgba(red, 0.6); + } } } }