This commit is contained in:
zyronon
2024-06-05 23:50:16 +08:00
parent 9b5c007514
commit 682b692070
20 changed files with 313 additions and 476 deletions

View File

@@ -4,7 +4,7 @@ import DictPlan from "@/pages/mobile/components/DictPlan.vue";
import NavBar from "@/pages/mobile/components/NavBar.vue";
import {onMounted} from "vue";
import {useRoute} from "vue-router";
import {DefaultDict, Dict} from "@/types.ts";
import {Dict, getDefaultDict} from "@/types.ts";
import {cloneDeep} from "lodash-es";
import {nanoid} from "nanoid";
import {dictionaryResources} from "@/assets/dictionary.ts";
@@ -27,7 +27,7 @@ onMounted(() => {
runtimeStore.editDict = cloneDeep(find)
} else {
runtimeStore.editDict = cloneDeep({
...cloneDeep(DefaultDict),
...getDefaultDict(),
...item,
})
runtimeStore.editDict.id = nanoid(6)

View File

@@ -3,7 +3,7 @@ import {useBaseStore} from "@/stores/base.ts"
import {computed, onMounted, onUnmounted, provide, watch} from "vue"
import {useSettingStore} from "@/stores/setting.ts";
import {emitter, EventKey} from "@/utils/eventBus.ts";
import {emitter, EventKey, useEvent} from "@/utils/eventBus.ts";
import SlideHorizontal from "@/components/slide/SlideHorizontal.vue";
import SlideItem from "@/components/slide/SlideItem.vue";
import CollectList from "@/pages/mobile/components/CollectList.vue";
@@ -21,14 +21,8 @@ watch(() => settingStore.showPanel, n => {
}
})
onMounted(() => {
emitter.on(EventKey.changeDict, () => {
tabIndex = 0
})
})
onUnmounted(() => {
emitter.off(EventKey.changeDict)
useEvent(EventKey.changeDict, () => {
tabIndex = 0
})

View File

@@ -39,26 +39,15 @@ const word: Word = $computed(() => {
})
function getCurrentPractice() {
if (store.chapter.length) {
data.words = store.chapter
data.index = 0
data.words = cloneDeep(store.chapter)
emitter.emit(EventKey.resetWord)
}
}
function sort(list: Word[]) {
store.currentDict.chapterWords[store.currentDict.chapterIndex] = data.words = list
data.index = 0
syncMyDictList(store.currentDict)
}
function nextChapter() {
if (store.currentDict.chapterIndex >= store.currentDict.chapterWords.length - 1) {
store.currentDict.chapterIndex = 0
} else store.currentDict.chapterIndex++
getCurrentPractice()
}
@@ -222,7 +211,6 @@ function unknow() {
<div class="list-header">
<div class="left">
<div class="title">
{{ store.chapterName }}
</div>
<BaseIcon title="切换词典"
@click="emitter.emit(EventKey.openDictModal,'list')"
@@ -249,7 +237,7 @@ function unknow() {
</div>
<BaseIcon icon="bi:arrow-right"
@click="next"
v-if="store.currentDict.chapterIndex < store.currentDict.chapterWords.length - 1"/>
/>
</div>
<div class="right">
{{ data.words.length }}个单词

View File

@@ -318,7 +318,6 @@ onMounted(() => {
<div class="list-header">
<div class="left">
<div class="title">
{{ store.chapterName }}
</div>
<BaseIcon title="切换词典"
@click="emitter.emit(EventKey.openDictModal,'list')"

View File

@@ -7,7 +7,7 @@ import {useBaseStore} from "@/stores/base.ts";
import {onMounted, onUnmounted} from "vue";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {ShortcutKey, Word} from "@/types.ts";
import {emitter, EventKey} from "@/utils/eventBus.ts";
import {emitter, EventKey, useEvent, useEvents} from "@/utils/eventBus.ts";
import {useSettingStore} from "@/stores/setting.ts";
import {syncMyDictList} from "@/hooks/dict.ts";
@@ -29,31 +29,24 @@ function getCurrentPractice() {
}
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)
})
useEvents([
[EventKey.changeDict, getCurrentPractice],
[EventKey.next, next],
[ShortcutKey.NextChapter, next],
])
defineExpose({getCurrentPractice})

View File

@@ -13,7 +13,7 @@ import {Icon} from "@iconify/vue";
import Tooltip from "@/pages/pc/components/Tooltip.vue";
import IconWrapper from "@/pages/pc/components/IconWrapper.vue";
import BaseIcon from "@/components/BaseIcon.vue";
import {emitter, EventKey} from "@/utils/eventBus.ts";
import {emitter, EventKey, useEvent} from "@/utils/eventBus.ts";
import {useRouter} from "vue-router";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {cloneDeep} from "lodash-es";
@@ -46,14 +46,8 @@ function changeIndex(dict: Dict) {
store.changeDict(dict, practiceType)
}
onMounted(() => {
emitter.on(EventKey.changeDict, () => {
tabIndex = 0
})
})
onUnmounted(() => {
emitter.off(EventKey.changeDict)
useEvent(EventKey.changeDict, () => {
tabIndex = 0
})
const {

View File

@@ -5,7 +5,7 @@ import BaseButton from "@/components/BaseButton.vue";
import Empty from "@/components/Empty.vue";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {cloneDeep} from "lodash-es";
import {Article, DefaultArticle, DefaultDict, Dict, DictResource, DictType, Sort, TranslateType} from "@/types.ts";
import {Article, DefaultArticle, Dict, DictResource, DictType, getDefaultDict, Sort, TranslateType} from "@/types.ts";
import {emitter, EventKey} from "@/utils/eventBus.ts";
import EditBatchArticleModal from "@/pages/pc/components/article/EditBatchArticleModal.vue";
import {Icon} from "@iconify/vue";
@@ -58,7 +58,7 @@ async function getDictDetail(val: {
runtimeStore.editDict = cloneDeep(find)
} else {
runtimeStore.editDict = cloneDeep({
...cloneDeep(DefaultDict),
...getDefaultDict(),
...item,
})
runtimeStore.editDict.id = nanoid(6)

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import {DefaultDict, Dict, DictType} from "@/types.ts";
import {Dict, DictType, getDefaultDict} from "@/types.ts";
import {cloneDeep} from "lodash-es";
import {FormInstance, FormRules} from "element-plus";
@@ -54,7 +54,7 @@ async function onSubmit() {
await dictFormRef.validate((valid, fields) => {
if (valid) {
let data: Dict = cloneDeep({
...DefaultDict,
...getDefaultDict(),
...dictForm,
})
//任意修改,都将其变为自定义词典
@@ -100,7 +100,7 @@ onMounted(() => {
})
if (props.isAdd) {
dictForm = cloneDeep(DefaultDict)
dictForm = getDefaultDict()
} else {
dictForm = cloneDeep(runtimeStore.editDict)
}

View File

@@ -3,7 +3,7 @@
import BaseIcon from "@/components/BaseIcon.vue";
import BaseButton from "@/components/BaseButton.vue";
import {assign, chunk, cloneDeep, reverse, shuffle} from "lodash-es";
import {DefaultDict, Dict, DictResource, DictType, Sort, Word} from "@/types.ts";
import {Dict, DictResource, DictType, getDefaultDict, Sort, Word} from "@/types.ts";
import {nanoid} from "nanoid";
import {FormInstance, FormRules} from "element-plus";
import {reactive} from "vue";
@@ -78,7 +78,7 @@ async function getDictDetail(val: {
runtimeStore.editDict = cloneDeep(find)
} else {
runtimeStore.editDict = cloneDeep({
...cloneDeep(DefaultDict),
...getDefaultDict(),
...item,
})
runtimeStore.editDict.id = nanoid(6)

View File

@@ -19,7 +19,7 @@ import {MessageBox} from "@/utils/MessageBox.tsx";
import {useBaseStore} from "@/stores/base.ts";
import EditSingleArticleModal from "@/pages/pc/components/article/EditSingleArticleModal.vue";
import {usePracticeStore} from "@/stores/practice.ts";
import {emitter, EventKey} from "@/utils/eventBus.ts";
import {emitter, EventKey, useEvents} from "@/utils/eventBus.ts";
import IconWrapper from "@/pages/pc/components/IconWrapper.vue";
import {Icon} from "@iconify/vue";
import Tooltip from "@/pages/pc/components/Tooltip.vue";
@@ -284,27 +284,19 @@ function shortcutKeyEdit() {
onMounted(() => {
init()
emitter.on(EventKey.changeDict, init)
emitter.on(EventKey.next, next)
emitter.on(ShortcutKey.NextChapter, next)
emitter.on(ShortcutKey.PlayWordPronunciation, play)
emitter.on(ShortcutKey.ShowWord, show)
emitter.on(ShortcutKey.Next, skip)
emitter.on(ShortcutKey.ToggleCollect, collect)
emitter.on(ShortcutKey.EditArticle, shortcutKeyEdit)
})
onUnmounted(() => {
emitter.off(EventKey.changeDict, init)
emitter.off(EventKey.next, next)
emitter.off(ShortcutKey.NextChapter, next)
emitter.off(ShortcutKey.PlayWordPronunciation, play)
emitter.off(ShortcutKey.ShowWord, show)
emitter.off(ShortcutKey.Next, skip)
emitter.off(ShortcutKey.ToggleCollect, collect)
emitter.off(ShortcutKey.EditArticle, shortcutKeyEdit)
})
useEvents([
[EventKey.changeDict, init],
[EventKey.next, next],
[ShortcutKey.NextChapter, next],
[ShortcutKey.PlayWordPronunciation, play],
[ShortcutKey.ShowWord, show],
[ShortcutKey.Next, skip],
[ShortcutKey.ToggleCollect, collect],
[ShortcutKey.EditArticle, shortcutKeyEdit],
])
defineExpose({getCurrentPractice})

View File

@@ -6,10 +6,9 @@ import {useRoute} from "vue-router";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {useBaseStore} from "@/stores/base.ts";
import {assign, cloneDeep, reverse, shuffle} from "lodash-es";
import {DefaultDict, Sort, Word} from "@/types.ts";
import {Sort, Word} from "@/types.ts";
import {nanoid} from "nanoid";
import BaseIcon from "@/components/BaseIcon.vue";
import {Icon} from "@iconify/vue";
import {useNav} from "@/utils";
import {FormInstance, FormRules} from "element-plus";
import MiniDialog from "@/pages/pc/components/dialog/MiniDialog.vue";
@@ -174,13 +173,11 @@ function sort(type: Sort) {
<template>
<BasePage>
<header class="flex gap-4">
<div class="back" @click.stop="back">
<Icon icon="octicon:arrow-left-24" width="20"/>
</div>
<header class="flex gap-4 items-center">
<BaseIcon @click="back" icon="octicon:arrow-left-24" width="20"/>
<div class="left">
<div class="top">
<div class="title">
<div class="text-xl">
{{ runtimeStore.editDict.name }}
</div>
</div>

View File

@@ -6,12 +6,13 @@ import "vue-activity-calendar/style.css";
import {useRouter} from "vue-router";
import BaseIcon from "@/components/BaseIcon.vue";
import Dialog from "@/pages/pc/components/dialog/Dialog.vue";
import {useNav} from "@/utils";
import {_getAccomplishDate, _getAccomplishDays, useNav} from "@/utils";
import BasePage from "@/pages/pc/components/BasePage.vue";
import {getDefaultDict} from "@/types.ts";
import {onMounted, watch} from "vue";
import {getCurrentStudyWord} from "@/hooks/dict.ts";
import {usePracticeStore} from "@/stores/practice.ts";
import {EventKey, useEvent} from "@/utils/eventBus.ts";
const store = useBaseStore()
const statStore = usePracticeStore()
@@ -34,11 +35,6 @@ let currentStudy = $ref({
review: [],
write: []
})
watch(() => store.load, n => {
if (n) {
currentStudy = getCurrentStudyWord()
}
})
onMounted(() => {
if (!currentStudy.new.length) {
@@ -46,12 +42,21 @@ onMounted(() => {
}
})
useEvent(EventKey.changeDict, () => {
currentStudy = getCurrentStudyWord()
})
function study() {
nav('study-word', {}, currentStudy)
}
let show = $ref(false)
let tempPerDayStudyNumber = $ref(0)
function changePerDayStudyNumber() {
store.sdict.perDayStudyNumber = tempPerDayStudyNumber
currentStudy = getCurrentStudyWord()
}
</script>
<template>
@@ -68,35 +73,27 @@ let tempPerDayStudyNumber = $ref(0)
@click="router.push('/dict')"/>
</div>
<div class="flex-1 flex flex-col justify-end items-end">
<div class="flex gap-3">
<div class="">
<div class="title">
每日目标
</div>
<div class="flex">
<div style="color:#ac6ed1;" class="cursor-pointer" v-if="false">
更改目标
</div>
<div class="text-xs">学习 {{ store.sdict.perDayStudyNumber }} 个单词</div>
</div>
</div>
<div class="flex gap-3 items-center">
每日目标
<div
style="color:#ac6ed1;"
@click="show = true;tempPerDayStudyNumber = store.sdict.perDayStudyNumber"
class="bg-slate-200 w-10 h-10 flex center text-2xl rounded cursor-pointer">
class="bg-slate-200 px-2 h-10 flex center text-2xl rounded cursor-pointer">
{{ store.sdict.perDayStudyNumber }}
</div>
个单词
</div>
<div class="mt-2">
<div>预计完成日期2024-04-01</div>
<div class="mt-2 text-sm">
预计完成日期{{ _getAccomplishDate(store.sdict.words.length, store.sdict.perDayStudyNumber) }}
</div>
</div>
</div>
<div class="mt-2">
<div class="text-sm flex justify-between">
已学习{{ store.currentStudyWordProgress }}%
<span>{{ store.currentStudyWordDict.lastLearnIndex }} /{{
<span>{{ store.currentStudyWordDict.lastLearnIndex }} / {{
store.currentStudyWordDict.words.length
}}</span>
}}</span>
</div>
<el-progress class="mt-1" :percentage="store.currentStudyWordProgress" :show-text="false"></el-progress>
</div>
@@ -205,7 +202,7 @@ let tempPerDayStudyNumber = $ref(0)
<Dialog v-model="show"
title="每日目标"
:footer="true"
@ok="store.sdict.perDayStudyNumber = tempPerDayStudyNumber"
@ok="changePerDayStudyNumber"
>
<div class="target-modal">
<div class="center text-2xl gap-2">
@@ -228,7 +225,7 @@ let tempPerDayStudyNumber = $ref(0)
<div>预计</div>
<span class="text-2xl"
style="color:rgb(176,116,211)">{{
Math.ceil(store.sdict.words.length / tempPerDayStudyNumber)
_getAccomplishDays(store.sdict.words.length, tempPerDayStudyNumber)
}}</span>天完成学习
</div>
<div>

View File

@@ -69,7 +69,7 @@ const router = VueRouter.createRouter({
},
})
router.beforeEach((to, from) => {
router.beforeEach((to: any, from: any) => {
// console.log('beforeEach-to',to.path)
// console.log('beforeEach-from',from.path)
const runtimeStore = useRuntimeStore()

View File

@@ -1,16 +1,14 @@
import {defineStore} from 'pinia'
import {Article, DefaultDict, Dict, DictType, DisplayStatistics, getDefaultDict, Sort, Word} from "../types.ts"
import {chunk, cloneDeep, merge, reverse, shuffle} from "lodash-es";
import {Dict, DictType, getDefaultDict, Sort, Word} from "../types.ts"
import {cloneDeep, merge, reverse, shuffle} from "lodash-es";
import {emitter, EventKey} from "@/utils/eventBus.ts"
import {useRuntimeStore} from "@/stores/runtime.ts";
import * as localforage from "localforage";
import {nanoid} from "nanoid";
import {SAVE_DICT_KEY, SAVE_SETTING_KEY} from "@/utils/const.ts";
import {checkAndUpgradeSaveDict, getDictFile} from "@/utils";
import {SAVE_DICT_KEY} from "@/utils/const.ts";
import {_checkDictWords, checkAndUpgradeSaveDict, getDictFile} from "@/utils";
export interface BaseState {
myDictList: Dict[],
collectDictIds: string[],
current: {
index: number,
practiceType: DictType,//练习类型目前仅词典为collect时判断是练单词还是文章使用
@@ -25,8 +23,6 @@ export interface BaseState {
currentStudy?: {
word: {
dictIndex: number,
perDayStudyNumber: number,
lastLearnIndex: number,
},
article: {
dictIndex: number,
@@ -37,6 +33,7 @@ export interface BaseState {
export const DefaultBaseState = (): BaseState => ({
commonDictList: [
getDefaultDict(),
{
...getDefaultDict(),
index: 1,
@@ -120,7 +117,7 @@ export const DefaultBaseState = (): BaseState => ({
articleDictList: [
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'article_nce2',
name: "新概念英语2-课文",
description: '新概念英语2-课文',
@@ -175,7 +172,7 @@ export const DefaultBaseState = (): BaseState => ({
myDictList: [
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'collect',
name: '收藏',
type: DictType.collect,
@@ -184,7 +181,7 @@ export const DefaultBaseState = (): BaseState => ({
isCustom: true,
},
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'skip',
name: '简单词',
type: DictType.simple,
@@ -192,7 +189,7 @@ export const DefaultBaseState = (): BaseState => ({
isCustom: true,
},
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'wrong',
name: '错词本',
type: DictType.wrong,
@@ -200,7 +197,7 @@ export const DefaultBaseState = (): BaseState => ({
isCustom: true,
},
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'cet4',
name: 'CET-4',
description: '大学英语四级词库',
@@ -213,7 +210,7 @@ export const DefaultBaseState = (): BaseState => ({
type: DictType.word
},
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'article_nce2',
name: "新概念英语2-课文",
description: '新概念英语2-课文',
@@ -226,26 +223,9 @@ export const DefaultBaseState = (): BaseState => ({
resourceId: 'article_nce2',
length: 96
},
// {
// ...cloneDeep(DefaultDict),
// id: 'nce-new-2',
// name: '新概念英语(新版)-2',
// description: '新概念英语新版第二册',
// category: '青少年英语',
// tags: ['新概念英语'],
// url: 'nce-new-2.json',
// translateLanguage: 'common',
// language: 'en',
// type: DictType.word,
// resourceId: 'nce-new-2',
// length: 862
// },
],
collectDictIds: [],
current: {
index: 4,
// dictType: DictType.article,
// dictIndex: 0,
practiceType: DictType.article,
},
simpleWords: [
@@ -324,21 +304,6 @@ export const useBaseStore = defineStore('base', {
chapter(state: BaseState): Word[] {
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
},
chapterName(state: BaseState) {
let title = ''
switch (this.currentDict.type) {
case DictType.collect:
if (state.current.practiceType === DictType.article) {
return `${this.currentDict.chapterIndex + 1}`
}
case DictType.wrong:
case DictType.simple:
return this.currentDict.name
case DictType.word:
return `${this.currentDict.chapterIndex + 1}`
}
return title
}
},
actions: {
setState(obj: any) {
@@ -353,7 +318,7 @@ export const useBaseStore = defineStore('base', {
} else {
let configStr: string = await localforage.getItem(SAVE_DICT_KEY.key)
let data = checkAndUpgradeSaveDict(configStr)
// this.setState(data)
this.setState(data)
}
localforage.setItem(SAVE_DICT_KEY.key, JSON.stringify({val: this.$state, version: SAVE_DICT_KEY.version}))
} catch (e) {
@@ -368,21 +333,9 @@ export const useBaseStore = defineStore('base', {
}
if (this.currentStudy.word.dictIndex >= 0) {
let current = this.currentStudyWordDict
await _checkDictWords(this.currentStudyWordDict)
let current = this.articleDictList[this.currentStudy.article.dictIndex]
let dictResourceUrl = `./dicts/${current.language}/${current.type}/${current.translateLanguage}/${current.url}`;
if (!current.words.length) {
let v = await getDictFile(dictResourceUrl)
// v = v.slice(0, 50)
v.map(s => {
s.id = nanoid(6)
})
// current.originWords = cloneDeep(v)
// current.words = cloneDeep(v)
current.words = Object.freeze(v)
}
current = this.articleDictList[this.currentStudy.article.dictIndex]
dictResourceUrl = `./dicts/${current.language}/${current.type}/${current.translateLanguage}/${current.url}`;
if (!current.articles.length) {
let s = await getDictFile(dictResourceUrl)
current.articles = cloneDeep(s.map(v => {
@@ -398,96 +351,10 @@ export const useBaseStore = defineStore('base', {
})
},
async changeDict(dict: Dict, practiceType?: DictType, chapterIndex?: number, wordIndex?: number) {
//TODO 保存统计
// this.saveStatistics()
console.log('changeDict', cloneDeep(dict), chapterIndex, wordIndex)
if (practiceType === undefined) this.current.practiceType = practiceType
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) {
}
} 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.length = dict.words.length
} else {
dict.length = dict.words.length
}
}
}
}
// 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)
},
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.words.length) {
let v = await getDictFile(url)
v.map(s => {
s.id = nanoid(6)
})
if (dict.sort === Sort.normal) {
dict.words = cloneDeep(v)
} else if (dict.sort === Sort.random) {
dict.words = shuffle(v)
} else {
dict.words = reverse(v)
}
}
}
}
console.log('changeDict', cloneDeep(dict),)
this.wordDictList.map(v => {
v.words = []
})
// await checkDictHasTranslate(dict)
this.wordDictList.map((v) => v.words = [])
// await checkDictHasTranslate(newDict)
let rIndex = this.wordDictList.findIndex((v: Dict) => v.id === dict.id)
if (rIndex > -1) {
this.wordDictList[rIndex] = Object.assign(dict, this.wordDictList[rIndex])
@@ -496,7 +363,9 @@ export const useBaseStore = defineStore('base', {
this.wordDictList.push(getDefaultDict(dict))
this.currentStudy.word.dictIndex = this.wordDictList.length - 1
}
await _checkDictWords(this.currentStudyWordDict)
console.log(' store.currentStudyWordDict', this.currentStudyWordDict)
emitter.emit(EventKey.changeDict)
},
async changeArticleDict(dict: Dict) {
@@ -566,6 +435,7 @@ export const useBaseStore = defineStore('base', {
if (rIndex > -1) {
this.currentStudy.word.dictIndex = rIndex
}
}
},
},
})

View File

@@ -1,6 +1,5 @@
import {defineStore} from "pinia"
import {DefaultDict, Dict} from "@/types.ts";
import {cloneDeep} from "lodash-es";
import {Dict, getDefaultDict} from "@/types.ts";
export interface RuntimeState {
disableEventListener: boolean,
@@ -18,7 +17,7 @@ export const useRuntimeStore = defineStore('runtime', {
routeData: null,
disableEventListener: false,
modalList: [],
editDict: cloneDeep(DefaultDict),
editDict: getDefaultDict(),
showDictModal: false,
showSettingModal: false,
excludeRoutes: [],

View File

@@ -236,26 +236,6 @@ export const languageCategoryOptions = [
{id: 'my', name: '我的', flag: myFlag},
]
export const DefaultDict: Dict = {
id: '',
name: '',
description: '',
sort: Sort.normal,
words: [],
articles: [],
statistics: [],
isCustom: false,
length: 0,
/*资源属性*/
resourceId: '',
url: '',
category: '',
tags: [],
translateLanguage: 'common',
type: DictType.word,
language: 'en',
}
export function getDefaultDict(val = {}): Dict {
return {
id: '',
@@ -288,7 +268,6 @@ export interface Dict {
perDayStudyNumber: number,
description: string,
sort: Sort,
originWords: Word[],//原始单词
words: Word[],
articles: Article[],
statistics: Statistics[],

View File

@@ -30,4 +30,14 @@ export function useEvent(key: string, func: () => void) {
onUnmounted(() => {
emitter.off(key, func)
})
}
export function useEvents(arrs: any[],) {
onMounted(() => {
arrs.map((arr) => emitter.on(arr[0], arr[1]))
})
onUnmounted(() => {
arrs.map((arr) => emitter.off(arr[0], arr[1]))
})
}

View File

@@ -6,6 +6,8 @@ import {Dict, DictType} from "@/types.ts";
import {ArchiveReader, libarchiveWasm} from "libarchive-wasm";
import {useRouter} from "vue-router";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {nanoid} from "nanoid";
import dayjs from 'dayjs'
export function getRandom(a: number, b: number): number {
return Math.random() * (b - a) + a;
@@ -45,41 +47,8 @@ export function checkAndUpgradeSaveDict(val: any) {
}
return defaultBaseState
} else {
if (version <= 3) {
// if (false) {
let temp = (list: any[]): any[] => {
return list.map(a => {
return {
word: a.name,
trans: a.trans.map(b => {
return {
cn: b,
}
}),
phonetic0: a.usphone,
phonetic1: a.ukphone,
}
})
}
state.myDictList.map(v => {
if ([DictType.collect, DictType.simple, DictType.wrong].includes(v.type)) {
v.originWords = temp(v.originWords)
if (v.words) v.words = temp(v.words)
v.chapterWords.map((s, i) => {
v.chapterWords[i] = temp(s)
})
} else {
if (v.isCustom) {
if (v.type === DictType.word) {
v.originWords = temp(v.originWords)
if (v.words) v.words = temp(v.words)
v.chapterWords.map((s, i) => {
v.chapterWords[i] = temp(s)
})
}
}
}
})
if (version <= 4) {
state = defaultBaseState
}
//防止人为删除数据,导致数据不完整报错
for (const [key, value] of Object.entries(defaultBaseState)) {
@@ -236,4 +205,33 @@ export function _dateFormat(val, type?): string {
default:
return `${year}-${mStr}-${dayStr} ${hStr}:${minStr}:${secStr}`
}
}
export async function _checkDictWords(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.words.length) {
let v = await getDictFile(url)
v.map(s => {
s.id = nanoid(6)
})
dict.words = Object.freeze(v)
}
}
}
}
export function _getAccomplishDays(total: number, dayNumber: number) {
return Math.ceil(total / dayNumber)
}
export function _getAccomplishDate(total: number, dayNumber: number) {
let d = _getAccomplishDays(total, dayNumber)
return dayjs().add(d, 'day').format('YYYY-MM-DD')
}