bf
This commit is contained in:
@@ -18,11 +18,9 @@ const {setTheme} = useTheme()
|
||||
|
||||
watch(store.$state, (n: BaseState) => {
|
||||
let data: BaseState = cloneDeep(n)
|
||||
data.myDicts.map((v: any) => {
|
||||
if (v.type === DictType.word && v.translateLanguage === 'common') {
|
||||
v.originWordsSimple = v.originWords.map(s => s.name)
|
||||
v.originWords = []
|
||||
}
|
||||
data.myDictList.map((v: any) => {
|
||||
if (v.type === DictType.word) v.originWords = []
|
||||
if (v.type === DictType.article) v.articles = []
|
||||
v.words = []
|
||||
v.chapterWords = []
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ let isEdit = $ref(true)
|
||||
useDisableEventListener()
|
||||
|
||||
let list = $computed(() => {
|
||||
return store.myDicts.filter(v => v.type === DictType.customArticle)
|
||||
return store.myDictList.filter(v => v.type === DictType.customArticle)
|
||||
.concat([
|
||||
store.simple,
|
||||
store.wrong,
|
||||
@@ -128,16 +128,16 @@ async function onSubmit() {
|
||||
...form,
|
||||
}
|
||||
if (form.id) {
|
||||
let rIndex = store.myDicts.findIndex(v => v.id === form.id)
|
||||
let rIndex = store.myDictList.findIndex(v => v.id === form.id)
|
||||
runtimeStore.editDict = data
|
||||
store.myDicts[rIndex] = cloneDeep(data)
|
||||
store.myDictList[rIndex] = cloneDeep(data)
|
||||
isEdit = false
|
||||
} else {
|
||||
if (store.myDicts.find(v => v.name === form.name)) {
|
||||
if (store.myDictList.find(v => v.name === form.name)) {
|
||||
return ElMessage.warning('已有相同名称词典!')
|
||||
} else {
|
||||
runtimeStore.editDict = data
|
||||
store.myDicts.push(cloneDeep(data))
|
||||
store.myDictList.push(cloneDeep(data))
|
||||
isEdit = false
|
||||
console.log('submit!', data)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ function importData(e: Event) {
|
||||
showImportBtn = true
|
||||
return ElMessage.error('请填写词典名称!')
|
||||
} else {
|
||||
if (base.myDicts.find(v => v.name === obj.name)) {
|
||||
if (base.myDictList.find(v => v.name === obj.name)) {
|
||||
showImportBtn = true
|
||||
return ElMessage.error('词典名称已存在!')
|
||||
}
|
||||
@@ -171,7 +171,7 @@ function importData(e: Event) {
|
||||
message: '导入成功,已切换到',
|
||||
duration: 5000
|
||||
})
|
||||
base.myDicts.push(obj)
|
||||
base.myDictList.push(obj)
|
||||
runtimeStore.editDict = cloneDeep(runtimeStore.editDict)
|
||||
showImportBtn = true
|
||||
} catch (e) {
|
||||
|
||||
@@ -48,7 +48,7 @@ async function selectDict(val: { dict: DictResource, index: number }) {
|
||||
detailListTabIndex = 0
|
||||
wordFormMode = FormMode.None
|
||||
loading = true
|
||||
let find: Dict = store.myDicts.find((v: Dict) => v.name === item.name)
|
||||
let find: Dict = store.myDictList.find((v: Dict) => v.name === item.name)
|
||||
if (find) {
|
||||
runtimeStore.editDict = cloneDeep(find)
|
||||
} else {
|
||||
@@ -59,7 +59,7 @@ async function selectDict(val: { dict: DictResource, index: number }) {
|
||||
}
|
||||
|
||||
if ([DictType.collect, DictType.simple, DictType.wrong].includes(runtimeStore.editDict.type)) {
|
||||
wordList = cloneDeep(runtimeStore.editDict.originWords)
|
||||
wordList = cloneDeep(runtimeStore.editDict.words)
|
||||
} else {
|
||||
let url = `./dicts/${runtimeStore.editDict.language}/${runtimeStore.editDict.type}/${runtimeStore.editDict.translateLanguage}/${runtimeStore.editDict.url}`;
|
||||
if (runtimeStore.editDict.type === DictType.word) {
|
||||
@@ -67,10 +67,16 @@ async function selectDict(val: { dict: DictResource, index: number }) {
|
||||
let r = await fetch(url)
|
||||
let v = await r.json()
|
||||
runtimeStore.editDict.originWords = cloneDeep(v)
|
||||
runtimeStore.editDict.words = cloneDeep(v)
|
||||
runtimeStore.editDict.chapterWords = chunk(runtimeStore.editDict.words, runtimeStore.editDict.chapterWordNumber)
|
||||
changeSort(runtimeStore.editDict.sort)
|
||||
}
|
||||
wordList = cloneDeep(runtimeStore.editDict.originWords)
|
||||
wordList = cloneDeep(runtimeStore.editDict.words)
|
||||
}
|
||||
|
||||
if (runtimeStore.editDict.type === DictType.customWord) {
|
||||
if (!runtimeStore.editDict.words.length) {
|
||||
changeSort(runtimeStore.editDict.sort)
|
||||
}
|
||||
wordList = cloneDeep(runtimeStore.editDict.words)
|
||||
}
|
||||
|
||||
if (runtimeStore.editDict.type === DictType.article) {
|
||||
@@ -83,6 +89,8 @@ async function selectDict(val: { dict: DictResource, index: number }) {
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
@@ -116,7 +124,7 @@ const groupByTranslateLanguage = $computed(() => {
|
||||
data = groupBy(articleList, 'translateLanguage')
|
||||
} else if (currentLanguage === 'my') {
|
||||
data = {
|
||||
common: store.myDicts.concat([{name: '',} as any])
|
||||
common: store.myDictList.concat([{name: '',} as any])
|
||||
}
|
||||
} else {
|
||||
data = groupBy(groupByLanguage[currentLanguage], 'translateLanguage')
|
||||
@@ -255,18 +263,22 @@ async function onSubmit() {
|
||||
...DefaultDict,
|
||||
...dictForm,
|
||||
}
|
||||
//任意修改,都将其变为自定义词典
|
||||
if (data.type === DictType.word) data.type = DictType.customWord
|
||||
if (data.type === DictType.article) data.type = DictType.customArticle
|
||||
|
||||
if (data.id) {
|
||||
let rIndex = store.myDicts.findIndex(v => v.id === data.id)
|
||||
store.myDicts[rIndex] = cloneDeep(data)
|
||||
let rIndex = store.myDictList.findIndex(v => v.id === data.id)
|
||||
store.myDictList[rIndex] = cloneDeep(data)
|
||||
runtimeStore.editDict = cloneDeep(data)
|
||||
isAddDict = false
|
||||
ElMessage.success('修改成功')
|
||||
} else {
|
||||
data.id = 'custom-dict-' + Date.now()
|
||||
if (store.myDicts.find(v => v.name === dictForm.name)) {
|
||||
if (store.myDictList.find(v => v.name === dictForm.name)) {
|
||||
return ElMessage.warning('已有相同名称词典!')
|
||||
} else {
|
||||
store.myDicts.push(cloneDeep(data))
|
||||
store.myDictList.push(cloneDeep(data))
|
||||
runtimeStore.editDict = cloneDeep(data)
|
||||
isAddDict = false
|
||||
ElMessage.success('添加成功')
|
||||
@@ -306,6 +318,20 @@ const wordRules = reactive<FormRules>({
|
||||
})
|
||||
let wordListRef: any = $ref()
|
||||
|
||||
//同步到我的词典列表
|
||||
function syncMyDictList() {
|
||||
//任意修改,都将其变为自定义词典
|
||||
if (runtimeStore.editDict.type === DictType.word) runtimeStore.editDict.type = DictType.customWord
|
||||
if (runtimeStore.editDict.type === DictType.article) runtimeStore.editDict.type = DictType.customArticle
|
||||
|
||||
let rIndex = store.myDictList.findIndex(v => v.id === runtimeStore.editDict.id)
|
||||
if (rIndex > -1) {
|
||||
store.myDictList[rIndex] = cloneDeep(runtimeStore.editDict)
|
||||
} else {
|
||||
store.myDictList.push(cloneDeep(runtimeStore.editDict))
|
||||
}
|
||||
}
|
||||
|
||||
async function onSubmitWord() {
|
||||
await wordFormRef.validate((valid, fields) => {
|
||||
if (valid) {
|
||||
@@ -320,28 +346,70 @@ async function onSubmitWord() {
|
||||
return ElMessage.warning('已有相同名称单词!')
|
||||
} else {
|
||||
runtimeStore.editDict.originWords.push(data)
|
||||
runtimeStore.editDict.words.push(data)
|
||||
//因为虚拟列表,必须重新赋值才能检测到更新
|
||||
wordList = cloneDeep(runtimeStore.editDict.originWords)
|
||||
wordList = cloneDeep(runtimeStore.editDict.words)
|
||||
|
||||
runtimeStore.editDict.chapterWords[runtimeStore.editDict.chapterWords.length - 1].push(data)
|
||||
|
||||
ElMessage.success('添加成功')
|
||||
wordForm = cloneDeep(DefaultFormWord)
|
||||
setTimeout(wordListRef?.scrollToBottom, 100)
|
||||
}
|
||||
console.log('runtimeStore.editDict', runtimeStore.editDict)
|
||||
} else {
|
||||
runtimeStore.editDict.originWords[wordFormMode] = data
|
||||
runtimeStore.editDict.words[wordFormMode] = data
|
||||
//因为虚拟列表,必须重新赋值才能检测到更新
|
||||
wordList = cloneDeep(runtimeStore.editDict.originWords)
|
||||
wordList = cloneDeep(runtimeStore.editDict.words)
|
||||
//同步到原始列表,因为word可能是随机的,所以需要自己寻找index去修改原始列表
|
||||
let rIndex = runtimeStore.editDict.originWords.findIndex(v => v.name === data.name)
|
||||
if (rIndex > -1) {
|
||||
runtimeStore.editDict.originWords[rIndex] = data
|
||||
}
|
||||
|
||||
runtimeStore.editDict.chapterWords = runtimeStore.editDict.chapterWords.map(list => {
|
||||
let rIndex2 = list.findIndex(v => v.name === data.name)
|
||||
if (rIndex2 > -1) {
|
||||
list[rIndex2] = data
|
||||
}
|
||||
return list
|
||||
})
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
syncMyDictList()
|
||||
} else {
|
||||
ElMessage.warning('请填写完整')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function delWord(index: number) {
|
||||
runtimeStore.editDict.originWords.splice(index, 1)
|
||||
wordList = cloneDeep(runtimeStore.editDict.originWords)
|
||||
function delWord(word: Word, index: number) {
|
||||
//同步到原始列表,因为word可能是随机的,所以需要自己寻找index去修改原始列表
|
||||
let rIndex = runtimeStore.editDict.originWords.findIndex(v => v.name === word.name)
|
||||
if (rIndex > -1) {
|
||||
runtimeStore.editDict.originWords.splice(rIndex, 1)
|
||||
}
|
||||
|
||||
runtimeStore.editDict.chapterWords.map(list => {
|
||||
let rIndex2 = list.findIndex(v => v.name === word.name)
|
||||
if (rIndex2 > -1) {
|
||||
list.splice(rIndex2, 1)
|
||||
}
|
||||
})
|
||||
|
||||
runtimeStore.editDict.chapterWords = runtimeStore.editDict.chapterWords.filter(v => v.length)
|
||||
if (runtimeStore.editDict.chapterWords.length === 0) runtimeStore.editDict.chapterIndex = -1
|
||||
else {
|
||||
if (runtimeStore.editDict.chapterIndex >= runtimeStore.editDict.chapterWords.length) {
|
||||
runtimeStore.editDict.chapterIndex = runtimeStore.editDict.chapterWords.length - 1
|
||||
}
|
||||
}
|
||||
|
||||
runtimeStore.editDict.words.splice(index, 1)
|
||||
wordList = cloneDeep(runtimeStore.editDict.words)
|
||||
syncMyDictList()
|
||||
|
||||
closeWordForm()
|
||||
}
|
||||
|
||||
function editWord(val: { word: Word, index: number }) {
|
||||
@@ -602,7 +670,7 @@ watch(() => step, v => {
|
||||
<template v-slot="{word,index}">
|
||||
<BaseIcon
|
||||
class-name="del"
|
||||
@click="delWord(index)"
|
||||
@click="delWord(word,index)"
|
||||
title="移除"
|
||||
icon="solar:trash-bin-minimalistic-linear"/>
|
||||
</template>
|
||||
|
||||
@@ -38,7 +38,7 @@ async function selectDict(item: DictResource) {
|
||||
console.log('item', item)
|
||||
step = 1
|
||||
loading = true
|
||||
let find: Dict = baseStore.myDicts.find((v: Dict) => v.name === item.name)
|
||||
let find: Dict = baseStore.myDictList.find((v: Dict) => v.name === item.name)
|
||||
if (find) {
|
||||
runtimeStore.editDict = cloneDeep(find)
|
||||
if (find.type === DictType.article) {
|
||||
|
||||
@@ -7,15 +7,14 @@ import {useRuntimeStore} from "@/stores/runtime.ts";
|
||||
import * as localforage from "localforage";
|
||||
|
||||
export interface BaseState {
|
||||
myDicts: Dict[],
|
||||
current: {
|
||||
dictType: DictType,
|
||||
index: number,
|
||||
editIndex: number,
|
||||
practiceType: DictType,//练习类型,目前仅词典为collect时判断是练单词还是文章使用
|
||||
},
|
||||
simpleWords: string[],
|
||||
load: boolean
|
||||
myDictList: Dict[],
|
||||
current: {
|
||||
index: number,
|
||||
editIndex: number,
|
||||
practiceType: DictType,//练习类型,目前仅词典为collect时判断是练单词还是文章使用
|
||||
},
|
||||
simpleWords: string[],
|
||||
load: boolean
|
||||
}
|
||||
|
||||
// words: [
|
||||
@@ -64,270 +63,252 @@ export interface BaseState {
|
||||
// ],
|
||||
|
||||
export const useBaseStore = defineStore('base', {
|
||||
state: (): BaseState => {
|
||||
return {
|
||||
myDicts: [
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'collect',
|
||||
name: '收藏',
|
||||
type: DictType.collect,
|
||||
category: '自带字典',
|
||||
tags: ['自带'],
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'skip',
|
||||
name: '简单词',
|
||||
type: DictType.simple,
|
||||
category: '自带字典'
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'wrong',
|
||||
name: '错词本',
|
||||
type: DictType.wrong,
|
||||
category: '自带字典'
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'article_nce2',
|
||||
name: "新概念英语2-课文",
|
||||
description: '新概念英语2-课文',
|
||||
category: '英语学习',
|
||||
tags: ['新概念英语'],
|
||||
url: 'NCE_2.json',
|
||||
translateLanguage: 'common',
|
||||
language: 'en',
|
||||
type: DictType.article
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
name: '新概念英语(新版)-2',
|
||||
description: '新概念英语新版第二册',
|
||||
category: '青少年英语',
|
||||
tags: ['新概念英语'],
|
||||
url: 'nce-new-2.json',
|
||||
translateLanguage: 'common',
|
||||
language: 'en',
|
||||
type: DictType.word
|
||||
},
|
||||
],
|
||||
current: {
|
||||
dictType: DictType.word,
|
||||
index: 4,
|
||||
editIndex: 0,
|
||||
// dictType: DictType.article,
|
||||
// index: 0,
|
||||
practiceType: DictType.word,
|
||||
},
|
||||
simpleWords: [
|
||||
'a', 'an',
|
||||
'i', 'my', 'you', 'your', 'me', 'it',
|
||||
'am', 'is', 'do', 'are', 'did', 'were',
|
||||
'what', 'who', 'where', 'how', 'no', 'yes',
|
||||
'not', 'can', 'could',
|
||||
'the', 'to', 'of', 'for', 'and', 'that', 'this', 'be'
|
||||
],
|
||||
load: false
|
||||
}
|
||||
state: (): BaseState => {
|
||||
return {
|
||||
myDictList: [
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'collect',
|
||||
name: '收藏',
|
||||
type: DictType.collect,
|
||||
category: '自带字典',
|
||||
tags: ['自带'],
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'skip',
|
||||
name: '简单词',
|
||||
type: DictType.simple,
|
||||
category: '自带字典'
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'wrong',
|
||||
name: '错词本',
|
||||
type: DictType.wrong,
|
||||
category: '自带字典'
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
id: 'article_nce2',
|
||||
name: "新概念英语2-课文",
|
||||
description: '新概念英语2-课文',
|
||||
category: '英语学习',
|
||||
tags: ['新概念英语'],
|
||||
url: 'NCE_2.json',
|
||||
translateLanguage: 'common',
|
||||
language: 'en',
|
||||
type: DictType.article
|
||||
},
|
||||
{
|
||||
...cloneDeep(DefaultDict),
|
||||
name: '新概念英语(新版)-2',
|
||||
description: '新概念英语新版第二册',
|
||||
category: '青少年英语',
|
||||
tags: ['新概念英语'],
|
||||
url: 'nce-new-2.json',
|
||||
translateLanguage: 'common',
|
||||
language: 'en',
|
||||
type: DictType.word
|
||||
},
|
||||
],
|
||||
current: {
|
||||
index: 4,
|
||||
editIndex: 0,
|
||||
// dictType: DictType.article,
|
||||
// index: 0,
|
||||
practiceType: DictType.word,
|
||||
},
|
||||
simpleWords: [
|
||||
'a', 'an',
|
||||
'i', 'my', 'you', 'your', 'me', 'it',
|
||||
'am', 'is', 'do', 'are', 'did', 'were',
|
||||
'what', 'who', 'where', 'how', 'no', 'yes',
|
||||
'not', 'can', 'could',
|
||||
'the', 'to', 'of', 'for', 'and', 'that', 'this', 'be'
|
||||
],
|
||||
load: false
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
collect() {
|
||||
return this.myDictList[0]
|
||||
},
|
||||
getters: {
|
||||
collect() {
|
||||
return this.myDicts[0]
|
||||
},
|
||||
simple(): Dict {
|
||||
return this.myDicts[1]
|
||||
},
|
||||
wrong() {
|
||||
return this.myDicts[2]
|
||||
},
|
||||
skipWordNames() {
|
||||
return this.simple.originWords.map(v => v.name.toLowerCase())
|
||||
},
|
||||
skipWordNamesWithSimpleWords() {
|
||||
return this.simple.originWords.map(v => v.name.toLowerCase()).concat(this.simpleWords)
|
||||
},
|
||||
isArticle(state: BaseState): boolean {
|
||||
//如果是收藏时,特殊判断
|
||||
if (this.currentDict.type === DictType.collect) {
|
||||
return state.current.practiceType === DictType.article
|
||||
}
|
||||
return [
|
||||
DictType.article,
|
||||
DictType.customArticle
|
||||
].includes(this.currentDict.type)
|
||||
},
|
||||
editDict(state: BaseState) {
|
||||
if (state.current.editIndex === -1) {
|
||||
return cloneDeep(DefaultDict)
|
||||
}
|
||||
return state.myDicts.filter(v => [DictType.customWord, DictType.customArticle].includes(v.type))[state.current.editIndex - 3]
|
||||
},
|
||||
currentDict(): Dict {
|
||||
return this.myDicts[this.current.index]
|
||||
},
|
||||
currentEditDict(): Dict {
|
||||
return this.myDicts[this.current.editIndex]
|
||||
},
|
||||
wordIndex(state: BaseState): number {
|
||||
return this.currentDict.wordIndex
|
||||
},
|
||||
chapter(state: BaseState): Word[] {
|
||||
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
|
||||
},
|
||||
dictTitle(state: BaseState) {
|
||||
let title = this.currentDict.name
|
||||
return title + this.chapterName
|
||||
},
|
||||
chapterName(state: BaseState) {
|
||||
let title = ''
|
||||
switch (this.currentDict.type) {
|
||||
case DictType.collect:
|
||||
if (state.current.practiceType === DictType.word) {
|
||||
return `第${this.currentDict.chapterIndex + 1}章`
|
||||
}
|
||||
case DictType.word:
|
||||
case DictType.customWord:
|
||||
return `第${this.currentDict.chapterIndex + 1}章`
|
||||
}
|
||||
return title
|
||||
}
|
||||
simple(): Dict {
|
||||
return this.myDictList[1]
|
||||
},
|
||||
actions: {
|
||||
setState(obj: any) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
this[key] = value
|
||||
}
|
||||
// console.log('this/', this)
|
||||
},
|
||||
async init() {
|
||||
return new Promise(async resolve => {
|
||||
try {
|
||||
let configStr: string = await localforage.getItem(SaveDict.key)
|
||||
if (configStr) {
|
||||
let data = JSON.parse(configStr)
|
||||
wrong() {
|
||||
return this.myDictList[2]
|
||||
},
|
||||
skipWordNames() {
|
||||
return this.simple.originWords.map(v => v.name.toLowerCase())
|
||||
},
|
||||
skipWordNamesWithSimpleWords() {
|
||||
return this.simple.originWords.map(v => v.name.toLowerCase()).concat(this.simpleWords)
|
||||
},
|
||||
isArticle(state: BaseState): boolean {
|
||||
//如果是收藏时,特殊判断
|
||||
if (this.currentDict.type === DictType.collect) {
|
||||
return state.current.practiceType === DictType.article
|
||||
}
|
||||
return [
|
||||
DictType.article,
|
||||
DictType.customArticle
|
||||
].includes(this.currentDict.type)
|
||||
},
|
||||
editDict(state: BaseState) {
|
||||
if (state.current.editIndex === -1) {
|
||||
return cloneDeep(DefaultDict)
|
||||
}
|
||||
return state.myDictList.filter(v => [DictType.customWord, DictType.customArticle].includes(v.type))[state.current.editIndex - 3]
|
||||
},
|
||||
currentDict(): Dict {
|
||||
return this.myDictList[this.current.index]
|
||||
},
|
||||
currentEditDict(): Dict {
|
||||
return this.myDictList[this.current.editIndex]
|
||||
},
|
||||
wordIndex(state: BaseState): number {
|
||||
return this.currentDict.wordIndex
|
||||
},
|
||||
chapter(state: BaseState): Word[] {
|
||||
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
|
||||
},
|
||||
dictTitle(state: BaseState) {
|
||||
let title = this.currentDict.name
|
||||
return title + this.chapterName
|
||||
},
|
||||
chapterName(state: BaseState) {
|
||||
let title = ''
|
||||
switch (this.currentDict.type) {
|
||||
case DictType.collect:
|
||||
if (state.current.practiceType === DictType.word) {
|
||||
return `第${this.currentDict.chapterIndex + 1}章`
|
||||
}
|
||||
case DictType.word:
|
||||
case DictType.customWord:
|
||||
return `第${this.currentDict.chapterIndex + 1}章`
|
||||
}
|
||||
return title
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setState(obj: any) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
this[key] = value
|
||||
}
|
||||
// console.log('this/', this)
|
||||
},
|
||||
async init() {
|
||||
return new Promise(async resolve => {
|
||||
try {
|
||||
let configStr: string = await localforage.getItem(SaveDict.key)
|
||||
console.log('s', configStr)
|
||||
if (configStr) {
|
||||
let data = JSON.parse(configStr)
|
||||
let state: BaseState = data.val
|
||||
state.load = false
|
||||
|
||||
let state: BaseState = data.val
|
||||
state.myDicts.map((v: any) => {
|
||||
if (v.type === DictType.word && v.translateLanguage === 'common') {
|
||||
v.originWords = v.originWordsSimple.map((name: string) => ({...DefaultWord, name}))
|
||||
delete v.originWordsSimple
|
||||
}
|
||||
})
|
||||
this.setState(state)
|
||||
|
||||
// if (data.version === SaveDict.version) {
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
if (this.current.index < 3) {
|
||||
|
||||
} else {
|
||||
if ([
|
||||
DictType.word,
|
||||
DictType.customWord,
|
||||
].includes(this.currentDict.type)) {
|
||||
if (!this.currentDict.originWords.length) {
|
||||
let r = await fetch(`./dicts/${this.currentDict.language}/${this.currentDict.type}/${this.currentDict.translateLanguage}/${this.currentDict.url}`)
|
||||
// let r = await fetch(`.${this.currentDict.url}`)
|
||||
r.json().then(v => {
|
||||
if (this.currentDict.translateLanguage === 'common') {
|
||||
const runtimeStore = useRuntimeStore()
|
||||
fetch('./translate/en2zh_CN-min.json').then(r2 => {
|
||||
// fetch('http://sc.ttentau.top/en2zh_CN-min.json').then(r2 => {
|
||||
r2.json().then((list: Word[]) => {
|
||||
runtimeStore.translateWordList = list
|
||||
|
||||
this.currentDict.originWords = cloneDeep(v)
|
||||
this.currentDict.words = cloneDeep(v)
|
||||
this.currentDict.chapterWords = chunk(this.currentDict.words, this.currentDict.chapterWordNumber)
|
||||
this.currentDict.chapterWords[this.currentDict.chapterIndex].map((w: Word) => {
|
||||
let res = list.find(a => a.name === w.name)
|
||||
if (res) w = Object.assign(w, res)
|
||||
})
|
||||
|
||||
resolve(true)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.currentDict.originWords = cloneDeep(v)
|
||||
this.currentDict.words = cloneDeep(v)
|
||||
this.currentDict.chapterWords = chunk(this.currentDict.words, this.currentDict.chapterWordNumber)
|
||||
resolve(true)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
}
|
||||
|
||||
if ([
|
||||
DictType.article,
|
||||
DictType.customArticle,
|
||||
].includes(this.currentDict.type)) {
|
||||
if (!this.currentDict.articles.length) {
|
||||
console.log(2)
|
||||
let r = await fetch(`./dicts/${this.currentDict.language}/${this.currentDict.type}/${this.currentDict.translateLanguage}/${this.currentDict.url}`)
|
||||
r.json().then((v: any[]) => {
|
||||
console.log(3)
|
||||
this.currentDict.articles = cloneDeep(v.map(v => {
|
||||
v.id = uuidv4()
|
||||
return v
|
||||
}))
|
||||
resolve(true)
|
||||
})
|
||||
} else {
|
||||
resolve(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
saveStatistics(statistics: DisplayStatistics) {
|
||||
if (statistics.spend > 1000 * 10) {
|
||||
delete statistics.wrongWords
|
||||
this.currentDict.statistics.push(statistics)
|
||||
}
|
||||
},
|
||||
async changeDict(dict: Dict, chapterIndex: number = dict.chapterIndex, chapterWordIndex: number = dict.chapterWordNumber, practiceType: DictType) {
|
||||
//TODO 保存统计
|
||||
// this.saveStatistics()
|
||||
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
|
||||
this.currentDict.type = dict.type
|
||||
this.current.practiceType = practiceType
|
||||
if ([DictType.collect,
|
||||
DictType.simple,
|
||||
DictType.wrong].includes(dict.type)) {
|
||||
this[dict.type].chapterIndex = 0
|
||||
this[dict.type].chapterWordIndex = chapterWordIndex
|
||||
this[dict.type].chapterWords = [this[dict.type].words]
|
||||
if (data.version === SaveDict.version) {
|
||||
this.setState(state)
|
||||
} else {
|
||||
if (dict.type === DictType.article || dict.type === DictType.customArticle) {
|
||||
if (chapterIndex > dict.articles.length) {
|
||||
dict.chapterIndex = 0
|
||||
}
|
||||
} else {
|
||||
if (chapterIndex > dict.chapterWords.length) {
|
||||
dict.chapterIndex = 0
|
||||
}
|
||||
}
|
||||
let rIndex = this.myDicts.findIndex((v: Dict) => v.name === dict.name)
|
||||
if (rIndex > -1) {
|
||||
this.myDicts[rIndex] = dict
|
||||
this.current.index = rIndex
|
||||
} else {
|
||||
this.myDicts.push(cloneDeep(dict))
|
||||
this.current.index = this.myDicts.length - 1
|
||||
}
|
||||
this.setState(state)
|
||||
}
|
||||
emitter.emit(EventKey.resetWord)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取本地dict数据失败',e)
|
||||
}
|
||||
|
||||
if (this.current.index < 3) {
|
||||
|
||||
} else {
|
||||
let dictResourceUrl = `./dicts/${this.currentDict.language}/${this.currentDict.type}/${this.currentDict.translateLanguage}/${this.currentDict.url}`;
|
||||
if ([
|
||||
DictType.word,
|
||||
DictType.customWord,
|
||||
].includes(this.currentDict.type)) {
|
||||
if (!this.currentDict.originWords.length) {
|
||||
let r = await fetch(dictResourceUrl)
|
||||
// let r = await fetch(`.${this.currentDict.url}`)
|
||||
let v = await r.json()
|
||||
if (this.currentDict.translateLanguage === 'common') {
|
||||
const runtimeStore = useRuntimeStore()
|
||||
let r2 = await fetch('./translate/en2zh_CN-min.json')
|
||||
// fetch('http://sc.ttentau.top/en2zh_CN-min.json').then(r2 => {
|
||||
let list: Word[] = await r2.json()
|
||||
|
||||
runtimeStore.translateWordList = list
|
||||
|
||||
this.currentDict.originWords = cloneDeep(v)
|
||||
this.currentDict.words = cloneDeep(v)
|
||||
this.currentDict.chapterWords = chunk(this.currentDict.words, this.currentDict.chapterWordNumber)
|
||||
this.currentDict.chapterWords[this.currentDict.chapterIndex].map((w: Word) => {
|
||||
let res = list.find(a => a.name === w.name)
|
||||
if (res) w = Object.assign(w, res)
|
||||
})
|
||||
} else {
|
||||
this.currentDict.originWords = cloneDeep(v)
|
||||
this.currentDict.words = cloneDeep(v)
|
||||
this.currentDict.chapterWords = chunk(this.currentDict.words, this.currentDict.chapterWordNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ([
|
||||
DictType.article,
|
||||
DictType.customArticle,
|
||||
].includes(this.currentDict.type)) {
|
||||
if (!this.currentDict.articles.length) {
|
||||
let r = await fetch(dictResourceUrl)
|
||||
let s: any[] = await r.json()
|
||||
this.currentDict.articles = cloneDeep(s.map(v => {
|
||||
v.id = uuidv4()
|
||||
return v
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve(true)
|
||||
})
|
||||
},
|
||||
saveStatistics(statistics: DisplayStatistics) {
|
||||
if (statistics.spend > 1000 * 10) {
|
||||
delete statistics.wrongWords
|
||||
this.currentDict.statistics.push(statistics)
|
||||
}
|
||||
},
|
||||
async changeDict(dict: Dict, chapterIndex: number = dict.chapterIndex, chapterWordIndex: number = dict.chapterWordNumber, practiceType: DictType) {
|
||||
//TODO 保存统计
|
||||
// this.saveStatistics()
|
||||
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
|
||||
this.currentDict.type = dict.type
|
||||
this.current.practiceType = practiceType
|
||||
if ([DictType.collect,
|
||||
DictType.simple,
|
||||
DictType.wrong].includes(dict.type)) {
|
||||
this[dict.type].chapterIndex = 0
|
||||
this[dict.type].chapterWordIndex = chapterWordIndex
|
||||
this[dict.type].chapterWords = [this[dict.type].words]
|
||||
} else {
|
||||
if (dict.type === DictType.article || dict.type === DictType.customArticle) {
|
||||
if (chapterIndex > dict.articles.length) {
|
||||
dict.chapterIndex = 0
|
||||
}
|
||||
} else {
|
||||
if (chapterIndex > dict.chapterWords.length) {
|
||||
dict.chapterIndex = 0
|
||||
}
|
||||
}
|
||||
let rIndex = this.myDictList.findIndex((v: Dict) => v.name === dict.name)
|
||||
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.resetWord)
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -231,7 +231,7 @@ export const DefaultDict: Dict = {
|
||||
category: '',
|
||||
tags: [],
|
||||
translateLanguage: 'common',
|
||||
type: DictType.word,
|
||||
type: DictType.customWord,
|
||||
language: 'en',
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user