设计文章逻辑

This commit is contained in:
zyronon
2023-09-05 18:44:35 +08:00
parent 0a896804dd
commit 1e7482db9c
6 changed files with 82 additions and 68 deletions

View File

@@ -26,14 +26,14 @@ onMounted(() => {
store.sideIsOpen = !store.sideIsOpen
if (store.sideIsOpen) {
switch (store.current.dictType) {
case DictType.newWordDict:
case DictType.newDict:
return tabIndex = 1;
case DictType.skipWordDict:
case DictType.skipDict:
return tabIndex = 3;
case DictType.wrongWordDict:
case DictType.wrongDict:
return tabIndex = 2;
case DictType.inner:
case DictType.custom:
case DictType.innerDict:
case DictType.customDict:
return tabIndex = 0;
}
}
@@ -42,7 +42,7 @@ onMounted(() => {
const newWordDictActiveIndex = computed(() => {
if (store.current.dictType !== DictType.newWordDict) return -1
if (store.current.dictType !== DictType.newDict) return -1
else {
if (store.current.repeatNumber) {
return store.chapter.findIndex(v => v.name === store.word.name)
@@ -52,7 +52,7 @@ const newWordDictActiveIndex = computed(() => {
})
const dictActiveIndex = computed(() => {
if (store.current.dictType !== DictType.inner) return -1
if (store.current.dictType !== DictType.innerDict) return -1
else {
if (store.current.repeatNumber) {
return store.chapter.findIndex(v => v.name === store.word.name)
@@ -63,7 +63,7 @@ const dictActiveIndex = computed(() => {
const wrongWordDictActiveIndex = computed(() => {
if (store.current.dictType !== DictType.wrongWordDict) return -1
if (store.current.dictType !== DictType.wrongDict) return -1
else {
if (store.current.repeatNumber) {
return store.chapter.findIndex(v => v.name === store.word.name)
@@ -74,7 +74,7 @@ const wrongWordDictActiveIndex = computed(() => {
const skipWordDictActiveIndex = computed(() => {
if (store.current.dictType !== DictType.skipWordDict) return -1
if (store.current.dictType !== DictType.skipDict) return -1
else {
if (store.current.repeatNumber) {
return store.chapter.findIndex(v => v.name === store.word.name)
@@ -106,9 +106,9 @@ const skipWordDictActiveIndex = computed(() => {
class="word-list"
@change="(e:number) => store.changeDict(store.dict,store.dict.chapterIndex,e)"
:isActive="store.sideIsOpen && tabIndex === 0"
:list="store.dict.chapters[store.dict.chapterIndex]??[]"
:list="store.dict.chapterWords[store.dict.chapterIndex]??[]"
:activeIndex="dictActiveIndex"/>
<footer v-if="![DictType.custom,DictType.inner].includes(store.current.dictType)">
<footer v-if="![DictType.customDict,DictType.innerDict].includes(store.current.dictType)">
<PopConfirm
:title="`确认切换?`"
@confirm="store.changeDict(store.dict)"
@@ -129,7 +129,7 @@ const skipWordDictActiveIndex = computed(() => {
:isActive="store.sideIsOpen && tabIndex === 1"
:list="store.newWordDict.words"
:activeIndex="newWordDictActiveIndex"/>
<footer v-if="store.current.dictType !== DictType.newWordDict && store.newWordDict.words.length">
<footer v-if="store.current.dictType !== DictType.newDict && store.newWordDict.words.length">
<PopConfirm
:title="`确认切换?`"
@confirm="store.changeDict(store.newWordDict)"
@@ -152,7 +152,7 @@ const skipWordDictActiveIndex = computed(() => {
:list="store.wrongWordDict.words"
:activeIndex="wrongWordDictActiveIndex"/>
<footer
v-if="store.current.dictType !== DictType.wrongWordDict && store.wrongWordDict.words.length">
v-if="store.current.dictType !== DictType.wrongDict && store.wrongWordDict.words.length">
<PopConfirm
:title="`确认切换?`"
@confirm="store.changeDict(store.wrongWordDict)"
@@ -173,7 +173,7 @@ const skipWordDictActiveIndex = computed(() => {
:isActive="store.sideIsOpen && tabIndex === 3"
:list="store.skipWordDict.words"
:activeIndex="skipWordDictActiveIndex"/>
<footer v-if="store.current.dictType !== DictType.skipWordDict && store.skipWordDict.words.length">
<footer v-if="store.current.dictType !== DictType.skipDict && store.skipWordDict.words.length">
<PopConfirm
:title="`确认切换?`"
@confirm="store.changeDict(store.skipWordDict)"

View File

@@ -39,7 +39,7 @@ watch(() => props.modelValue, (n: boolean) => {
async function selectDict(item: Dict) {
currentSelectDict = {
...item,
type: DictType.inner,
type: DictType.innerDict,
sort: Sort.normal,
wordList: [],
chapterList: [],

View File

@@ -63,7 +63,7 @@ function next() {
if (store.current.wrongWords.length) {
store.setCurrentWord(store.current.wrongWords)
} else {
if (store.currentDict.chapterIndex !== store.currentDict.chapters.length - 1) {
if (store.currentDict.chapterIndex !== store.currentDict.chapterWords.length - 1) {
console.log('这一章节完了')
emitter.emit(EventKey.openStatModal)
} else {
@@ -76,7 +76,7 @@ function next() {
console.log('这个词完了')
}
if ([DictType.custom, DictType.inner].includes(store.current.dictType) && store.skipWordNames.includes(store.word.name)) {
if ([DictType.customDict, DictType.innerDict].includes(store.current.dictType) && store.skipWordNames.includes(store.word.name)) {
next()
}
@@ -106,7 +106,7 @@ async function onKeyDown(e: KeyboardEvent) {
if (!store.wrongWordDict.originWords.find((v: Word) => v.name === store.word.name)) {
store.wrongWordDict.originWords.push(store.word)
store.wrongWordDict.words.push(store.word)
store.wrongWordDict.chapters = [store.wrongWordDict.words]
store.wrongWordDict.chapterWords = [store.wrongWordDict.words]
}
if (!store.current.wrongWords.find((v: Word) => v.name === store.word.name)) {
store.current.wrongWords.push(store.word)
@@ -138,7 +138,7 @@ async function onKeyDown(e: KeyboardEvent) {
if (!store.newWordDict.originWords.find((v: Word) => v.name === store.word.name)) {
store.newWordDict.originWords.push(store.word)
store.newWordDict.words.push(store.word)
store.newWordDict.chapters = [store.newWordDict.words]
store.newWordDict.chapterWords = [store.newWordDict.words]
}
activeIndex = 1
break
@@ -146,7 +146,7 @@ async function onKeyDown(e: KeyboardEvent) {
if (!store.skipWordNames.includes(store.word.name)) {
store.skipWordDict.originWords.push(store.word)
store.skipWordDict.words.push(store.word)
store.skipWordDict.chapters = [store.skipWordDict.words]
store.skipWordDict.chapterWords = [store.skipWordDict.words]
}
activeIndex = 0
next()

View File

@@ -16,7 +16,7 @@ import correct from '../assets/sound/correct.wav'
import {useSound} from "@/hooks/useSound.ts"
import {CnKeyboardMap, useSplitArticle} from "@/hooks/useSplitArticle";
import {$computed, $ref} from "vue/macros";
import {DictType, SaveKey, ShortKeyMap, Word} from "@/types";
import {Article, DictType, SaveKey, Sentence, ShortKeyMap, Word} from "@/types";
import {useBaseStore} from "@/stores/base";
let article1 = `How does the older investor differ in his approach to investment from the younger investor?
@@ -56,18 +56,6 @@ const [playCorrect] = useSound([correct], 1)
const store = useBaseStore()
export interface Sentence {
sentence: string,
words: string[]
}
export interface Article {
sections: Sentence[][],
translate: {
sentence: string,
location: string
}[],
}
let sectionIndex = $ref(0)
let sentenceIndex = $ref(0)
@@ -84,12 +72,23 @@ let hoverIndex = $ref({
})
let article = reactive<Article>({
article: article1,
articleTranslate: `上星期我去看戏。我的座位很好,戏很有意思,但我却无法欣赏。一青年男子与一青年女子坐在我的身后,大声地说着话。我非常生气,因为我听不见演员在说什么。我回过头去,怒视着那一男一女,他们却毫不理会。最后,我忍不住了,又一次回过头去,生气地说,“我一个字也听不见了!”
“不关你的事,”那男的毫不客气地说,“这是私人间的谈话!”`,
newWords: [],
articleAllWords: [],
sections: [],
translate: []
translate: [],
})
const simpleWord = [
'a', 'an', 'of', 'and',
'i', 'my', 'you', 'your',
'me', 'am', 'is', 'do', 'are',
'what', 'who', 'where', 'how', 'no', 'yes',
'not', 'did', 'were', 'can', 'could'
]
onMounted(() => {
let t1 = useSplitArticle(article1)
let t1 = useSplitArticle(article.article)
let wordNumber = 0
t1.map(v => {
v.map(w => {
@@ -101,7 +100,7 @@ onMounted(() => {
setTimeout(() => {
store.current = {
dictType: DictType.inner,
dictType: DictType.innerDict,
words: [],
index: wordIndex,
wrongWords: [],
@@ -117,8 +116,7 @@ onMounted(() => {
}
}
}, 1000)
let a = `上星期我去看戏。我的座位很好,戏很有意思,但我却无法欣赏。一青年男子与一青年女子坐在我的身后,大声地说着话。我非常生气,因为我听不见演员在说什么。我回过头去,怒视着那一男一女,他们却毫不理会。最后,我忍不住了,又一次回过头去,生气地说,“我一个字也听不见了!”
“不关你的事,”那男的毫不客气地说,“这是私人间的谈话!”`
let a = ``
let t = useSplitArticle(a, 'cn', CnKeyboardMap)
t.map((v, i) => {
v.map((w, j) => {
@@ -266,7 +264,7 @@ function onKeyDown(e: KeyboardEvent) {
if (!store.wrongWordDict.originWords.find((v: Word) => v.name === currentWord)) {
store.wrongWordDict.originWords.push(word)
store.wrongWordDict.words.push(word)
store.wrongWordDict.chapters = [store.wrongWordDict.words]
store.wrongWordDict.chapterWords = [store.wrongWordDict.words]
}
if (!store.current.wrongWords.find((v: Word) => v.name === currentWord)) {
store.current.wrongWords.push(word)

View File

@@ -9,11 +9,11 @@ export const useBaseStore = defineStore('base', {
newWordDict: {
name: '生词本',
sort: Sort.normal,
type: DictType.newWordDict,
type: DictType.newDict,
originWords: [],
words: [],
chapterWordNumber: 15,
chapters: [],
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
@@ -22,11 +22,11 @@ export const useBaseStore = defineStore('base', {
skipWordDict: {
name: '简单词',
sort: Sort.normal,
type: DictType.skipWordDict,
type: DictType.skipDict,
originWords: [],
words: [],
chapterWordNumber: 15,
chapters: [],
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
@@ -35,11 +35,11 @@ export const useBaseStore = defineStore('base', {
wrongWordDict: {
name: '错词本',
sort: Sort.normal,
type: DictType.wrongWordDict,
type: DictType.wrongDict,
originWords: [],
words: [],
chapterWordNumber: 15,
chapters: [],
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
@@ -48,11 +48,11 @@ export const useBaseStore = defineStore('base', {
dict: {
name: '新概念英语-2',
sort: Sort.normal,
type: DictType.inner,
type: DictType.innerDict,
originWords: [],
words: [],
chapterWordNumber: 15,
chapters: [],
chapterWords: [],
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
@@ -60,7 +60,7 @@ export const useBaseStore = defineStore('base', {
},
oldDicts: [],
current: {
dictType: DictType.inner,
dictType: DictType.innerDict,
words: [],
index: -1,
wrongWords: [],
@@ -89,22 +89,19 @@ export const useBaseStore = defineStore('base', {
}
},
getters: {
isWrongMode(state: State) {
return state.current.repeatNumber > 0
},
skipWordNames: (state: State) => {
return state.skipWordDict.words.map(v => v.name)
},
currentDict(state: State): Dict {
switch (state.current.dictType) {
case DictType.newWordDict:
case DictType.newDict:
return state.newWordDict
case DictType.skipWordDict:
case DictType.skipDict:
return state.skipWordDict
case DictType.wrongWordDict:
case DictType.wrongDict:
return state.wrongWordDict
case DictType.inner:
case DictType.custom:
case DictType.innerDict:
case DictType.customDict:
return state.dict
}
},
@@ -124,7 +121,7 @@ export const useBaseStore = defineStore('base', {
},
dictTitle(state: State) {
let title = this.currentDict.name
if ([DictType.inner, DictType.custom].includes(this.current.dictType)) {
if ([DictType.innerDict, DictType.customDict].includes(this.current.dictType)) {
title += `${this.currentDict.chapterIndex + 1}`
title += this.current.repeatNumber ? ' 复习错词' : ''
}
@@ -168,7 +165,7 @@ export const useBaseStore = defineStore('base', {
// let obj: Config = JSON.parse(configStr)
// this.setState(obj)
// }
if (this.current.dictType === DictType.inner) {
if (this.current.dictType === DictType.innerDict) {
let r = await fetch(`/public/${this.dict.url}`)
r.json().then(v => {
this.dict.originWords = cloneDeep(v)
@@ -194,9 +191,9 @@ export const useBaseStore = defineStore('base', {
this.saveStatistics()
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
this.current.dictType = dict.type
if ([DictType.newWordDict,
DictType.skipWordDict,
DictType.wrongWordDict].includes(dict.type)) {
if ([DictType.newDict,
DictType.skipDict,
DictType.wrongDict].includes(dict.type)) {
this[dict.type].chapterIndex = chapterIndex
this[dict.type].chapterWordIndex = chapterWordIndex
} else {

View File

@@ -76,11 +76,29 @@ export interface DictJson {
}
export enum DictType {
newWordDict = 'newWordDict',
skipWordDict = 'skipWordDict',
wrongWordDict = 'wrongWordDict',
inner = 'inner',
custom = 'custom',
newDict = 'newDict',
skipDict = 'skipDict',
wrongDict = 'wrongDict',
innerDict = 'innerDict',
customDict = 'customDict',
}
export interface Sentence {
sentence: string,
words: string[]
}
export interface Article {
article: string,
articleTranslate: string,
newWords: Word[],
articleAllWords: string[],
sections: Sentence[][],
translate: {
sentence: string,
location: string
}[],
}
export interface Dict {
@@ -90,7 +108,8 @@ export interface Dict {
originWords: Word[],//原始单词
words: Word[],
chapterWordNumber: number,//章节单词数量
chapters: Word[][],
chapterWords: Word[][],
// articles: Article[],
chapterIndex: number,
chapterWordIndex: number,
statistics: Statistics[],