save
This commit is contained in:
20
src/App.vue
20
src/App.vue
@@ -2,7 +2,7 @@
|
||||
|
||||
import {onMounted, watch} from "vue";
|
||||
import {BaseState, useBaseStore} from "@/stores/base.ts";
|
||||
import {DictType, SaveConfig, SaveDict} from "@/types.ts"
|
||||
import {Dict, DictType, SaveConfig, SaveDict} from "@/types.ts"
|
||||
import Practice from "@/pages/practice/index.vue"
|
||||
import {useRuntimeStore} from "@/stores/runtime.ts";
|
||||
import {useSettingStore} from "@/stores/setting.ts";
|
||||
@@ -21,11 +21,19 @@ const {setTheme} = useTheme()
|
||||
|
||||
watch(store.$state, (n: BaseState) => {
|
||||
let data: BaseState = cloneDeep(n)
|
||||
data.myDictList.map((v: any) => {
|
||||
if (v.type === DictType.word) v.originWords = []
|
||||
if (v.type === DictType.article) v.articles = []
|
||||
v.words = []
|
||||
v.chapterWords = []
|
||||
data.myDictList.map((v: Dict) => {
|
||||
if (v.isCustom) {
|
||||
if (v.type === DictType.article) {
|
||||
v.articles.map(s => {
|
||||
delete s.sections
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (v.type === DictType.word) v.originWords = []
|
||||
if (v.type === DictType.article) v.articles = []
|
||||
v.words = []
|
||||
v.chapterWords = []
|
||||
}
|
||||
})
|
||||
localforage.setItem(SaveDict.key, JSON.stringify({val: data, version: SaveDict.version}))
|
||||
})
|
||||
|
||||
@@ -70,14 +70,13 @@ watch(() => props.article, val => {
|
||||
function renewSections() {
|
||||
if (editArticle.text.trim()) {
|
||||
renewSectionTexts(editArticle)
|
||||
editArticle.sections = []
|
||||
return
|
||||
if (editArticle.useTranslateType === TranslateType.custom) {
|
||||
failCount = renewSectionTranslates(editArticle, editArticle.textCustomTranslate)
|
||||
}
|
||||
if (editArticle.useTranslateType === TranslateType.network) {
|
||||
failCount = renewSectionTranslates(editArticle, editArticle.textNetworkTranslate)
|
||||
}
|
||||
console.log('failCount',failCount)
|
||||
} else {
|
||||
editArticle.sections = []
|
||||
}
|
||||
@@ -165,6 +164,7 @@ function saveSentenceText(sentence: Sentence, val: string) {
|
||||
}
|
||||
|
||||
function save(option: 'save' | 'saveAndNext') {
|
||||
// return console.log(cloneDeep(editArticle))
|
||||
return new Promise((resolve: Function) => {
|
||||
// console.log('article', article)
|
||||
// copy(JSON.stringify(article))
|
||||
|
||||
@@ -46,7 +46,7 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
|
||||
let doc = nlp.tokenize(rowSection)
|
||||
let sentences = doc.json()
|
||||
// console.log('--')
|
||||
console.log('ss', sentences)
|
||||
// console.log('ss', sentences)
|
||||
sentences.map(sentenceRow => {
|
||||
let sentence: Sentence = {
|
||||
//他没有空格,导致修改一行一行的数据时,汇总时全没有空格了,库无法正常断句
|
||||
@@ -138,15 +138,20 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
|
||||
break
|
||||
//类似于这种的“' -- ”的。需要保留空格,用了一个占位符才处理,因为每个符号都会把前面的那个字符的nextSpace改为false
|
||||
case ' ':
|
||||
console.log('sentence', sentence)
|
||||
sentence.words[sentence.words.length - 1].nextSpace = true
|
||||
let word3 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
name: 'placeholder',
|
||||
isSymbol: true,
|
||||
nextSpace: false,
|
||||
});
|
||||
sentence.words.push(word3)
|
||||
// console.log('sentence', sentence)
|
||||
//遇到“The clock has stopped!' I looked at my watch.”
|
||||
//检测到stopped!' 的'时,如果前引号不在当前句,会把当前句的word合并到前一句。那么当前句的word就为空了,会报错
|
||||
//所以需要检测一下
|
||||
if (sentence.words.length) {
|
||||
sentence.words[sentence.words.length - 1].nextSpace = true
|
||||
let word3 = cloneDeep({
|
||||
...DefaultArticleWord,
|
||||
name: 'placeholder',
|
||||
isSymbol: true,
|
||||
nextSpace: false,
|
||||
});
|
||||
sentence.words.push(word3)
|
||||
}
|
||||
break
|
||||
default:
|
||||
// console.log('post', post)
|
||||
@@ -183,11 +188,7 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
|
||||
let post: string = v.post
|
||||
//判断是不是等于空,因为正常的词后面都会有个空格。这种不需要处理。
|
||||
if (post && post !== ' ') {
|
||||
try {
|
||||
checkSymbol(post)
|
||||
} catch (e) {
|
||||
console.log('err', v)
|
||||
}
|
||||
checkSymbol(post)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -197,19 +198,19 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
|
||||
})
|
||||
})
|
||||
|
||||
// sections = sections.filter(sectionItem => sectionItem.length)
|
||||
// sections.map((sectionItem, a) => {
|
||||
// sectionItem.map((sentenceItem, b) => {
|
||||
// sentenceItem.text = sentenceItem.words.reduce((previousValue: string, currentValue) => {
|
||||
// previousValue += currentValue.name + (currentValue.nextSpace ? ' ' : '')
|
||||
// return previousValue
|
||||
// }, '')
|
||||
// })
|
||||
// })
|
||||
sections = sections.filter(sectionItem => sectionItem.length)
|
||||
sections.map((sectionItem, a) => {
|
||||
sectionItem.map((sentenceItem, b) => {
|
||||
sentenceItem.text = sentenceItem.words.reduce((previousValue: string, currentValue) => {
|
||||
previousValue += currentValue.name + (currentValue.nextSpace ? ' ' : '')
|
||||
return previousValue
|
||||
}, '')
|
||||
})
|
||||
})
|
||||
// console.log(sections)
|
||||
// console.timeEnd()
|
||||
|
||||
console.log('sections', sections)
|
||||
// console.log('sections', sections)
|
||||
return {
|
||||
newText: text,
|
||||
sections
|
||||
@@ -278,11 +279,12 @@ export function isArticle(type: DictType): boolean {
|
||||
|
||||
export function getTranslateText(article: Article) {
|
||||
if (article.useTranslateType === TranslateType.custom) {
|
||||
|
||||
return article.textCustomTranslate
|
||||
.split('\r\n\r\n').filter(v => v)
|
||||
.split('\n\n').filter(v => v)
|
||||
} else if (article.useTranslateType === TranslateType.network) {
|
||||
return article.textNetworkTranslate
|
||||
.split('\r\n\r\n').filter(v => v)
|
||||
.split('\n\n').filter(v => v)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -6,29 +6,29 @@ import {Translator} from "@opentranslate/translator/src/translator.ts";
|
||||
|
||||
export function renewSectionTranslates(article: Article, translate: string) {
|
||||
let failCount = 0
|
||||
let articleTranslate = translate.split('\n')
|
||||
// console.log('articleTranslate', articleTranslate)
|
||||
// console.log('articleTranslate', articleTranslate)
|
||||
let count = 0
|
||||
for (let i = 0; i < article.sections.length; i++) {
|
||||
let v = article.sections[i]
|
||||
for (let j = 0; j < v.length; j++) {
|
||||
let sentence = v[j]
|
||||
try {
|
||||
let trans = articleTranslate[count]
|
||||
if (trans) {
|
||||
sentence.translate = trans
|
||||
} else {
|
||||
failCount++
|
||||
}
|
||||
} catch (e) {
|
||||
failCount++
|
||||
// console.log('没有对应的翻译', sentence.text)
|
||||
}
|
||||
count++
|
||||
let articleTranslate = translate.split('\n')
|
||||
// console.log('articleTranslate', articleTranslate)
|
||||
// console.log('articleTranslate', articleTranslate)
|
||||
let count = 0
|
||||
for (let i = 0; i < article.sections.length; i++) {
|
||||
let v = article.sections[i]
|
||||
for (let j = 0; j < v.length; j++) {
|
||||
let sentence = v[j]
|
||||
try {
|
||||
let trans = articleTranslate[count]
|
||||
if (trans.trim()) {
|
||||
sentence.translate = trans
|
||||
} else {
|
||||
failCount++
|
||||
}
|
||||
count++
|
||||
} catch (e) {
|
||||
failCount++
|
||||
// console.log('没有对应的翻译', sentence.text)
|
||||
}
|
||||
count++
|
||||
}
|
||||
count++
|
||||
}
|
||||
return failCount
|
||||
}
|
||||
|
||||
|
||||
@@ -252,6 +252,13 @@ function add() {
|
||||
emitter.emit(EventKey.openArticleListModal)
|
||||
}
|
||||
|
||||
function back() {
|
||||
emit('back')
|
||||
setTimeout(() => {
|
||||
isEditDict = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
defineExpose({getDictDetail, add, editDict})
|
||||
|
||||
|
||||
@@ -260,7 +267,7 @@ defineExpose({getDictDetail, add, editDict})
|
||||
<template>
|
||||
<div class="article-detail">
|
||||
<header>
|
||||
<div class="back" @click.stop="emit('back')">
|
||||
<div class="back" @click.stop="back">
|
||||
<Icon icon="octicon:arrow-left-24" width="20"/>
|
||||
</div>
|
||||
<div class="left">
|
||||
|
||||
@@ -425,7 +425,7 @@ function resetChapterList(num?: number, sync?: boolean) {
|
||||
runtimeStore.editDict.chapterWords = chunk(runtimeStore.editDict.words, runtimeStore.editDict.chapterWordNumber)
|
||||
runtimeStore.editDict.length = runtimeStore.editDict.words.length
|
||||
chapterList2 = runtimeStore.editDict.chapterWords.map((v, i) => ({id: i}))
|
||||
if (sync!==undefined){
|
||||
if (sync !== undefined) {
|
||||
syncMyDictList(runtimeStore.editDict)
|
||||
}
|
||||
}
|
||||
@@ -544,6 +544,13 @@ function s() {
|
||||
}
|
||||
}
|
||||
|
||||
function back() {
|
||||
emit('back')
|
||||
setTimeout(() => {
|
||||
isEditDict = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
defineExpose({getDictDetail, add: addWord, editDict})
|
||||
|
||||
</script>
|
||||
@@ -551,7 +558,7 @@ defineExpose({getDictDetail, add: addWord, editDict})
|
||||
<template>
|
||||
<div class="dict-detail">
|
||||
<header>
|
||||
<div class="back" @click.stop="emit('back')">
|
||||
<div class="back" @click.stop="back">
|
||||
<Icon icon="octicon:arrow-left-24" width="20"/>
|
||||
</div>
|
||||
<div class="left">
|
||||
|
||||
@@ -35,7 +35,7 @@ onUnmounted(() => {
|
||||
|
||||
<template>
|
||||
<div class="footer " :class="!settingStore.showToolbar && 'hide'">
|
||||
<div class="bottom anim">
|
||||
<div class="bottom ">
|
||||
<el-progress
|
||||
:percentage="progress"
|
||||
:stroke-width="8"
|
||||
@@ -82,7 +82,7 @@ onUnmounted(() => {
|
||||
.footer {
|
||||
width: var(--toolbar-width);
|
||||
margin-bottom: 10rem;
|
||||
transition: all .3s;
|
||||
transition: all var(--anim-time);
|
||||
position: relative;
|
||||
margin-top: 15rem;
|
||||
|
||||
@@ -91,7 +91,7 @@ onUnmounted(() => {
|
||||
margin-top: 50rem;
|
||||
|
||||
.progress {
|
||||
bottom: calc(100% + 20rem);
|
||||
bottom: calc(100% + 25rem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -193,16 +193,21 @@ export const useBaseStore = defineStore('base', {
|
||||
let configStr: string = await localforage.getItem(SaveDict.key)
|
||||
// console.log(configStr)
|
||||
// console.log('s', new Blob([configStr]).size)
|
||||
// configStr = ''
|
||||
configStr = ''
|
||||
if (configStr) {
|
||||
let data = JSON.parse(configStr)
|
||||
let state: BaseState = data.val
|
||||
let version = Number(data.version)
|
||||
// console.log('state', state)
|
||||
state.load = false
|
||||
|
||||
if (data.version === SaveDict.version) {
|
||||
if (version === SaveDict.version) {
|
||||
this.setState(state)
|
||||
} else {
|
||||
this.setState(state)
|
||||
if (version === 2) {
|
||||
|
||||
}
|
||||
// this.setState(state)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -148,7 +148,7 @@ export const ShortcutKeyMap = {
|
||||
|
||||
export const SaveDict = {
|
||||
key: 'typing-word-dict',
|
||||
version: 2
|
||||
version: 3
|
||||
}
|
||||
export const SaveConfig = {
|
||||
key: 'typing-word-config',
|
||||
|
||||
Reference in New Issue
Block a user