This commit is contained in:
zyronon
2024-05-25 22:43:59 +08:00
parent aa20b159e9
commit 80da09e1db
6 changed files with 634 additions and 270 deletions

View File

@@ -35,7 +35,7 @@
"sentence-splitter": "^4.2.1",
"tesseract.js": "^4.1.1",
"vant": "^4.8.1",
"vue": "^3.3.4",
"vue": "^3.4.27",
"vue-activity-calendar": "^1.2.2",
"vue-i18n": "9",
"vue-router": "4",
@@ -64,7 +64,7 @@
"unplugin-auto-import": "^0.16.6",
"unplugin-vue-components": "^0.25.2",
"unplugin-vue-define-options": "^1.4.1",
"vite": "^4.4.5",
"vite": "^5.2.11",
"vue-tsc": "^1.8.5",
"xlsx": "^0.18.5"
},

712
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import {DictResource,} from "@/types.ts";
import {DictResource, getDefaultDict, Sort,} from "@/types.ts";
import {dictionaryResources} from "@/assets/dictionary.ts";
import {groupBy} from "lodash-es";
import {useBaseStore} from "@/stores/base.ts";
@@ -11,6 +11,7 @@ import deFlag from "@/assets/img/flags/de.png";
import codeFlag from "@/assets/img/flags/code.png";
import BaseIcon from "@/components/BaseIcon.vue";
import {useRouter} from "vue-router";
import {useNav} from "@/utils";
const emit = defineEmits<{
add: [],
@@ -67,7 +68,14 @@ const languageCategoryOptions = [
{id: 'code', name: 'Code', flag: codeFlag},
]
const router = useRouter()
const {nav, back} = useNav()
function change(e) {
console.log('e', e.dict)
e.dict.sort = Sort.normal
store.changeWordDict(getDefaultDict(e.dict))
ElMessage.success('切换成功')
}
</script>
<template>
@@ -75,7 +83,7 @@ const router = useRouter()
<header class="flex justify-center pb-3">
<div class="container2 flex justify-between items-center">
<div class="flex items-center gap-5">
<BaseIcon icon="ion:chevron-back" @click="router.back"/>
<BaseIcon icon="ion:chevron-back" title="返回" @click="back"/>
<div class="tabs">
<div class="tab"
:class="currentLanguage === item.id && 'active'"
@@ -100,7 +108,7 @@ const router = useRouter()
<DictGroup
v-for="item in groupedByCategoryAndTag"
:select-id="store.currentDict.id"
@selectDict="e => emit('selectDict',e)"
@selectDict="change"
:groupByTag="item[1]"
:category="item[0]"
/>
@@ -123,8 +131,10 @@ const router = useRouter()
header {
position: fixed;
top: 0;
left: var(--aside-width);
width: calc(100vw - var(--aside-width));
//left: var(--aside-width);
//width: calc(100vw - var(--aside-width));
left: 0;
width: 100vw;
z-index: 9;
background: var(--color-main-bg);

View File

@@ -7,6 +7,7 @@ import {useRouter} from "vue-router";
import BaseIcon from "@/components/BaseIcon.vue";
import {useNav} from "@/utils";
import BasePage from "@/pages/pc/components/BasePage.vue";
import {watch} from "vue";
const base = useBaseStore()
const router = useRouter()
@@ -15,6 +16,11 @@ const {nav} = useNav()
function clickEvent(e) {
console.log('e', e)
}
watch(() => base.currentStudyWordProgress, n => {
console.log('n', n)
}, {immediate: true})
</script>
<template>
@@ -44,16 +50,22 @@ function clickEvent(e) {
<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.currentStudyWordDict.name }}</span>
<Icon icon="gg:arrows-exchange" class="text-2xl ml-2"/>
<Icon icon="uil:setting" class="text-2xl ml-2"/>
<BaseIcon
title="切换词典"
icon="gg:arrows-exchange"
class="ml-2"
@click="router.push('/dict')"/>
</div>
<div class="rounded-xl bg-slate-800 flex items-center py-3 px-5 text-white cursor-pointer"
@click="router.push('study-word')">
开始学习
</div>
</div>
<div class="mt-5 text-sm">已学习5555个单词的1%</div>
<el-progress class="mt-1" :percentage="80" :show-text="false"></el-progress>
<div class="mt-5 text-sm">已学习{{
base.currentStudyWordDict.words.length
}}个单词的{{ base.currentStudyWordProgress }}%
</div>
<el-progress class="mt-1" :percentage="base.currentStudyWordProgress" :show-text="false"></el-progress>
</div>
<div class="card flex gap-3">
<div class="bg-slate-200 w-10 h-10 flex center text-2xl rounded">
@@ -80,7 +92,9 @@ function clickEvent(e) {
<div class="title">
其他学习词典
</div>
<BaseIcon icon="ic:round-add" @click="router.push('/dict')"/>
<BaseIcon icon="ic:round-add"
title="切换词典"
@click="router.push('/dict')"/>
</div>
<div class="grid grid-cols-2 gap-6 mt-5 ">
<div class=" p-4 rounded-md justify-between items-center bg-slate-200 " v-for="i in 3">

View File

@@ -135,7 +135,7 @@ export const DefaultBaseState = (): BaseState => ({
word: {
dictIndex: 0,
perDayStudyNumber: 30,
lastLearnIndex: 0,
lastLearnIndex: 10,
},
article: {
dictIndex: 0,
@@ -263,6 +263,10 @@ export const useBaseStore = defineStore('base', {
currentStudyWordDict(): Dict {
return this.wordDictList[this.currentStudy.word.dictIndex] ?? {}
},
currentStudyWordProgress(): number {
if (!this.currentStudyWordDict.words?.length) return 0
return Number(((this.currentStudy.word.lastLearnIndex / this.currentStudyWordDict.words?.length) * 100).toFixed())
},
currentArticleDict(): Dict {
return this.articleDictList[this.currentStudy.article.dictIndex] ?? {}
},
@@ -447,6 +451,111 @@ export const useBaseStore = defineStore('base', {
}
emitter.emit(EventKey.changeDict)
}
},
async changeWordDict(dict: Dict) {
if ([DictType.collect,
DictType.simple,
DictType.wrong].includes(dict.type)) {
} else {
//TODO 需要和其他需要下载的地方统一
let url = `./dicts/${dict.language}/${dict.type}/${dict.translateLanguage}/${dict.url}`;
//如果不是自定义词典并且有url地址才去下载
if (!dict.isCustom && dict.url) {
if (!dict.originWords.length) {
let v = await getDictFile(url)
v.map(s => {
s.id = nanoid(6)
})
dict.originWords = cloneDeep(v)
if (dict.sort === Sort.normal) {
dict.words = cloneDeep(dict.originWords)
} else if (dict.sort === Sort.random) {
dict.words = shuffle(dict.originWords)
} else {
dict.words = reverse(dict.originWords)
}
}
}
}
console.log('changeDict', cloneDeep(dict),)
// await checkDictHasTranslate(dict)
let rIndex = this.wordDictList.findIndex((v: Dict) => v.id === dict.id)
if (rIndex > -1) {
this.wordDictList[rIndex] = dict
this.currentStudy.word.dictIndex = rIndex
} else {
this.wordDictList.push(cloneDeep(dict))
this.currentStudy.word.dictIndex = this.wordDictList.length - 1
}
this.currentStudy.word.lastLearnIndex = 0
emitter.emit(EventKey.changeDict)
},
async changeArticleDict(dict: Dict) {
//TODO 保存统计
// this.saveStatistics()
console.log('changeDict', cloneDeep(dict),)
if ([DictType.collect,
DictType.simple,
DictType.wrong].includes(dict.type)) {
} else {
//TODO 需要和其他需要下载的地方统一
let url = `./dicts/${dict.language}/${dict.type}/${dict.translateLanguage}/${dict.url}`;
if (dict.type === DictType.article) {
if (!dict.articles.length) {
let r = await fetch(url)
let v = await r.json()
v.map(s => {
s.id = nanoid(6)
})
dict.articles = cloneDeep(v)
} else {
dict.length = dict.articles.length
}
if (chapterIndex > dict.articles.length) {
dict.chapterIndex = 0
dict.wordIndex = 0
}
} else {
//如果不是自定义词典并且有url地址才去下载
if (!dict.isCustom && dict.url) {
if (!dict.originWords.length) {
let v = await getDictFile(url)
v.map(s => {
s.id = nanoid(6)
})
dict.originWords = cloneDeep(v)
if (dict.sort === Sort.normal) {
dict.words = cloneDeep(dict.originWords)
} else if (dict.sort === Sort.random) {
dict.words = shuffle(dict.originWords)
} else {
dict.words = reverse(dict.originWords)
}
dict.words.map(v => v.checked = false)
dict.chapterWords = chunk(dict.words, dict.chapterWordNumber)
dict.length = dict.words.length
} else {
dict.length = dict.words.length
}
}
if (chapterIndex > dict.chapterWords.length) {
dict.chapterIndex = 0
dict.wordIndex = 0
}
}
}
// await checkDictHasTranslate(dict)
let rIndex = this.myDictList.findIndex((v: Dict) => v.id === dict.id)
if (rIndex > -1) {
this.myDictList[rIndex] = dict
this.current.index = rIndex
} else {
this.myDictList.push(cloneDeep(dict))
this.current.index = this.myDictList.length - 1
}
emitter.emit(EventKey.changeDict)
},
},
})

View File

@@ -238,6 +238,35 @@ export const DefaultDict: Dict = {
language: 'en',
}
export function getDefaultDict(val = {}): Dict {
return {
id: '',
name: '',
description: '',
sort: Sort.normal,
originWords: [],//原始单词
words: [],
chapterWordNumber: DefaultChapterWordNumber,//章节单词数量
chapterWords: [],
residueWords: [],//未分配单词
chapterIndex: 0,//章节下标
wordIndex: 0,//单词下标
articles: [],
statistics: [],
isCustom: false,
length: 0,
/*资源属性*/
resourceId: '',
url: '',
category: '',
tags: [],
translateLanguage: 'common',
type: DictType.word,
language: 'en',
...val
}
}
export interface Dict {
id: string,
name: string,