This commit is contained in:
zyronon
2023-08-25 18:57:07 +08:00
parent f72438c989
commit 71f4b0e5fd
2 changed files with 63 additions and 6 deletions

View File

@@ -100,6 +100,8 @@ function onKeyUp(e: KeyboardEvent) {
showFullWord = false
}
const wrongWord = $ref([])
async function onKeyDown(e: KeyboardEvent) {
//TODO 还有横杠
if ((e.keyCode >= 65 && e.keyCode <= 90) || e.code === 'Space') {
@@ -109,6 +111,12 @@ async function onKeyDown(e: KeyboardEvent) {
wrong = ''
playKeySound()
} else {
if (!store.wrongDict.wordList.find((v: Word) => v.name === store.word.name)) {
store.wrongDict.wordList.push(store.word)
}
if (!wrongWord.find((v: string) => v === store.word.name)) {
wrongWord.push(store.word.name)
}
wrong = letter
playKeySound()
playBeep()
@@ -121,6 +129,10 @@ async function onKeyDown(e: KeyboardEvent) {
playCorrect()
setTimeout(next, 300)
}
console.log('s',(store.currentDict.wordIndex + 1 - wrongWord.length) / (store.currentDict.wordIndex + 1))
store.lastStatistics.correctRate = Math.trunc(((store.currentDict.wordIndex + 1 - wrongWord.length) / (store.currentDict.wordIndex + 1)) * 100)
store.lastStatistics.correctNumber = store.currentDict.wordIndex - wrongWord.length
} else {
// console.log('e', e)
switch (e.key) {
@@ -202,6 +214,23 @@ const {appearance, toggle} = useThemeColor()
color="rgb(224,231,255)"
:show-text="false"/>
</div>
<div class="stat">
<div class="row">
<div>{{ store.lastStatistics.endDate }}</div>
</div>
<div class="row">
<div>正确率:{{ store.lastStatistics.correctRate }}</div>
</div>
<div class="row">
<div>正确数:{{ store.lastStatistics.correctNumber }}</div>
</div>
<div class="row">
<div>wordIndex:{{ store.currentDict.wordIndex }}</div>
</div>
<div class="row">
<div>wrongWord:{{ wrongWord.length }}</div>
</div>
</div>
</div>
</template>

View File

@@ -1,5 +1,5 @@
import {defineStore} from 'pinia'
import {Config, Dict, DictType, SaveKey, Sort, State, Word} from "../types.ts"
import {Config, Dict, DictType, SaveKey, Sort, State, Statistics, Word} from "../types.ts"
import {chunk, cloneDeep} from "lodash";
export const useBaseStore = defineStore('base', {
@@ -20,7 +20,8 @@ export const useBaseStore = defineStore('base', {
chapterList: [],
chapterIndex: 0,
wordIndex: 0,
dictStatistics: []
dictStatistics: [],
chapterWordNumber: 15
},
skipWordDict: {
type: DictType.skipWordDict,
@@ -37,7 +38,8 @@ export const useBaseStore = defineStore('base', {
chapterList: [],
chapterIndex: 0,
wordIndex: 0,
dictStatistics: []
dictStatistics: [],
chapterWordNumber: 15
},
wrongDict: {
type: DictType.wrongDict,
@@ -54,7 +56,8 @@ export const useBaseStore = defineStore('base', {
chapterList: [],
chapterIndex: 0,
wordIndex: 0,
dictStatistics: []
dictStatistics: [],
chapterWordNumber: 15
},
dict: {
type: DictType.inner,
@@ -72,7 +75,14 @@ export const useBaseStore = defineStore('base', {
chapterIndex: 0,
chapterWordNumber: 15,
wordIndex: 0,
dictStatistics: []
dictStatistics: [
{
startDate: Date.now(),
endDate: -1,
chapterWordNumber: 15,
statistics: []
}
]
},
oldDicts: [],
currentDictType: DictType.inner,
@@ -114,6 +124,15 @@ export const useBaseStore = defineStore('base', {
name: ''
}
},
lastStatistics(): Statistics {
if (this.currentDict.dictStatistics.length) {
let stat = this.currentDict.dictStatistics[this.currentDict.dictStatistics.length - 1]
if (stat.statistics.length) {
return stat.statistics[stat.statistics.length - 1]
}
}
return {} as any
}
},
actions: {
setState(obj: any) {
@@ -142,7 +161,16 @@ export const useBaseStore = defineStore('base', {
this.dict.chapterList = chunk(this.dict.wordList, this.dict.chapterWordNumber)
})
}
this.dictModalIsOpen = false
if (this.dict.dictStatistics.length) {
this.dict.dictStatistics[this.dict.dictStatistics.length - 1].statistics.push({
startDate: Date.now(),//开始日期
endDate: -1,
correctRate: -1,
correctNumber: -1
})
}
this.dict.wordIndex = 0
this.dictModalIsOpen2 = false
},
async changeDict(dict: Dict, chapterIndex: number = -1, wordIndex: number = -1) {