From 25b90820f6c9c7d50fd8b34b14f488a9d6cf8b5a Mon Sep 17 00:00:00 2001 From: zyronon Date: Thu, 3 Aug 2023 21:40:10 +0800 Subject: [PATCH] save --- src/App.vue | 56 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/App.vue b/src/App.vue index f946a5db..f5ebad8a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,26 +6,68 @@ import {$ref} from "vue/macros" // import {$ref, $computed} from 'vue/macros' // import MCE_3 from './assets/dicts/NCE_3.json' -type Word = {"name": string, "usphone": string, "ukphone": string, "trans": string[]} -const wordList: Word[][] = chunk(NCE_2 as any, 15) -const chapterIndex = $ref(0) -const wordIndex = $ref(0) -const word: Word = $computed(() => { +type Word = { "name": string, "usphone": string, "ukphone": string, "trans": string[] } +let wordList: Word[][] = chunk(NCE_2 as any, 15) +let chapterIndex = $ref(0) +let wordIndex = $ref(0) +let word: Word = $computed(() => { return wordList[chapterIndex][wordIndex] }) let input = $ref('') let wrong = $ref('') +let skipWordList = $ref([]) +let newWordList = $ref([]) + +function next() { + if (wordIndex === wordList[chapterIndex].length - 1) { + if (chapterIndex !== wordList.length - 1) { + wordIndex = 0 + chapterIndex++ + console.log('这一章节完了') + } else { + console.log('这本书完了') + } + } else { + wordIndex++ + console.log('这个词完了') + } + wrong = input = '' +} function onKeyDown(e: KeyboardEvent) { if (e.keyCode >= 65 && e.keyCode <= 90) { let letter = e.key.toLowerCase() if (input + letter === word.name.slice(0, input.length + 1)) { input += letter + wrong = '' } else { wrong = letter setTimeout(() => { - wrong = input = '' - }, 1000) + wrong = '' + // wrong = input = '' + }, 500) + } + if (input === word.name) { + next() + } + } else { + console.log('e', e) + switch (e.key) { + case 'Backspace': + if (wrong) { + wrong = '' + } else { + input = input.slice(0, -1) + } + break + case 'Enter': + newWordList.push(word) + break + case 'Tab': + e.preventDefault() + skipWordList.push(word) + next() + break } } }