chore: update

This commit is contained in:
zyronon
2023-09-20 18:28:17 +08:00
parent 84d4b82850
commit 1b2f8a2d45
13 changed files with 331 additions and 222 deletions

View File

@@ -4,7 +4,7 @@ import {$computed, $ref} from "vue/macros"
import {onMounted, onUnmounted} from "vue"
import {useBaseStore} from "@/stores/base.ts"
import Tooltip from "@/components/Tooltip.vue"
import {usePracticeStore} from "@/components/Practice/practice.ts";
import {usePracticeStore} from "@/stores/practice.ts";
import {Icon} from "@iconify/vue";
import {useSettingStore} from "@/stores/setting.ts";

View File

@@ -2,7 +2,7 @@
import Toolbar from "@/components/Toolbar/Toolbar.vue"
import {onMounted, watch} from "vue";
import {usePracticeStore} from "@/components/Practice/practice.ts";
import {usePracticeStore} from "@/stores/practice.ts";
import Footer from "@/components/Practice/Footer.vue";
import TypeWord from "@/components/Practice/TypeWord.vue";
import TypeArticle from "@/components/Practice/TypeArticle.vue";
@@ -11,6 +11,7 @@ import {$ref} from "vue/macros";
import Statistics from "@/components/Practice/Statistics.vue";
import {emitter, EventKey} from "@/utils/eventBus";
import {useSettingStore} from "@/stores/setting";
import {cloneDeep} from "lodash-es";
const practiceStore = usePracticeStore()
const store = useBaseStore()
@@ -1143,7 +1144,12 @@ watch(() => store.load, n => {
})
function getCurrentWords() {
wordData.words = store.chapter
wordData.words = cloneDeep(store.chapter)
wordData.index = 0
}
function getCurrentArticle() {
wordData.words = cloneDeep(store.chapter)
wordData.index = 0
}
@@ -1152,18 +1158,21 @@ onMounted(() => {
})
function write() {
console.log('write')
settingStore.dictation = true
repeat()
}
//TODO 需要判断是否已忽略
function repeat() {
console.log('repeat')
getCurrentWords()
emitter.emit(EventKey.resetWord)
}
//TODO 能否下一章
function next() {
console.log('next')
store.currentDict.chapterIndex++
repeat()
}

View File

@@ -10,7 +10,7 @@ import {emitter, EventKey} from "@/utils/eventBus.ts";
import {onMounted, reactive} from "vue";
import {cloneDeep} from "lodash-es";
import {Icon} from '@iconify/vue';
import {usePracticeStore} from "@/components/Practice/practice.ts";
import {usePracticeStore} from "@/stores/practice.ts";
import {useSettingStore} from "@/stores/setting.ts";
const store = useBaseStore()

View File

@@ -3,7 +3,7 @@ import {computed, nextTick, watchEffect} from "vue"
import {$ref} from "vue/macros";
import {Article, ArticleWord, ShortKeyMap, Word} from "@/types";
import {useBaseStore} from "@/stores/base";
import {usePracticeStore} from "@/components/Practice/practice.ts";
import {usePracticeStore} from "@/stores/practice.ts";
import TypeWord from "@/components/Practice/TypeWord.vue";
import {useSettingStore} from "@/stores/setting.ts";
import {usePlayBeep, usePlayCorrect, usePlayKeyboardAudio, usePlayWordAudio} from "@/hooks/sound.ts";

View File

