This commit is contained in:
zyronon
2024-06-01 03:15:07 +08:00
parent d5495679ff
commit 380a13410e
7 changed files with 192 additions and 195 deletions

View File

@@ -8,50 +8,50 @@ export function useWordOptions() {
const store = useBaseStore()
function isWordCollect(val: Word) {
return !!store.collectWord.find(v => v.word.toLowerCase() === val.word.toLowerCase())
return !!store.collectWord.words.find(v => v.word.toLowerCase() === val.word.toLowerCase())
}
function toggleWordCollect(val: Word) {
let rIndex = store.collectWord.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.collectWord.words.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.collectWord.splice(rIndex, 1)
store.collectWord.words.splice(rIndex, 1)
} else {
let rIndex = store.simple2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.simple.words.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.simple2.splice(rIndex, 1)
store.simple.words.splice(rIndex, 1)
}
store.collectWord.push(val)
store.collectWord.words.push(val)
}
}
function isWordSimple(val: Word) {
return !!store.simple2.find(v => v.word.toLowerCase() === val.word.toLowerCase())
return !!store.simple.words.find(v => v.word.toLowerCase() === val.word.toLowerCase())
}
function toggleWordSimple(val: Word) {
let rIndex = store.simple2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.simple.words.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.simple2.splice(rIndex, 1)
store.simple.words.splice(rIndex, 1)
} else {
let rIndex = store.collectWord.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.collectWord.words.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.collectWord.splice(rIndex, 1)
store.collectWord.words.splice(rIndex, 1)
}
store.simple2.push(val)
store.simple.words.push(val)
}
}
function delWrongWord(val: Word) {
let rIndex = store.wrong2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.wrong.words.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.wrong2.splice(rIndex, 1)
store.wrong.words.splice(rIndex, 1)
}
}
function delSimpleWord(val: Word) {
let rIndex = store.simple2.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
let rIndex = store.simple.words.findIndex(v => v.word.toLowerCase() === val.word.toLowerCase())
if (rIndex > -1) {
store.simple2.splice(rIndex, 1)
store.simple.words.splice(rIndex, 1)
}
}
@@ -69,15 +69,15 @@ export function useArticleOptions() {
const store = useBaseStore()
function isArticleCollect(val: Article) {
return !!store.collectArticle.find(v => v.title.toLowerCase() === val.title.toLowerCase())
return !!store.collectArticle.articles.find(v => v.title.toLowerCase() === val.title.toLowerCase())
}
function toggleArticleCollect(val: Article) {
let rIndex = store.collectArticle.findIndex(v => v.title.toLowerCase() === val.title.toLowerCase())
let rIndex = store.collectArticle.articles.findIndex(v => v.title.toLowerCase() === val.title.toLowerCase())
if (rIndex > -1) {
store.collectArticle.splice(rIndex, 1)
store.collectArticle.articles.splice(rIndex, 1)
} else {
store.collectArticle.push(val)
store.collectArticle.articles.push(val)
}
}
@@ -110,13 +110,12 @@ export function getCurrentStudyWord() {
console.time()
const store = useBaseStore()
let data = {new: [], review: [], write: []}
let c = store.currentStudy.word
let dict = store.currentStudyWordDict;
if (dict.words?.length) {
for (let i = c.lastLearnIndex; i < dict.words.length; i++) {
if (data.new.length >= c.perDayStudyNumber) break
for (let i = dict.lastLearnIndex; i < dict.words.length; i++) {
if (data.new.length >= dict.perDayStudyNumber) break
let item = dict.words[i]
if (!store.simple2.map(v => v.word.toLowerCase()).includes(item.word.toLowerCase())) {
if (!store.simple.words.map(v => v.word.toLowerCase()).includes(item.word.toLowerCase())) {
data.new.push(item)
}
}
@@ -126,12 +125,12 @@ export function getCurrentStudyWord() {
return dict.words.slice(startIndex, endIndex)
}
let s = c.lastLearnIndex - c.perDayStudyNumber
let e = c.lastLearnIndex
let s = dict.lastLearnIndex - dict.perDayStudyNumber
let e = dict.lastLearnIndex
//取上一次学习的单词用于复习
let list = getList(s, e)
list.map(item => {
if (!store.master.map(v => v.word.toLowerCase()).includes(item.word.toLowerCase())) {
if (!store.master.words.map(v => v.word.toLowerCase()).includes(item.word.toLowerCase())) {
data.review.push(item)
}
})
@@ -140,17 +139,17 @@ export function getCurrentStudyWord() {
//取前天至再往前数3天的单词用于默写
Array.from({length: 4}).map((_, j) => {
e = s
s -= c.perDayStudyNumber
s -= dict.perDayStudyNumber
list = getList(s, e)
let d = []
for (let i = 0; i < list.length; i++) {
if (j === 3) {
if (d.length >= c.perDayStudyNumber - data.write.length) break
if (d.length >= dict.perDayStudyNumber - data.write.length) break
} else {
if (d.length >= Math.floor(c.perDayStudyNumber / 4)) break
if (d.length >= Math.floor(dict.perDayStudyNumber / 4)) break
}
let item = list[i]
if (!store.master.map(v => v.word.toLowerCase()).includes(item.word.toLowerCase())) {
if (!store.master.words.map(v => v.word.toLowerCase()).includes(item.word.toLowerCase())) {
d.push(item)
}
}

View File

@@ -23,7 +23,7 @@ import Slide from "@/pages/pc/components/Slide.vue";
import {useNav} from "@/utils";
const props = withDefaults(defineProps<{
type: DictType
type?: DictType
}>(), {
type: DictType.word
})
@@ -69,12 +69,16 @@ const {
const {nav} = useNav()
const showCollectToggleButton = $computed(() => {
if (props.type === DictType.word) return !store.collectWord.length
return !store.collectArticle.length
if (props.type === DictType.word) return store.collectWord.words.length
return store.collectArticle.articles.length
})
function changeCollect(){
function changeCollect() {
if (props.type === DictType.word) {
store.currentStudy.word.dictIndex = -store.collectWord.index
} else {
}
}
</script>
@@ -84,9 +88,10 @@ function changeCollect(){
<header>
<div class="tabs">
<div class="tab" :class="tabIndex === 0 && 'active'" @click="tabIndex = 0">当前</div>
<div class="tab" :class="tabIndex === 1 && 'active'" @click="tabIndex = 1">{{ store.collect.name }}</div>
<div class="tab" :class="tabIndex === 1 && 'active'" @click="tabIndex = 1">收藏</div>
<div class="tab" :class="tabIndex === 2 && 'active'" @click="tabIndex = 2">{{ store.simple.name }}</div>
<div class="tab" :class="tabIndex === 3 && 'active'" @click="tabIndex = 3">{{ store.wrong.name }}</div>
<div class="tab" :class="tabIndex === 4 && 'active'" @click="tabIndex = 4">{{ store.master.name }}</div>
</div>
<Tooltip
:title="`关闭(${settingStore.shortcutKeyMap[ShortcutKey.TogglePanel]})`"
@@ -102,18 +107,18 @@ function changeCollect(){
<div class="panel-page-item">
<div class="list-header">
<div class="left">
<div class="dict-name" v-if="props.type === DictType.word && store.collectWord.length">
{{ store.collectWord.length }}个单词
<div class="dict-name" v-if="props.type === DictType.word && store.collectWord.words.length">
{{ store.collectWord.words.length }}个单词
</div>
<div class="dict-name" v-if="props.type === DictType.article">
{{ store.collectArticle.length }}篇文章
<div class="dict-name" v-if="props.type === DictType.article && store.collectArticle.articles.length">
{{ store.collectArticle.articles.length }}篇文章
</div>
<BaseIcon icon="fluent:add-12-regular" title="添加" @click="nav('edit-word-dict',{type:0})"/>
</div>
<template v-if="showCollectToggleButton">
<PopConfirm
:title="`确认切换?`"
@confirm="changeIndex( store.collect)"
@confirm="changeCollect"
>
<BaseButton size="small">切换</BaseButton>
</PopConfirm>
@@ -121,9 +126,9 @@ function changeCollect(){
</div>
<template v-if="props.type === DictType.word">
<WordList
v-if="store.collectWord.length"
v-if="store.collectWord.words.length"
class="word-list"
:list="store.collectWord">
:list="store.collectWord.words">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"
@@ -136,8 +141,8 @@ function changeCollect(){
</template>
<template v-else>
<ArticleList
v-if="store.collectArticle.length"
:list="store.collectArticle">
v-if="store.collectArticle.articles.length"
:list="store.collectArticle.articles">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"
@@ -154,10 +159,10 @@ function changeCollect(){
<div class="panel-page-item">
<div class="list-header">
<div class="left">
<div class="dict-name">总词数{{ store.simple2.length }}</div>
<div class="dict-name">总词数{{ store.simple.words.length }}</div>
<BaseIcon icon="fluent:add-12-regular" title="添加" @click="nav('edit-word-dict',{type:2})"/>
</div>
<template v-if="store.simple2.length">
<template v-if="store.simple.words.length">
<PopConfirm
:title="`确认切换?`"
@confirm="changeIndex( store.simple)"
@@ -167,9 +172,9 @@ function changeCollect(){
</template>
</div>
<WordList
v-if="store.simple2.length"
v-if="store.simple.words.length"
class="word-list"
:list="store.simple2">
:list="store.simple.words">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"
@@ -182,22 +187,19 @@ function changeCollect(){
</div>
</div>
<div class="slide-item">
<div class="panel-page-item" v-if="store.wrong2.length">
<div class="panel-page-item" v-if="store.wrong.words.length">
<div class="list-header">
<div class="dict-name">总词数{{ store.wrong2.length }}</div>
<template
v-if="store.wrong2.length">
<PopConfirm
:title="`确认切换?`"
@confirm="changeIndex( store.wrong)"
>
<BaseButton size="small">切换</BaseButton>
</PopConfirm>
</template>
<div class="dict-name">总词数{{ store.wrong.words.length }}</div>
<PopConfirm
:title="`确认切换?`"
@confirm="changeIndex( store.wrong)"
>
<BaseButton size="small">切换</BaseButton>
</PopConfirm>
</div>
<WordList
class="word-list"
:list="store.wrong2">
:list="store.wrong.words">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"

View File

@@ -90,27 +90,27 @@ $bg-color: rgb(226, 226, 226);
.pop-confirm-content {
position: fixed;
background: var(--color-tooltip-bg);
padding: 15rem;
border-radius: 4rem;
transform: translate(-50%, calc(-100% - 10rem));
padding: 1rem;
border-radius: .24rem;
transform: translate(-50%, calc(-100% - .6rem));
box-shadow: 0 0 6px 1px var(--color-tooltip-shadow);
z-index: 999;
.text {
color: var(--color-font-1);
text-align: start;
font-size: 14rem;
width: 150rem;
min-width: 150rem;
font-size: .9rem;
width: 9rem;
min-width: 9rem;
}
.options {
margin-top: 15rem;
margin-top: .9rem;
display: flex;
justify-content: flex-end;
align-items: center;
gap: 12rem;
font-size: 12rem;
gap: .7rem;
font-size: .7rem;
div {
cursor: pointer;
@@ -119,8 +119,8 @@ $bg-color: rgb(226, 226, 226);
.main {
color: gray;
background: $bg-color;
padding: 3rem 10rem;
border-radius: 4rem;
padding: .2rem .6rem;
border-radius: .24rem;
}
}
}

View File

@@ -36,12 +36,7 @@ let list = $computed({
onMounted(() => {
switch (Number(route.query.type)) {
case 0:
runtimeStore.editDict = cloneDeep({
...cloneDeep(DefaultDict),
id: nanoid(),
name: '收藏',
words: store.collectWord
})
runtimeStore.editDict = cloneDeep(store.collectWord)
break
case 1:
runtimeStore.editDict = cloneDeep({

View File

@@ -74,11 +74,11 @@ function study() {
<div style="color:#ac6ed1;" class="cursor-pointer" v-if="false">
更改目标
</div>
<div class="text-xs">学习 {{ store.currentStudy.word.perDayStudyNumber }} 个单词</div>
<div class="text-xs">学习 {{ store.currentStudyWordDict.perDayStudyNumber }} 个单词</div>
</div>
</div>
<div class="bg-slate-200 w-10 h-10 flex center text-2xl rounded">
{{ store.currentStudy.word.perDayStudyNumber }}
{{ store.currentStudyWordDict.perDayStudyNumber }}
</div>
</div>
<div class="mt-2">
@@ -89,7 +89,7 @@ function study() {
<div class="mt-2">
<div class="text-sm flex justify-between">
已学习{{ store.currentStudyWordProgress }}%
<span>{{ store.currentStudy.word.lastLearnIndex }} /{{ store.currentStudyWordDict.words.length }}</span>
<span>{{ store.currentStudyWordDict.lastLearnIndex }} /{{ store.currentStudyWordDict.words.length }}</span>
</div>
<el-progress class="mt-1" :percentage="store.currentStudyWordProgress" :show-text="false"></el-progress>
</div>
@@ -131,19 +131,19 @@ function study() {
<div class="grid grid-cols-6 gap-4 mt-4">
<div class="my-dict" @click="nav('edit-word-dict',{type:0})">
<span>收藏</span>
<div class="absolute bottom-4 right-4">{{ store.collectWord.length }}个词</div>
<div class="absolute bottom-4 right-4">{{ store.collectWord.words.length }}个词</div>
</div>
<div class="my-dict" @click="nav('edit-word-dict',{type:1})">
<span>错词本</span>
<div class="absolute bottom-4 right-4">{{ store.wrong2.length }}个词</div>
<div class="absolute bottom-4 right-4">{{ store.wrong.words.length }}个词</div>
</div>
<div class="my-dict" @click="nav('edit-word-dict',{type:2})">
<span>简单词</span>
<div class="absolute bottom-4 right-4">{{ store.simple2.length }}个词</div>
<div class="absolute bottom-4 right-4">{{ store.simple.words.length }}个词</div>
</div>
<div class="my-dict" @click="nav('edit-word-dict',{type:3})">
<span>已掌握</span>
<div class="absolute bottom-4 right-4">{{ store.master.length }}个词</div>
<div class="absolute bottom-4 right-4">{{ store.master.words.length }}个词</div>
</div>
</div>
</div>

View File

@@ -41,75 +41,87 @@ export interface BaseState {
}
export const DefaultBaseState = (): BaseState => ({
collectWord: [
{
"word": "pharmacy",
"trans": [
{
"cn": "n.药房,配药学,药学,制药业,一批备用药品"
}
],
"phonetic0": "ˈfɑ:məsi",
"phonetic1": "ˈfɑ:rməsi"
},
{
"word": "foregone",
"trans": [
{
"cn": "过去的;先前的;预知的;预先决定的"
},
{
"cn": "发生在…之前forego的过去分词"
}
],
"phonetic0": "fɔː'gɒn",
"phonetic1": "'fɔrɡɔn"
},
{
"word": "calculate",
"trans": [
{
"cn": "vt.& vi.计算,估计,打算,计划,旨在"
},
{
"cn": "vt.预测,推测"
}
],
"phonetic0": "ˈkælkjuleɪt",
"phonetic1": "ˈkælkjəˌlet"
},
{
"word": "compete",
"trans": [
{
"cn": "vi.竞赛,竞争,比得上,参加比赛(或竞赛)"
}
],
"phonetic0": "kəmˈpi:t",
"phonetic1": "kəmˈpit"
},
{
"word": "furnish",
"trans": [
{
"cn": "vt.陈设,布置,提供,供应,装修(房屋)"
}
],
"phonetic0": "ˈfɜ:nɪʃ",
"phonetic1": "ˈfɜ:rnɪʃ"
},
],
collectWord: [],
collectArticle: [],
simple2: [],
wrong2: [],
master: [],
commonDictList: [
{type: DictType.collectWord, words: [], statistics: []},
{type: DictType.collectArticle, articles: [], statistics: []},
{type: DictType.simple, words: [], statistics: []},
{type: DictType.wrong, words: [], statistics: []},
{type: DictType.master, words: [], statistics: []},
{
...getDefaultDict(),
index: 1,
name: '收藏', type: DictType.collectWord, words: [
{
"word": "pharmacy",
"trans": [
{
"cn": "n.药房,配药学,药学,制药业,一批备用药品"
}
],
"phonetic0": "ˈfɑ:məsi",
"phonetic1": "ˈfɑ:rməsi"
},
{
"word": "foregone",
"trans": [
{
"cn": "过去的;先前的;预知的;预先决定的"
},
{
"cn": "发生在…之前forego的过去分词"
}
],
"phonetic0": "fɔː'gɒn",
"phonetic1": "'fɔrɡɔn"
},
{
"word": "calculate",
"trans": [
{
"cn": "vt.& vi.计算,估计,打算,计划,旨在"
},
{
"cn": "vt.预测,推测"
}
],
"phonetic0": "ˈkælkjuleɪt",
"phonetic1": "ˈkælkjəˌlet"
},
{
"word": "compete",
"trans": [
{
"cn": "vi.竞赛,竞争,比得上,参加比赛(或竞赛)"
}
],
"phonetic0": "kəmˈpi:t",
"phonetic1": "kəmˈpit"
},
{
"word": "furnish",
"trans": [
{
"cn": "vt.陈设,布置,提供,供应,装修(房屋)"
}
],
"phonetic0": "ˈfɜ:nɪʃ",
"phonetic1": "ˈfɜ:rnɪʃ"
},
], statistics: []
},
{
...getDefaultDict(),
index: 2, name: '收藏', type: DictType.collectArticle, articles: [], statistics: []},
{
...getDefaultDict(),
index: 3, name: '简单词', type: DictType.simple, words: [], statistics: []},
{
...getDefaultDict(),
index: 4, name: '错词', type: DictType.wrong, words: [], statistics: []},
{
...getDefaultDict(),
index: 5, name: '已掌握', type: DictType.master, words: [], statistics: []},
],
articleDictList: [
@@ -130,7 +142,7 @@ export const DefaultBaseState = (): BaseState => ({
],
wordDictList: [
{
...cloneDeep(DefaultDict),
...getDefaultDict(),
id: 'cet4',
name: 'CET-4',
description: '大学英语四级词库',
@@ -146,9 +158,7 @@ export const DefaultBaseState = (): BaseState => ({
],
currentStudy: {
word: {
dictIndex: 0,
perDayStudyNumber: 20,
lastLearnIndex: 100,
dictIndex: -1,
},
article: {
dictIndex: 0,
@@ -249,7 +259,6 @@ export const useBaseStore = defineStore('base', {
collect(): Dict {
return this.myDictList[0]
},
collectWord(): Dict {
return this.commonDictList[0]
},
@@ -284,14 +293,17 @@ export const useBaseStore = defineStore('base', {
return this.myDictList[this.current.index] ?? {}
},
currentStudyWordDict(): Dict {
return this.wordDictList[this.currentStudy.word.dictIndex] ?? getDefaultDict()
if (this.sword.dictIndex >= 0) {
return this.wordDictList[this.currentStudy.word.dictIndex] ?? getDefaultDict()
}
return this.commonDictList[Math.abs(this.currentStudy.word.dictIndex) - 1] ?? getDefaultDict()
},
sword() {
return this.currentStudy.word
},
currentStudyWordProgress(): number {
if (!this.currentStudyWordDict.words?.length) return 0
return Number(((this.currentStudy.word.lastLearnIndex / this.currentStudyWordDict.words?.length) * 100).toFixed())
return Number(((this.currentStudyWordDict.lastLearnIndex / this.currentStudyWordDict.words?.length) * 100).toFixed())
},
otherWordDictList(): Dict[] {
return this.wordDictList.filter(v => this.currentStudyWordDict.id !== v.id)
@@ -345,30 +357,32 @@ export const useBaseStore = defineStore('base', {
}
let currentDict = this.wordDictList[this.currentStudy.word.dictIndex]
let dictResourceUrl = `./dicts/${currentDict.language}/${currentDict.type}/${currentDict.translateLanguage}/${currentDict.url}`;
if (!currentDict.words.length) {
let v = await getDictFile(dictResourceUrl)
// v = v.slice(0, 50)
v.map(s => {
s.id = nanoid(6)
})
// currentDict.originWords = cloneDeep(v)
// currentDict.words = cloneDeep(v)
currentDict.words = Object.freeze(v)
}
if (this.currentStudy.word.dictIndex>=0){
let current = this.currentStudyWordDict
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)
}
currentDict = this.articleDictList[this.currentStudy.article.dictIndex]
dictResourceUrl = `./dicts/${currentDict.language}/${currentDict.type}/${currentDict.translateLanguage}/${currentDict.url}`;
if (!currentDict.articles.length) {
let s = await getDictFile(dictResourceUrl)
currentDict.articles = cloneDeep(s.map(v => {
v.id = nanoid(6)
return 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 => {
v.id = nanoid(6)
return v
}))
}
console.log('this.wordDictList', this.wordDictList[0].words[0])
console.log('this.wordDictList', this.wordDictList[0].words[0])
}
emitter.emit(EventKey.changeDict)
resolve(true)
})

View File

@@ -241,13 +241,7 @@ export const DefaultDict: Dict = {
name: '',
description: '',
sort: Sort.normal,
originWords: [],//原始单词
words: [],
chapterWordNumber: DefaultChapterWordNumber,//章节单词数量
chapterWords: [],
residueWords: [],//未分配单词
chapterIndex: 0,//章节下标
wordIndex: 0,//单词下标
articles: [],
statistics: [],
isCustom: false,
@@ -266,15 +260,11 @@ export function getDefaultDict(val = {}): Dict {
return {
id: '',
name: '',
lastLearnIndex: 0,
perDayStudyNumber: 20,
description: '',
sort: Sort.normal,
originWords: [],//原始单词
words: [],
chapterWordNumber: DefaultChapterWordNumber,//章节单词数量
chapterWords: [],
residueWords: [],//未分配单词
chapterIndex: 0,//章节下标
wordIndex: 0,//单词下标
articles: [],
statistics: [],
isCustom: false,
@@ -294,15 +284,12 @@ export function getDefaultDict(val = {}): Dict {
export interface Dict {
id: string,
name: string,
lastLearnIndex: number,
perDayStudyNumber: number,
description: string,
sort: Sort,
originWords: Word[],//原始单词
words: Word[],
chapterWordNumber: number,//章节单词数量
chapterWords: Word[][],
residueWords: Word[],
chapterIndex: number,//章节下标
wordIndex: number,//单词下标
articles: Article[],
statistics: Statistics[],
isCustom: boolean,