This commit is contained in:
zyronon
2024-05-22 18:13:25 +08:00
parent 25c3797322
commit 943f095200
5 changed files with 59 additions and 59 deletions

View File

@@ -6,62 +6,55 @@ import {isArticle} from "@/hooks/article.ts";
import {nanoid} from "nanoid";
export function useWordOptions() {
const store = useBaseStore()
function isWordCollect(val: Word) {
return !!store.collect.originWords.find(v => v.word.toLowerCase() === val.word.toLowerCase())
return !!store.collectWord.find(v => v.word.toLowerCase() === val.word.toLowerCase())
}
function toggleWordCollect(val: Word) {
let rIndex = store.collect.originWords.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.collectWord.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.collect.originWords.splice(rIndex, 1)
store.collectWord.splice(rIndex, 1)
} else {
let rIndex = store.simple.originWords.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.simple2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.simple.originWords.splice(rIndex, 1)
store.simple2.splice(rIndex, 1)
}
store.collect.originWords.push(val)
store.collectWord.push(val)
}
store.collect.length = store.collect.originWords.length
}
function isWordSimple(val: Word) {
return !!store.simple.originWords.find(v => v.word.toLowerCase() === val.word.toLowerCase())
return !!store.simple2.find(v => v.word.toLowerCase() === val.word.toLowerCase())
}
function toggleWordSimple(val: Word) {
let rIndex = store.simple.originWords.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.simple2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.simple.originWords.splice(rIndex, 1)
store.simple2.splice(rIndex, 1)
} else {
let rIndex = store.collect.originWords.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.collectWord.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.collect.originWords.splice(rIndex, 1)
store.collectWord.splice(rIndex, 1)
}
store.simple.originWords.push(val)
store.simple2.push(val)
}
store.simple.length = store.simple.originWords.length
}
function delWrongWord(val: Word) {
let rIndex = store.wrong.originWords.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.wrong2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.wrong.originWords.splice(rIndex, 1)
store.wrong2.splice(rIndex, 1)
}
store.wrong.length = store.wrong.originWords.length
}
function delSimpleWord(val: Word) {
let rIndex = store.simple.originWords.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.simple2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.simple.originWords.splice(rIndex, 1)
store.simple2.splice(rIndex, 1)
}
store.simple.length = store.simple.originWords.length
}
return {

View File

@@ -1,7 +1,7 @@
<script setup lang="ts">
import {onMounted, onUnmounted, watch} from "vue"
import {useBaseStore} from "@/stores/base.ts"
import {DefaultDisplayStatistics, DictType, ShortcutKey, Sort, Word} from "../../../../types.ts";
import {DefaultDisplayStatistics, DictType, ShortcutKey, Sort, Word} from "@/types.ts";
import {emitter, EventKey} from "@/utils/eventBus.ts"
import {cloneDeep, reverse, shuffle} from "lodash-es"
import {usePracticeStore} from "@/stores/practice.ts"
@@ -12,9 +12,8 @@ import Tooltip from "@/pages/pc/components/Tooltip.vue";
import Options from "@/pages/pc/practice/Options.vue";
import Typing from "@/pages/pc/practice/practice-word/Typing.vue";
import Panel from "@/pages/pc/practice/Panel.vue";
import IconWrapper from "@/pages/pc/components/IconWrapper.vue";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {syncMyDictList, useWordOptions} from "@/hooks/dict.ts";
import {useWordOptions} from "@/hooks/dict.ts";
import BaseIcon from "@/components/BaseIcon.vue";
import WordList from "@/pages/pc/components/list/WordList.vue";
import Empty from "@/components/Empty.vue";
@@ -147,8 +146,8 @@ function next(isTyping: boolean = true) {
}
function wordWrong() {
if (!store.wrong.originWords.find((v: Word) => v.word.toLowerCase() === word.word.toLowerCase())) {
store.wrong.originWords.push(word)
if (!store.wrong2.find((v: Word) => v.word.toLowerCase() === word.word.toLowerCase())) {
store.wrong2.push(word)
}
if (!data.wrongWords.find((v: Word) => v.word.toLowerCase() === word.word.toLowerCase())) {
data.wrongWords.push(word)

View File

@@ -21,38 +21,27 @@ let wordData = $ref({
})
function getCurrentPractice() {
if (store.chapter.length) {
if (store.currentWordDict.words?.length) {
wordData.index = 0
wordData.words = cloneDeep(store.chapter)
wordData.words = cloneDeep(store.currentWordDict.words.slice(store.currentStudy.word.lastWordIndex, store.currentStudy.word.lastWordIndex + store.currentStudy.word.perDayStudyNumber))
emitter.emit(EventKey.resetWord)
}
}
//TODO wait
function sort(list: Word[]) {
store.currentDict.chapterWords[store.currentDict.chapterIndex] = wordData.words = list
wordData.index = 0
syncMyDictList(store.currentDict)
}
function next() {
if (store.currentDict.chapterIndex >= store.currentDict.chapterWords.length - 1) {
store.currentDict.chapterIndex = 0
} else store.currentDict.chapterIndex++
getCurrentPractice()
}
onMounted(() => {
getCurrentPractice()
emitter.on(EventKey.changeDict, getCurrentPractice)
emitter.on(EventKey.next, next)
emitter.on(ShortcutKey.NextChapter, next)
})
onUnmounted(() => {
emitter.off(EventKey.changeDict, getCurrentPractice)
emitter.off(EventKey.next, next)
emitter.off(ShortcutKey.NextChapter, next)
})
defineExpose({getCurrentPractice})

View File

@@ -24,9 +24,17 @@ function clickEvent(e) {
我的词典
</div>
<div class="grid flex-1 flex gap-5 mt-4">
<div class="p-4 flex-1 rounded-md bg-slate-200 relative" v-for="i in 3">
<div class="p-4 flex-1 rounded-md bg-slate-200 relative">
<span>收藏</span>
<div class="absolute bottom-4 right-4">333个词</div>
<div class="absolute bottom-4 right-4">{{ base.collectWord.length}}个词</div>
</div>
<div class="p-4 flex-1 rounded-md bg-slate-200 relative">
<span>生词本</span>
<div class="absolute bottom-4 right-4">{{ base.wrong2.length}}个词</div>
</div>
<div class="p-4 flex-1 rounded-md bg-slate-200 relative">
<span>简单词</span>
<div class="absolute bottom-4 right-4">{{ base.simple2.length}}个词</div>
</div>
</div>
</div>
@@ -34,7 +42,7 @@ function clickEvent(e) {
<div class="card ">
<div class="flex justify-between items-center">
<div class="bg-slate-200 p-3 rounded-md cursor-pointer flex items-center">
<span class="text-lg font-bold">{{ base.currentDict.name }}</span>
<span class="text-lg font-bold">{{ base.currentWordDict.name }}</span>
<Icon icon="gg:arrows-exchange" class="text-2xl ml-2"/>
<Icon icon="uil:setting" class="text-2xl ml-2"/>
</div>
@@ -59,7 +67,7 @@ function clickEvent(e) {
更改目标
</div>
</div>
<div class="mt-2 text-xs">学习 50 个单词</div>
<div class="mt-2 text-xs">学习 {{ base.currentStudy.word.perDayStudyNumber }} 个单词</div>
<el-progress class="flex-1 mt-1" :percentage="80" :show-text="false"></el-progress>
</div>
</div>

View File

@@ -18,14 +18,18 @@ export interface BaseState {
simpleWords: string[],
load: boolean
collectWord?: Word[],
collectArticle?: Article[],
simple?: Word[],
wrong?: Word[],
collectWord?: Word[],
simple2?: Word[],
wrong2?: Word[],
articleDictList?: Dict[]
wordDictList?: Dict[],
currentLearn?: {
wordIndex: number,
currentStudy?: {
word: {
dictIndex: number,
perDayStudyNumber: number,
lastWordIndex: number,
},
articleIndex: number,
}
}
@@ -33,8 +37,8 @@ export interface BaseState {
export const DefaultBaseState = (): BaseState => ({
collectWord: [],
collectArticle: [],
simple: [],
wrong: [],
simple2: [],
wrong2: [],
articleDictList: [
{
...cloneDeep(DefaultDict),
@@ -66,9 +70,13 @@ export const DefaultBaseState = (): BaseState => ({
type: DictType.word
},
],
currentLearn: {
wordIndex: 0,
articleIndex: 0
currentStudy: {
word: {
dictIndex: 0,
perDayStudyNumber: 30,
lastWordIndex: 0,
},
articleIndex: 0,
},
myDictList: [
@@ -143,7 +151,7 @@ export const DefaultBaseState = (): BaseState => ({
current: {
index: 4,
// dictType: DictType.article,
// index: 0,
// dictIndex: 0,
practiceType: DictType.article,
},
simpleWords: [
@@ -188,6 +196,9 @@ export const useBaseStore = defineStore('base', {
currentDict(): Dict {
return this.myDictList[this.current.index] ?? {}
},
currentWordDict(): Dict {
return this.wordDictList[this.currentStudy.word.dictIndex] ?? {}
},
chapter(state: BaseState): Word[] {
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
},
@@ -289,7 +300,7 @@ export const useBaseStore = defineStore('base', {
}
}
let currentDict = this.wordDictList[this.currentLearn.wordIndex]
let currentDict = this.wordDictList[this.currentStudy.word.dictIndex]
let dictResourceUrl = `./dicts/${currentDict.language}/${currentDict.type}/${currentDict.translateLanguage}/${currentDict.url}`;
if (!currentDict.originWords.length) {
let v = await getDictFile(dictResourceUrl)
@@ -302,7 +313,7 @@ export const useBaseStore = defineStore('base', {
currentDict.chapterWords = chunk(currentDict.words, currentDict.chapterWordNumber)
}
console.log('this.wordDictList',this.wordDictList)
console.log('this.wordDictList', this.wordDictList)
emitter.emit(EventKey.changeDict)
resolve(true)
})