@@ -6,7 +6,7 @@ import {DictType, DisplayStatistics, ShortKeyMap, Statistics, Word} from "../../
import BaseButton from "@/components/BaseButton.vue";
import {emitter, EventKey} from "@/utils/eventBus.ts"
import {cloneDeep} from "lodash-es"
import {usePracticeStore} from "@/components/Practice/practice.ts"
import {usePracticeStore} from "@/stores/practice.ts"
import {useSettingStore} from "@/stores/setting.ts";
import {usePlayBeep, usePlayCorrect, usePlayKeyboardAudio, usePlayWordAudio} from "@/hooks/sound.ts";
import {useEventListener} from "@/hooks/event.ts";
@@ -111,7 +111,7 @@ function next() {
data.index++
practiceStore.inputNumber++
console.log('这个词完了')
if ([DictType.customDict, DictType.innerDict].includes(store.current.dictType)
if ([DictType.customDict, DictType.publicDict].includes(store.current.dictType)
&& store.skipWordNames.includes(word.name.toLowerCase())) {
next()
}

View File

@@ -32,7 +32,7 @@ onMounted(() => {
return tabIndex = 3;
case DictType.wrongDict:
return tabIndex = 2;
case DictType.innerDict:
case DictType.publicDict:
case DictType.customDict:
return tabIndex = 0;
}
@@ -52,7 +52,7 @@ const newWordDictActiveIndex = computed(() => {
})
const dictActiveIndex = computed(() => {
if (store.current.dictType !== DictType.innerDict) return -1
if (store.current.dictType !== DictType.publicDict) return -1
else {
if (store.current.repeatNumber) {
return store.chapter.findIndex(v => v.name === store.word.name)
@@ -108,7 +108,7 @@ const skipWordDictActiveIndex = computed(() => {
:isActive="store.sideIsOpen && tabIndex === 0"
:list="store.dict.chapterWords[store.dict.chapterIndex]??[]"
:activeIndex="dictActiveIndex"/>
<footer v-if="![DictType.customDict,DictType.innerDict].includes(store.current.dictType)">
<footer v-if="![DictType.customDict,DictType.publicDict].includes(store.current.dictType)">
<PopConfirm
:title="`确认切换?`"
@confirm="store.changeDict(store.dict)"

View File

@@ -40,7 +40,7 @@ async function selectDict(item: Dict) {
currentSelectDict = {
...item,
sort: Sort.normal,
type: DictType.innerDict,
type: DictType.publicDict,
originWords: [],
words: [],
chapterWordNumber: 15,

View File

@@ -16,10 +16,12 @@ import RepeatSetting from "@/components/Toolbar/RepeatSetting.vue";
import TranslateSetting from "@/components/Toolbar/TranslateSetting.vue";
import Add from "@/components/Toolbar/Add.vue";
import {useSettingStore} from "@/stores/setting.ts";
import {usePracticeStore} from "@/stores/practice.ts";
const {toggle} = useTheme()
const store = useBaseStore()
const settingStore = useSettingStore()
const practiceStore = usePracticeStore()
const showFeedbackModal = $ref(false)
const showSettingModal = $ref(false)
@@ -42,7 +44,7 @@ watch(() => settingStore.showToolbar, n => {
<header ref="headerRef">
<div class="content">
<div class="info" @click="showDictModal = true">
{{ store.dictTitle }}
{{ store.dictTitle }} {{ practiceStore.repeatNumber ? ' 复习错词' : ''}}
</div>
<div class="options">
<Tooltip title="切换主题">

View File

@@ -48,7 +48,7 @@ export function splitArticle(article: string, lang: string = 'en', keyboardMap:
article = article.replaceAll(``, '"')
}
// console.log('article', article)
// console.log('articles', articles)
article.split('').map((v, i, arr) => {
switch (v) {
@@ -181,7 +181,7 @@ export function splitCNArticle(article: string, lang: string = 'cn', keyboardMap
let word = cloneDeep({...DefaultArticleWord, name: '', nextSpace: true});
//加\n用于添加最后一段
article += '\n'
// console.log('article', article)
// console.log('articles', articles)
article.split('').map((v, i, arr) => {
switch (v) {

View File

@@ -4,214 +4,238 @@ import {chunk, cloneDeep} from "lodash-es";
import {emitter, EventKey} from "@/utils/eventBus.ts"
export const useBaseStore = defineStore('base', {
state: (): State => {
return {
newWordDict: {
name: '生词本',
sort: Sort.normal,
type: DictType.newDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '',
},
skipWordDict: {
name: '简单词',
sort: Sort.normal,
type: DictType.skipDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '',
},
wrongWordDict: {
name: '错词本',
sort: Sort.normal,
type: DictType.wrongDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '',
},
dict: {
name: '新概念英语-2',
sort: Sort.normal,
type: DictType.innerDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '/dicts/NCE_2.json',
},
oldDicts: [],
current: {
dictType: DictType.innerDict,
words: [],
index: -1,
wrongWords: [],
originWrongWords: [],
repeatNumber: 0,
statistics: {
startDate: -1,
endDate: -1,
spend: -1,
total: -1,
correctRate: -1,
wrongWordNumber: -1,
state: (): State => {
return {
newWordDict: {
name: '生词本',
sort: Sort.normal,
type: DictType.newDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '',
},
skipWordDict: {
name: '简单词',
sort: Sort.normal,
type: DictType.skipDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '',
},
wrongWordDict: {
name: '错词本',
sort: Sort.normal,
type: DictType.wrongDict,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '',
},
// dict: {
// name: '新概念英语-2',
// sort: Sort.normal,
// type: DictType.innerDict,
// originWords: [],
// articles: [],
// words: [],
// chapterWordNumber: 15,
// chapterWords: [],
// chapterIndex: 0,
// chapterWordIndex: 0,
// statistics: [],
// url: '/dicts/NCE_2.json',
// },
dict: {
name: '新概念英语-2',
sort: Sort.normal,
type: DictType.publicArticle,
originWords: [],
articles: [],
words: [],
chapterWordNumber: 15,
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '/articles/NCE_2.json',
},
oldDicts: [],
current: {
dictType: DictType.publicDict,
words: [],
index: -1,
wrongWords: [],
originWrongWords: [],
repeatNumber: 0,
statistics: {
startDate: -1,
endDate: -1,
spend: -1,
total: -1,
correctRate: -1,
wrongWordNumber: -1,
}
},
sideIsOpen: false,
isDictation: true,
simpleWords: [
'a', 'an', 'of', 'and',
'i', 'my', 'you', 'your',
'me', 'am', 'is', 'do', 'are',
'what', 'who', 'where', 'how', 'no', 'yes',
'not', 'did', 'were', 'can', 'could', 'it',
'the', 'to'
],
theme: 'auto',
load: false
}
},
sideIsOpen: false,
isDictation: true,
simpleWords: [
'a', 'an', 'of', 'and',
'i', 'my', 'you', 'your',
'me', 'am', 'is', 'do', 'are',
'what', 'who', 'where', 'how', 'no', 'yes',
'not', 'did', 'were', 'can', 'could', 'it',
'the', 'to'
],
theme: 'auto',
load: false
}
},
getters: {
skipWordNames: (state: State) => {
return state.skipWordDict.originWords.map(v => v.name.toLowerCase())
},
skipWordNamesWithSimpleWords: (state: State) => {
return state.skipWordDict.originWords.map(v => v.name.toLowerCase()).concat(state.simpleWords)
},
currentDict(state: State): Dict {
switch (state.current.dictType) {
case DictType.newDict:
return state.newWordDict
case DictType.skipDict:
return state.skipWordDict
case DictType.wrongDict:
return state.wrongWordDict
case DictType.innerDict:
case DictType.customDict:
return state.dict
}
},
wordIndex(state: State): number {
return this.currentDict.wordIndex
},
chapter(state: State): Word[] {
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
},
word(state: State): Word {
return state.current.words[state.current.index] ?? {
trans: [],
name: '',
usphone: '',
ukphone: '',
}
},
dictTitle(state: State) {
let title = this.currentDict.name
if ([DictType.innerDict, DictType.customDict].includes(this.current.dictType)) {
title += `${this.currentDict.chapterIndex + 1}`
title += this.current.repeatNumber ? ' 复习错词' : ''
}
return title
}
},
actions: {
setState(obj: any) {
for (const [key, value] of Object.entries(obj)) {
this[key] = value
}
// console.log('this/', this)
},
setCurrentWord(words: Word[], restart: boolean = false, index: number = 0) {
this.current.words = cloneDeep(words)
if (restart) {
this.current.repeatNumber = 0
this.current.originWrongWords = []
this.current.statistics = {
startDate: Date.now(),
endDate: -1,
spend: -1,
wordNumber: words.length,
correctRate: -1,
wrongWordNumber: -1,
getters: {
skipWordNames: (state: State) => {
return state.skipWordDict.originWords.map(v => v.name.toLowerCase())
},
skipWordNamesWithSimpleWords: (state: State) => {
return state.skipWordDict.originWords.map(v => v.name.toLowerCase()).concat(state.simpleWords)
},
currentDict(state: State): Dict {
switch (state.current.dictType) {
case DictType.newDict:
return state.newWordDict
case DictType.skipDict:
return state.skipWordDict
case DictType.wrongDict:
return state.wrongWordDict
case DictType.publicDict:
case DictType.publicArticle:
case DictType.customDict:
return state.dict
}
},
wordIndex(state: State): number {
return this.currentDict.wordIndex
},
chapter(state: State): Word[] {
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
},
word(state: State): Word {
return state.current.words[state.current.index] ?? {
trans: [],
name: '',
usphone: '',
ukphone: '',
}
},
dictTitle(state: State) {
let title = this.currentDict.name
if ([DictType.publicDict, DictType.customDict].includes(this.current.dictType)) {
title += `${this.currentDict.chapterIndex + 1}`
}
return title
}
} else {
this.current.repeatNumber++
if (!this.current.originWrongWords.length) {
this.current.originWrongWords = cloneDeep(this.current.wrongWords)
},
actions: {
setState(obj: any) {
for (const [key, value] of Object.entries(obj)) {
this[key] = value
}
// console.log('this/', this)
},
setCurrentWord(words: Word[], restart: boolean = false, index: number = 0) {
this.current.words = cloneDeep(words)
if (restart) {
this.current.repeatNumber = 0
this.current.originWrongWords = []
this.current.statistics = {
startDate: Date.now(),
endDate: -1,
spend: -1,
wordNumber: words.length,
correctRate: -1,
wrongWordNumber: -1,
}
} else {
this.current.repeatNumber++
if (!this.current.originWrongWords.length) {
this.current.originWrongWords = cloneDeep(this.current.wrongWords)
}
this.current.statistics.correctRate = -1
this.current.statistics.wrongWordNumber = -1
}
this.current.index = index
this.current.wrongWords = []
},
async init() {
// let configStr = localStorage.getItem(SaveKey)
// if (configStr) {
// let obj: Config = JSON.parse(configStr)
// this.setState(obj)
// }
if (this.current.dictType === DictType.publicDict) {
let r = await fetch(`/public/${this.dict.url}`)
r.json().then(v => {
this.dict.originWords = cloneDeep(v)
this.dict.words = cloneDeep(v)
this.dict.chapterWords = chunk(this.dict.words, this.dict.chapterWordNumber)
this.setCurrentWord(this.chapter, true)
this.load = true
})
}
if (this.current.dictType === DictType.publicArticle) {
let r = await fetch(`/public/${this.dict.url}`)
r.json().then(v => {
this.dict.originWords = cloneDeep(v)
this.dict.words = cloneDeep(v)
this.dict.chapterWords = chunk(this.dict.words, this.dict.chapterWordNumber)
this.setCurrentWord(this.chapter, true)
this.load = true
})
}
},
saveStatistics(statistics: Statistics) {
if (statistics.spend > 1000 * 10) {
this.currentDict.statistics.push(statistics)
}
},
async changeDict(dict: Dict, chapterIndex: number = dict.chapterIndex, chapterWordIndex: number = dict.chapterWordNumber) {
this.saveStatistics()
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
this.current.dictType = dict.type
if ([DictType.newDict,
DictType.skipDict,
DictType.wrongDict].includes(dict.type)) {
this[dict.type].chapterIndex = chapterIndex
this[dict.type].chapterWordIndex = chapterWordIndex
} else {
this.dict = cloneDeep(dict)
if (dict.originWords.length) {
let r = await fetch(`/public/${this.dict.url}`)
let v = await r.json()
this.dict.originWords = cloneDeep(v)
this.dict.words = cloneDeep(v)
this.dict.chapters = chunk(this.dict.words, this.dict.chapterWordNumber)
}
this.dict.chapterIndex = chapterIndex
this.dict.chapterWordIndex = chapterWordIndex
}
this.setCurrentWord(this.chapter, true, chapterWordIndex)
emitter.emit(EventKey.resetWord)
}
this.current.statistics.correctRate = -1
this.current.statistics.wrongWordNumber = -1
}
this.current.index = index
this.current.wrongWords = []
},
async init() {
// let configStr = localStorage.getItem(SaveKey)
// if (configStr) {
// let obj: Config = JSON.parse(configStr)
// this.setState(obj)
// }
if (this.current.dictType === DictType.innerDict) {
let r = await fetch(`/public/${this.dict.url}`)
r.json().then(v => {
this.dict.originWords = cloneDeep(v)
this.dict.words = cloneDeep(v)
this.dict.chapterWords = chunk(this.dict.words, this.dict.chapterWordNumber)
this.setCurrentWord(this.chapter, true)
this.load = true
})
}
},
saveStatistics(statistics: Statistics) {
if (statistics.spend > 1000 * 10) {
this.currentDict.statistics.push(statistics)
}
},
async changeDict(dict: Dict, chapterIndex: number = dict.chapterIndex, chapterWordIndex: number = dict.chapterWordNumber) {
this.saveStatistics()
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
this.current.dictType = dict.type
if ([DictType.newDict,
DictType.skipDict,
DictType.wrongDict].includes(dict.type)) {
this[dict.type].chapterIndex = chapterIndex
this[dict.type].chapterWordIndex = chapterWordIndex
} else {
this.dict = cloneDeep(dict)
if (dict.originWords.length) {
let r = await fetch(`/public/${this.dict.url}`)
let v = await r.json()
this.dict.originWords = cloneDeep(v)
this.dict.words = cloneDeep(v)
this.dict.chapters = chunk(this.dict.words, this.dict.chapterWordNumber)
}
this.dict.chapterIndex = chapterIndex
this.dict.chapterWordIndex = chapterWordIndex
}
this.setCurrentWord(this.chapter, true, chapterWordIndex)
emitter.emit(EventKey.resetWord)
}
},
})

View File

@@ -15,7 +15,7 @@ export interface PracticeState {
export const usePracticeStore = defineStore('practice', {
state: (): PracticeState => {
return {
// type: 'article',
// type: 'articles',
type: 'word',
wrongWords: [],
repeatNumber: 0,

View File

@@ -86,9 +86,9 @@ export enum DictType {
newDict = 'newDict',
skipDict = 'skipDict',
wrongDict = 'wrongDict',
innerDict = 'innerDict',
publicDict = 'publicDict',
customDict = 'customDict',
innerArticle = 'innerArticle',
publicArticle = 'publicArticle',
customArticle = 'customArticle'
}