This commit is contained in:
zyronon
2024-05-23 18:40:10 +08:00
parent 943f095200
commit a2fbfb6cbc
8 changed files with 4358 additions and 4995 deletions

9231
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -43,7 +43,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.currentArticleDict.name }}</span>
<Icon icon="gg:arrows-exchange" class="text-2xl ml-2"/>
<Icon icon="uil:setting" class="text-2xl ml-2"/>
</div>

View File

@@ -1,8 +1,12 @@
<script lang="jsx">
import {nextTick} from "vue";
import {Teleport, Transition} from 'vue'
export default {
name: "PopConfirm",
components: {
Teleport,
Transition
},
props: {
title: {
type: String,
@@ -36,7 +40,7 @@ export default {
e?.stopPropagation()
let rect = e.target.getBoundingClientRect()
this.show = true
nextTick(() => {
this.$nextTick(() => {
let tip = this.$refs?.tip?.getBoundingClientRect()
console.log('rect', rect, tip)
if (!tip) return

View File

@@ -1,7 +1,12 @@
<script lang="jsx">
import {Teleport, Transition} from 'vue'
export default {
name: "Tooltip",
components: {
Teleport,
Transition
},
props: {
title: {
type: String,

View File

@@ -131,9 +131,9 @@ const showCollectToggleButton = $computed(() => {
</div>
<template v-if="practiceType === DictType.word">
<WordList
v-if="store.collect.words.length"
v-if="store.collectWord.length"
class="word-list"
:list="store.collect.words">
:list="store.collectWord">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"
@@ -146,8 +146,8 @@ const showCollectToggleButton = $computed(() => {
</template>
<template v-else>
<ArticleList
v-if="store.collect.articles.length"
:list="store.collect.articles">
v-if="store.collectArticle.length"
:list="store.collectArticle">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"
@@ -164,10 +164,10 @@ const showCollectToggleButton = $computed(() => {
<div class="panel-page-item">
<div class="list-header">
<div class="left">
<div class="dict-name">总词数{{ store.simple.words.length }}</div>
<div class="dict-name">总词数{{ store.simple2.length }}</div>
<BaseIcon icon="fluent:add-12-regular" title="添加" @click="addSimple"/>
</div>
<template v-if="store.currentDict.type !== DictType.simple && store.simple.words.length">
<template v-if="store.currentDict.type !== DictType.simple && store.simple2.length">
<PopConfirm
:title="`确认切换?`"
@confirm="changeIndex( store.simple)"
@@ -177,9 +177,9 @@ const showCollectToggleButton = $computed(() => {
</template>
</div>
<WordList
v-if="store.simple.words.length"
v-if="store.simple2.length"
class="word-list"
:list="store.simple.words">
:list="store.simple2">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"
@@ -192,11 +192,11 @@ const showCollectToggleButton = $computed(() => {
</div>
</div>
<div class="slide-item">
<div class="panel-page-item" v-if="store.wrong.words.length">
<div class="panel-page-item" v-if="store.wrong2.length">
<div class="list-header">
<div class="dict-name">总词数{{ store.wrong.words.length }}</div>
<div class="dict-name">总词数{{ store.wrong2.length }}</div>
<template
v-if="store.currentDict.type !== DictType.wrong && store.wrong.words.length">
v-if="store.currentDict.type !== DictType.wrong && store.wrong2.length">
<PopConfirm
:title="`确认切换?`"
@confirm="changeIndex( store.wrong)"
@@ -207,7 +207,7 @@ const showCollectToggleButton = $computed(() => {
</div>
<WordList
class="word-list"
:list="store.wrong.words">
:list="store.wrong2">
<template v-slot:suffix="{item,index}">
<BaseIcon
class="del"

View File

@@ -54,17 +54,17 @@ let articleIsActive = $computed(() => tabIndex === 0)
function next() {
if (!articleIsActive) return
if (store.currentDict.chapterIndex >= articleData.articles.length - 1) {
store.currentDict.chapterIndex = 0
} else store.currentDict.chapterIndex++
if (store.currentArticleDict.chapterIndex >= articleData.articles.length - 1) {
store.currentArticleDict.chapterIndex = 0
} else store.currentArticleDict.chapterIndex++
emitter.emit(EventKey.resetWord)
getCurrentPractice()
}
function init() {
if (!store.currentDict.articles.length) return
articleData.articles = cloneDeep(store.currentDict.articles)
if (!store.currentArticleDict.articles.length) return
articleData.articles = cloneDeep(store.currentArticleDict.articles)
getCurrentPractice()
console.log('inin', articleData.article)
@@ -72,7 +72,7 @@ function init() {
function setArticle(val: Article) {
let tempVal = cloneDeep(val)
articleData.articles[store.currentDict.chapterIndex] = tempVal
articleData.articles[store.currentArticleDict.chapterIndex] = tempVal
articleData.article = tempVal
practiceStore.inputWordNumber = 0
practiceStore.wrongWordNumber = 0
@@ -92,12 +92,12 @@ function setArticle(val: Article) {
}
function getCurrentPractice() {
// console.log('store.currentDict',store.currentDict)
// console.log('store.currentArticleDict',store.currentArticleDict)
// return
tabIndex = 0
articleData.article = cloneDeep(DefaultArticle)
let currentArticle = articleData.articles[store.currentDict.chapterIndex]
let currentArticle = articleData.articles[store.currentArticleDict.chapterIndex]
let tempArticle = {...DefaultArticle, ...currentArticle}
// console.log('article', tempArticle)
if (tempArticle.sections.length) {
@@ -165,9 +165,9 @@ function getCurrentPractice() {
function saveArticle(val: Article) {
console.log('saveArticle', val)
showEditArticle = false
let rIndex = store.currentDict.articles.findIndex(v => v.id === val.id)
let rIndex = store.currentArticleDict.articles.findIndex(v => v.id === val.id)
if (rIndex > -1) {
store.currentDict.articles[rIndex] = cloneDeep(val)
store.currentArticleDict.articles[rIndex] = cloneDeep(val)
}
setArticle(val)
}
@@ -232,7 +232,7 @@ function nextWord(word: ArticleWord) {
function handleChangeChapterIndex(val: ArticleItem) {
let rIndex = articleData.articles.findIndex(v => v.id === val.item.id)
if (rIndex > -1) {
store.currentDict.chapterIndex = rIndex
store.currentArticleDict.chapterIndex = rIndex
getCurrentPractice()
}
}
@@ -357,11 +357,11 @@ defineExpose({getCurrentPractice})
@click="emitter.emit(EventKey.openDictModal,'list')"
icon="carbon:change-catalog"/>
<div class="title">
{{ store.currentDict.name }}
{{ store.currentArticleDict.name }}
</div>
<Tooltip
:title="`下一章(${settingStore.shortcutKeyMap[ShortcutKey.NextChapter]})`"
v-if="store.currentDict.chapterIndex < articleData.articles .length - 1">
v-if="store.currentArticleDict.chapterIndex < articleData.articles .length - 1">
<IconWrapper>
<Icon @click="emitter.emit(EventKey.next)" icon="octicon:arrow-right-24"/>
</IconWrapper>

View File

@@ -23,7 +23,7 @@ let wordData = $ref({
function getCurrentPractice() {
if (store.currentWordDict.words?.length) {
wordData.index = 0
wordData.words = cloneDeep(store.currentWordDict.words.slice(store.currentStudy.word.lastWordIndex, store.currentStudy.word.lastWordIndex + store.currentStudy.word.perDayStudyNumber))
wordData.words = cloneDeep(store.currentWordDict.words.slice(store.currentStudy.word.lastLearnIndex, store.currentStudy.word.lastLearnIndex + store.currentStudy.word.perDayStudyNumber))
emitter.emit(EventKey.resetWord)
}
}

View File

@@ -28,9 +28,12 @@ export interface BaseState {
word: {
dictIndex: number,
perDayStudyNumber: number,
lastWordIndex: number,
lastLearnIndex: number,
},
articleIndex: number,
article: {
dictIndex: number,
lastLearnIndex: number,
}
}
}
@@ -74,9 +77,12 @@ export const DefaultBaseState = (): BaseState => ({
word: {
dictIndex: 0,
perDayStudyNumber: 30,
lastWordIndex: 0,
lastLearnIndex: 0,
},
article: {
dictIndex: 0,
lastLearnIndex: 0,
},
articleIndex: 0,
},
myDictList: [
@@ -199,6 +205,9 @@ export const useBaseStore = defineStore('base', {
currentWordDict(): Dict {
return this.wordDictList[this.currentStudy.word.dictIndex] ?? {}
},
currentArticleDict(): Dict {
return this.articleDictList[this.currentStudy.article.dictIndex] ?? {}
},
chapter(state: BaseState): Word[] {
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
},
@@ -239,32 +248,6 @@ export const useBaseStore = defineStore('base', {
}
const runtimeStore = useRuntimeStore()
if (location.href.includes('?mode=article')) {
console.log('文章')
//TODO
let dict = {
...cloneDeep(DefaultDict),
id: 'article_nce2',
name: "新概念英语2-课文",
description: '新概念英语2-课文',
category: '英语学习',
tags: ['新概念英语'],
url: 'NCE_2.json',
translateLanguage: 'common',
language: 'en',
type: DictType.article,
resourceId: 'article_nce2',
length: 96
}
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
}
}
if (this.current.index < 3) {
//前三本词典的isCustom为true。数据全都保存了不需要处理了
@@ -313,7 +296,17 @@ export const useBaseStore = defineStore('base', {
currentDict.chapterWords = chunk(currentDict.words, currentDict.chapterWordNumber)
}
console.log('this.wordDictList', this.wordDictList)
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
}))
}
console.log('this.wordDictList', this.articleDictList)
emitter.emit(EventKey.changeDict)
resolve(true)
})