save
This commit is contained in:
2
components.d.ts
vendored
2
components.d.ts
vendored
@@ -9,12 +9,10 @@ declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
Add: typeof import('./src/components/Toolbar/Add.vue')['default']
|
||||
AddArticle: typeof import('./src/components/Practice/AddArticle.vue')['default']
|
||||
Alert: typeof import('./src/components/Modal/Alert.vue')['default']
|
||||
Backgorund: typeof import('./src/components/Backgorund.vue')['default']
|
||||
BaseButton: typeof import('./src/components/BaseButton.vue')['default']
|
||||
ChapterDetail: typeof import('./src/components/ChapterDetail.vue')['default']
|
||||
ChapterList: typeof import('./src/components/ChapterList.vue')['default']
|
||||
Confirm: typeof import('./src/components/Modal/Confirm.vue')['default']
|
||||
DictList: typeof import('./src/components/DictList.vue')['default']
|
||||
DictModal: typeof import('./src/components/Toolbar/DictModal.vue')['default']
|
||||
EditAbleText: typeof import('./src/components/EditAbleText.vue')['default']
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,10 +6,11 @@ import {useEsc} from "@/hooks/event.ts";
|
||||
import {$ref} from "vue/macros";
|
||||
import BaseButton from "@/components/BaseButton.vue";
|
||||
|
||||
interface IProps {
|
||||
export interface ModalProps {
|
||||
modelValue?: boolean,
|
||||
showClose?: boolean,
|
||||
title?: string,
|
||||
content?: string,
|
||||
fullScreen?: boolean;
|
||||
padding?: boolean
|
||||
footer?: boolean
|
||||
@@ -18,7 +19,7 @@ interface IProps {
|
||||
cancelButtonText?: string
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<IProps>(), {
|
||||
const props = withDefaults(defineProps<ModalProps>(), {
|
||||
modelValue: undefined,
|
||||
showClose: true,
|
||||
fullScreen: false,
|
||||
@@ -56,7 +57,6 @@ function close() {
|
||||
setTimeout(() => {
|
||||
emit('update:modelValue', false)
|
||||
emit('close')
|
||||
emit('cancel')
|
||||
visible = false
|
||||
resolve(true)
|
||||
}, closeTime)
|
||||
@@ -81,6 +81,16 @@ onMounted(() => {
|
||||
|
||||
useEsc(close, () => props.modelValue)
|
||||
|
||||
async function ok() {
|
||||
await close()
|
||||
emit('ok')
|
||||
}
|
||||
|
||||
async function cancel() {
|
||||
await close()
|
||||
emit('cancel')
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -89,12 +99,13 @@ useEsc(close, () => props.modelValue)
|
||||
<div class="modal-mask"
|
||||
ref="maskRef"
|
||||
v-if="!fullScreen"
|
||||
@click="close"></div>
|
||||
@click.stop="close"></div>
|
||||
<div class="modal"
|
||||
ref="modalRef"
|
||||
:class="[
|
||||
fullScreen?'full':'window'
|
||||
]"
|
||||
@click.stop="null"
|
||||
>
|
||||
<div class="modal-header" v-if="header">
|
||||
<div class="title">{{ props.title }}</div>
|
||||
@@ -108,13 +119,14 @@ useEsc(close, () => props.modelValue)
|
||||
</div>
|
||||
<div class="modal-body" :class="{padding}">
|
||||
<slot></slot>
|
||||
<div v-if="content" class="content">{{ content }}</div>
|
||||
</div>
|
||||
<div class="modal-footer" v-if="footer">
|
||||
<div class="left">
|
||||
</div>
|
||||
<div class="right">
|
||||
<BaseButton type="link" @click="close">取消</BaseButton>
|
||||
<BaseButton @click="emit('ok'),close()">确定</BaseButton>
|
||||
<BaseButton type="link" @click="cancel">{{ cancelButtonText }}</BaseButton>
|
||||
<BaseButton @click="ok">{{ confirmButtonText }}</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -252,6 +264,12 @@ $header-height: 60rem;
|
||||
&.padding {
|
||||
padding: 4rem 24rem 24rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 350rem;
|
||||
color: black;
|
||||
padding: 4rem 24rem 24rem;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
|
||||
@@ -135,16 +135,21 @@ function onPaste(event: ClipboardEvent) {
|
||||
event.preventDefault()
|
||||
// @ts-ignore
|
||||
let paste = (event.clipboardData || window.clipboardData).getData("text");
|
||||
ElMessageBox.confirm('', '是否需要进行自动分句?', {
|
||||
confirmButtonText: '需要',
|
||||
cancelButtonText: '关闭',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
let r = getSplitTranslateText(paste)
|
||||
if (r) appendTranslate(r)
|
||||
}).catch(() => {
|
||||
appendTranslate(paste)
|
||||
})
|
||||
return MessageBox.confirm(
|
||||
'是否需要进行自动分句',
|
||||
'提示',
|
||||
() => {
|
||||
let r = getSplitTranslateText(paste)
|
||||
if (r) appendTranslate(r)
|
||||
},
|
||||
() => {
|
||||
appendTranslate(paste)
|
||||
},
|
||||
{
|
||||
confirmButtonText: '需要',
|
||||
cancelButtonText: '关闭',
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function onBlur() {
|
||||
@@ -174,37 +179,29 @@ function save() {
|
||||
|
||||
if (article.useTranslateType === TranslateType.network) {
|
||||
if (!article.textNetworkTranslate.trim()) {
|
||||
// MessageBox.confirm(
|
||||
// '您选择了“网络翻译”,但译文内容却为空白,是否修改为“不需要翻译”并保存?',
|
||||
// '提示',
|
||||
// () => {
|
||||
// // article.useTranslateType = TranslateType.none
|
||||
// // saveTemp()
|
||||
// },
|
||||
// () => void 0,
|
||||
// )
|
||||
// return
|
||||
return ElMessageBox.confirm('您选择了“网络翻译”,但译文内容却为空白,是否修改为“不需要翻译”并保存?', '提示', {
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
article.useTranslateType = TranslateType.none
|
||||
saveTemp()
|
||||
}).catch(() => void 0)
|
||||
return MessageBox.confirm(
|
||||
'您选择了“网络翻译”,但译文内容却为空白,是否修改为“不需要翻译”并保存?',
|
||||
'提示',
|
||||
() => {
|
||||
article.useTranslateType = TranslateType.none
|
||||
saveTemp()
|
||||
},
|
||||
() => void 0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (article.useTranslateType === TranslateType.custom) {
|
||||
if (!article.textCustomTranslate.trim()) {
|
||||
return ElMessageBox.confirm('您选择了“本地翻译”,但译文内容却为空白,是否修改为“不需要翻译”并保存?', '提示', {
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
article.useTranslateType = TranslateType.none
|
||||
saveTemp()
|
||||
}).catch(() => void 0)
|
||||
return MessageBox.confirm(
|
||||
'您选择了“本地翻译”,但译文内容却为空白,是否修改为“不需要翻译”并保存?',
|
||||
'提示',
|
||||
() => {
|
||||
article.useTranslateType = TranslateType.none
|
||||
saveTemp()
|
||||
},
|
||||
() => void 0,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +243,6 @@ watch(() => article.useTranslateType, () => {
|
||||
<template>
|
||||
<Modal
|
||||
:model-value="props.modelValue"
|
||||
@close="emit('update:modelValue')"
|
||||
:full-screen="true"
|
||||
>
|
||||
<div class="add-article" @click.stop="null">
|
||||
|
||||
@@ -38,13 +38,6 @@ onUnmounted(() => {
|
||||
|
||||
<template>
|
||||
<div class="footer" :class="!settingStore.showToolbar && 'hide'">
|
||||
<Tooltip :title="settingStore.showToolbar?'收起':'展开'">
|
||||
<Icon icon="icon-park-outline:down"
|
||||
@click="settingStore.showToolbar = !settingStore.showToolbar"
|
||||
class="arrow"
|
||||
:class="!settingStore.showToolbar && 'down'"
|
||||
width="24" color="#999"/>
|
||||
</Tooltip>
|
||||
<div class="bottom">
|
||||
<el-progress :percentage="progress"
|
||||
:stroke-width="8"
|
||||
@@ -99,25 +92,10 @@ onUnmounted(() => {
|
||||
margin-bottom: -90rem;
|
||||
margin-top: 65rem;
|
||||
|
||||
.arrow {
|
||||
transform: translate3d(-50%, -220%, 0) rotate(180deg);
|
||||
}
|
||||
|
||||
.progress {
|
||||
bottom: calc(100% + 30rem);
|
||||
}
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
cursor: pointer;
|
||||
transition: all .3s;
|
||||
transform: translate3d(-50%, -100%, 0) rotate(0);
|
||||
padding: 5rem;
|
||||
}
|
||||
|
||||
.bottom {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
@@ -146,7 +124,6 @@ onUnmounted(() => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.progress {
|
||||
|
||||
@@ -59,7 +59,7 @@ watch(() => store.load, n => {
|
||||
|
||||
function getCurrentPractice() {
|
||||
if (store.isArticle) {
|
||||
// return
|
||||
return
|
||||
let tempArticle = {...DefaultArticle, ...store.currentDict.articles[store.currentDict.chapterIndex]}
|
||||
console.log('article', tempArticle)
|
||||
if (tempArticle.sections.length) {
|
||||
@@ -77,33 +77,40 @@ function getCurrentPractice() {
|
||||
articleData.article = tempArticle
|
||||
} else {
|
||||
//说明有本地翻译,但是没格式化成一行一行的
|
||||
ElMessageBox.confirm('', '检测到存在本地翻译,但未格式化,是否进行编辑?', {
|
||||
confirmButtonText: '去编辑',
|
||||
cancelButtonText: '不需要翻译',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
editArticle = tempArticle
|
||||
showEditArticle = true
|
||||
}).catch(() => {
|
||||
updateSections(tempArticle)
|
||||
tempArticle.useTranslateType = TranslateType.none
|
||||
articleData.article = tempArticle
|
||||
})
|
||||
MessageBox.confirm('检测到存在本地翻译,但未格式化,是否进行编辑?',
|
||||
'提示',
|
||||
() => {
|
||||
editArticle = tempArticle
|
||||
showEditArticle = true
|
||||
},
|
||||
() => {
|
||||
updateSections(tempArticle)
|
||||
tempArticle.useTranslateType = TranslateType.none
|
||||
articleData.article = tempArticle
|
||||
},
|
||||
{
|
||||
confirmButtonText: '去编辑',
|
||||
cancelButtonText: '不需要翻译',
|
||||
})
|
||||
}
|
||||
} else {
|
||||
//没有本地翻译
|
||||
ElMessageBox.confirm('', '没有本地翻译,是否进行编辑?', {
|
||||
confirmButtonText: '去编辑',
|
||||
cancelButtonText: '不需要翻译',
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
editArticle = tempArticle
|
||||
showEditArticle = true
|
||||
}).catch(() => {
|
||||
updateSections(tempArticle)
|
||||
tempArticle.useTranslateType = TranslateType.none
|
||||
articleData.article = tempArticle
|
||||
})
|
||||
MessageBox.confirm(
|
||||
'没有本地翻译,是否进行编辑?',
|
||||
'提示',
|
||||
() => {
|
||||
editArticle = tempArticle
|
||||
showEditArticle = true
|
||||
},
|
||||
() => {
|
||||
updateSections(tempArticle)
|
||||
tempArticle.useTranslateType = TranslateType.none
|
||||
articleData.article = tempArticle
|
||||
},
|
||||
{
|
||||
confirmButtonText: '去编辑',
|
||||
cancelButtonText: '不需要翻译',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +174,7 @@ function test() {
|
||||
<template>
|
||||
<div class="practice">
|
||||
<Toolbar/>
|
||||
<!-- <BaseButton @click="test">test</BaseButton>-->
|
||||
<!-- <BaseButton @click="test">test</BaseButton>-->
|
||||
|
||||
<TypeArticle
|
||||
v-if="store.isArticle"
|
||||
|
||||
@@ -4,238 +4,238 @@ import {chunk, cloneDeep} from "lodash-es";
|
||||
import {emitter, EventKey} from "@/utils/eventBus.ts"
|
||||
|
||||
export const useBaseStore = defineStore('base', {
|
||||
state: (): State => {
|
||||
return {
|
||||
newWordDict: {
|
||||
name: '生词本',
|
||||
sort: Sort.normal,
|
||||
type: DictType.newDict,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '',
|
||||
},
|
||||
skipWordDict: {
|
||||
name: '简单词',
|
||||
sort: Sort.normal,
|
||||
type: DictType.skipDict,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '',
|
||||
},
|
||||
wrongWordDict: {
|
||||
name: '错词本',
|
||||
sort: Sort.normal,
|
||||
type: DictType.wrongDict,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '',
|
||||
},
|
||||
// dict: {
|
||||
// name: '新概念英语-2',
|
||||
// sort: Sort.normal,
|
||||
// type: DictType.innerDict,
|
||||
// originWords: [],
|
||||
// articles: [],
|
||||
// words: [],
|
||||
// chapterWordNumber: 15,
|
||||
// chapterWords: [],
|
||||
// chapterIndex: 0,
|
||||
// chapterWordIndex: 0,
|
||||
// statistics: [],
|
||||
// url: '/dicts/NCE_2.json',
|
||||
// },
|
||||
dict: {
|
||||
name: '新概念英语-2',
|
||||
sort: Sort.normal,
|
||||
type: DictType.publicArticle,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '/articles/NCE_2.json',
|
||||
},
|
||||
oldDicts: [],
|
||||
current: {
|
||||
dictType: DictType.publicArticle,
|
||||
words: [],
|
||||
index: -1,
|
||||
wrongWords: [],
|
||||
originWrongWords: [],
|
||||
repeatNumber: 0,
|
||||
statistics: {
|
||||
startDate: -1,
|
||||
endDate: -1,
|
||||
spend: -1,
|
||||
total: -1,
|
||||
correctRate: -1,
|
||||
wrongWordNumber: -1,
|
||||
state: (): State => {
|
||||
return {
|
||||
newWordDict: {
|
||||
name: '生词本',
|
||||
sort: Sort.normal,
|
||||
type: DictType.newDict,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '',
|
||||
},
|
||||
skipWordDict: {
|
||||
name: '简单词',
|
||||
sort: Sort.normal,
|
||||
type: DictType.skipDict,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '',
|
||||
},
|
||||
wrongWordDict: {
|
||||
name: '错词本',
|
||||
sort: Sort.normal,
|
||||
type: DictType.wrongDict,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '',
|
||||
},
|
||||
// dict: {
|
||||
// name: '新概念英语-2',
|
||||
// sort: Sort.normal,
|
||||
// type: DictType.innerDict,
|
||||
// originWords: [],
|
||||
// articles: [],
|
||||
// words: [],
|
||||
// chapterWordNumber: 15,
|
||||
// chapterWords: [],
|
||||
// chapterIndex: 0,
|
||||
// chapterWordIndex: 0,
|
||||
// statistics: [],
|
||||
// url: '/dicts/NCE_2.json',
|
||||
// },
|
||||
dict: {
|
||||
name: '新概念英语-2',
|
||||
sort: Sort.normal,
|
||||
type: DictType.publicArticle,
|
||||
originWords: [],
|
||||
articles: [],
|
||||
words: [],
|
||||
chapterWordNumber: 15,
|
||||
chapterWords: [],
|
||||
chapterIndex: 0,
|
||||
chapterWordIndex: 0,
|
||||
statistics: [],
|
||||
url: '/articles/NCE_2.json',
|
||||
},
|
||||
oldDicts: [],
|
||||
current: {
|
||||
dictType: DictType.publicArticle,
|
||||
words: [],
|
||||
index: -1,
|
||||
wrongWords: [],
|
||||
originWrongWords: [],
|
||||
repeatNumber: 0,
|
||||
statistics: {
|
||||
startDate: -1,
|
||||
endDate: -1,
|
||||
spend: -1,
|
||||
total: -1,
|
||||
correctRate: -1,
|
||||
wrongWordNumber: -1,
|
||||
}
|
||||
},
|
||||
sideIsOpen: false,
|
||||
isDictation: true,
|
||||
simpleWords: [
|
||||
'a', 'an', 'of', 'and',
|
||||
'i', 'my', 'you', 'your',
|
||||
'me', 'am', 'is', 'do', 'are',
|
||||
'what', 'who', 'where', 'how', 'no', 'yes',
|
||||
'not', 'did', 'were', 'can', 'could', 'it',
|
||||
'the', 'to'
|
||||
],
|
||||
theme: 'auto',
|
||||
load: false
|
||||
}
|
||||
},
|
||||
sideIsOpen: false,
|
||||
isDictation: true,
|
||||
simpleWords: [
|
||||
'a', 'an', 'of', 'and',
|
||||
'i', 'my', 'you', 'your',
|
||||
'me', 'am', 'is', 'do', 'are',
|
||||
'what', 'who', 'where', 'how', 'no', 'yes',
|
||||
'not', 'did', 'were', 'can', 'could', 'it',
|
||||
'the', 'to'
|
||||
],
|
||||
theme: 'auto',
|
||||
load: false
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
skipWordNames: (state: State) => {
|
||||
return state.skipWordDict.originWords.map(v => v.name.toLowerCase())
|
||||
},
|
||||
skipWordNamesWithSimpleWords: (state: State) => {
|
||||
return state.skipWordDict.originWords.map(v => v.name.toLowerCase()).concat(state.simpleWords)
|
||||
},
|
||||
isArticle(state: State): boolean {
|
||||
return [DictType.publicArticle, DictType.customArticle].includes(state.current.dictType)
|
||||
},
|
||||
currentDict(state: State): Dict {
|
||||
switch (state.current.dictType) {
|
||||
case DictType.newDict:
|
||||
return state.newWordDict
|
||||
case DictType.skipDict:
|
||||
return state.skipWordDict
|
||||
case DictType.wrongDict:
|
||||
return state.wrongWordDict
|
||||
case DictType.publicDict:
|
||||
case DictType.publicArticle:
|
||||
case DictType.customDict:
|
||||
return state.dict
|
||||
}
|
||||
},
|
||||
wordIndex(state: State): number {
|
||||
return this.currentDict.wordIndex
|
||||
},
|
||||
chapter(state: State): Word[] {
|
||||
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
|
||||
},
|
||||
word(state: State): Word {
|
||||
return state.current.words[state.current.index] ?? {
|
||||
trans: [],
|
||||
name: '',
|
||||
usphone: '',
|
||||
ukphone: '',
|
||||
}
|
||||
},
|
||||
dictTitle(state: State) {
|
||||
let title = this.currentDict.name
|
||||
if ([DictType.publicDict, DictType.customDict].includes(this.current.dictType)) {
|
||||
title += ` 第${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)
|
||||
},
|
||||
setCurrentWord(words: Word[], restart: boolean = false, index: number = 0) {
|
||||
this.current.words = cloneDeep(words)
|
||||
if (restart) {
|
||||
this.current.repeatNumber = 0
|
||||
this.current.originWrongWords = []
|
||||
this.current.statistics = {
|
||||
startDate: Date.now(),
|
||||
endDate: -1,
|
||||
spend: -1,
|
||||
wordNumber: words.length,
|
||||
correctRate: -1,
|
||||
wrongWordNumber: -1,
|
||||
getters: {
|
||||
skipWordNames: (state: State) => {
|
||||
return state.skipWordDict.originWords.map(v => v.name.toLowerCase())
|
||||
},
|
||||
skipWordNamesWithSimpleWords: (state: State) => {
|
||||
return state.skipWordDict.originWords.map(v => v.name.toLowerCase()).concat(state.simpleWords)
|
||||
},
|
||||
isArticle(state: State): boolean {
|
||||
return [DictType.publicArticle, DictType.customArticle].includes(state.current.dictType)
|
||||
},
|
||||
currentDict(state: State): Dict {
|
||||
switch (state.current.dictType) {
|
||||
case DictType.newDict:
|
||||
return state.newWordDict
|
||||
case DictType.skipDict:
|
||||
return state.skipWordDict
|
||||
case DictType.wrongDict:
|
||||
return state.wrongWordDict
|
||||
case DictType.publicDict:
|
||||
case DictType.publicArticle:
|
||||
case DictType.customDict:
|
||||
return state.dict
|
||||
}
|
||||
},
|
||||
wordIndex(state: State): number {
|
||||
return this.currentDict.wordIndex
|
||||
},
|
||||
chapter(state: State): Word[] {
|
||||
return this.currentDict.chapterWords[this.currentDict.chapterIndex] ?? []
|
||||
},
|
||||
word(state: State): Word {
|
||||
return state.current.words[state.current.index] ?? {
|
||||
trans: [],
|
||||
name: '',
|
||||
usphone: '',
|
||||
ukphone: '',
|
||||
}
|
||||
},
|
||||
dictTitle(state: State) {
|
||||
let title = this.currentDict.name
|
||||
if ([DictType.publicDict, DictType.customDict].includes(this.current.dictType)) {
|
||||
title += ` 第${this.currentDict.chapterIndex + 1}章`
|
||||
}
|
||||
return title
|
||||
}
|
||||
} else {
|
||||
this.current.repeatNumber++
|
||||
if (!this.current.originWrongWords.length) {
|
||||
this.current.originWrongWords = cloneDeep(this.current.wrongWords)
|
||||
},
|
||||
actions: {
|
||||
setState(obj: any) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
this[key] = value
|
||||
}
|
||||
// console.log('this/', this)
|
||||
},
|
||||
setCurrentWord(words: Word[], restart: boolean = false, index: number = 0) {
|
||||
this.current.words = cloneDeep(words)
|
||||
if (restart) {
|
||||
this.current.repeatNumber = 0
|
||||
this.current.originWrongWords = []
|
||||
this.current.statistics = {
|
||||
startDate: Date.now(),
|
||||
endDate: -1,
|
||||
spend: -1,
|
||||
wordNumber: words.length,
|
||||
correctRate: -1,
|
||||
wrongWordNumber: -1,
|
||||
}
|
||||
} else {
|
||||
this.current.repeatNumber++
|
||||
if (!this.current.originWrongWords.length) {
|
||||
this.current.originWrongWords = cloneDeep(this.current.wrongWords)
|
||||
}
|
||||
this.current.statistics.correctRate = -1
|
||||
this.current.statistics.wrongWordNumber = -1
|
||||
}
|
||||
this.current.index = index
|
||||
this.current.wrongWords = []
|
||||
},
|
||||
async init() {
|
||||
// let configStr = localStorage.getItem(SaveKey)
|
||||
// if (configStr) {
|
||||
// let obj: Config = JSON.parse(configStr)
|
||||
// this.setState(obj)
|
||||
// }
|
||||
if (this.current.dictType === DictType.publicDict) {
|
||||
let r = await fetch(`/public/${this.dict.url}`)
|
||||
r.json().then(v => {
|
||||
this.dict.originWords = cloneDeep(v)
|
||||
this.dict.words = cloneDeep(v)
|
||||
this.dict.chapterWords = chunk(this.dict.words, this.dict.chapterWordNumber)
|
||||
this.setCurrentWord(this.chapter, true)
|
||||
this.load = true
|
||||
})
|
||||
}
|
||||
if (this.current.dictType === DictType.publicArticle) {
|
||||
let r = await fetch(`/public/${this.dict.url}`)
|
||||
r.json().then(v => {
|
||||
this.dict.articles = cloneDeep(v)
|
||||
this.load = true
|
||||
})
|
||||
}
|
||||
},
|
||||
saveStatistics(statistics: Statistics) {
|
||||
if (statistics.spend > 1000 * 10) {
|
||||
this.currentDict.statistics.push(statistics)
|
||||
}
|
||||
},
|
||||
async changeDict(dict: Dict, chapterIndex: number = dict.chapterIndex, chapterWordIndex: number = dict.chapterWordNumber) {
|
||||
this.saveStatistics()
|
||||
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
|
||||
this.current.dictType = dict.type
|
||||
if ([DictType.newDict,
|
||||
DictType.skipDict,
|
||||
DictType.wrongDict].includes(dict.type)) {
|
||||
this[dict.type].chapterIndex = chapterIndex
|
||||
this[dict.type].chapterWordIndex = chapterWordIndex
|
||||
} else {
|
||||
this.dict = cloneDeep(dict)
|
||||
if (dict.originWords.length) {
|
||||
let r = await fetch(`/public/${this.dict.url}`)
|
||||
let v = await r.json()
|
||||
this.dict.originWords = cloneDeep(v)
|
||||
this.dict.words = cloneDeep(v)
|
||||
this.dict.chapters = chunk(this.dict.words, this.dict.chapterWordNumber)
|
||||
}
|
||||
this.dict.chapterIndex = chapterIndex
|
||||
this.dict.chapterWordIndex = chapterWordIndex
|
||||
}
|
||||
this.setCurrentWord(this.chapter, true, chapterWordIndex)
|
||||
emitter.emit(EventKey.resetWord)
|
||||
}
|
||||
this.current.statistics.correctRate = -1
|
||||
this.current.statistics.wrongWordNumber = -1
|
||||
}
|
||||
this.current.index = index
|
||||
this.current.wrongWords = []
|
||||
},
|
||||
async init() {
|
||||
// let configStr = localStorage.getItem(SaveKey)
|
||||
// if (configStr) {
|
||||
// let obj: Config = JSON.parse(configStr)
|
||||
// this.setState(obj)
|
||||
// }
|
||||
if (this.current.dictType === DictType.publicDict) {
|
||||
let r = await fetch(`/public/${this.dict.url}`)
|
||||
r.json().then(v => {
|
||||
this.dict.originWords = cloneDeep(v)
|
||||
this.dict.words = cloneDeep(v)
|
||||
this.dict.chapterWords = chunk(this.dict.words, this.dict.chapterWordNumber)
|
||||
this.setCurrentWord(this.chapter, true)
|
||||
this.load = true
|
||||
})
|
||||
}
|
||||
if (this.current.dictType === DictType.publicArticle) {
|
||||
let r = await fetch(`/public/${this.dict.url}`)
|
||||
r.json().then(v => {
|
||||
this.dict.articles = cloneDeep(v)
|
||||
this.load = true
|
||||
})
|
||||
}
|
||||
},
|
||||
saveStatistics(statistics: Statistics) {
|
||||
if (statistics.spend > 1000 * 10) {
|
||||
this.currentDict.statistics.push(statistics)
|
||||
}
|
||||
},
|
||||
async changeDict(dict: Dict, chapterIndex: number = dict.chapterIndex, chapterWordIndex: number = dict.chapterWordNumber) {
|
||||
this.saveStatistics()
|
||||
console.log('changeDict', cloneDeep(dict), chapterIndex, chapterWordIndex)
|
||||
this.current.dictType = dict.type
|
||||
if ([DictType.newDict,
|
||||
DictType.skipDict,
|
||||
DictType.wrongDict].includes(dict.type)) {
|
||||
this[dict.type].chapterIndex = chapterIndex
|
||||
this[dict.type].chapterWordIndex = chapterWordIndex
|
||||
} else {
|
||||
this.dict = cloneDeep(dict)
|
||||
if (dict.originWords.length) {
|
||||
let r = await fetch(`/public/${this.dict.url}`)
|
||||
let v = await r.json()
|
||||
this.dict.originWords = cloneDeep(v)
|
||||
this.dict.words = cloneDeep(v)
|
||||
this.dict.chapters = chunk(this.dict.words, this.dict.chapterWordNumber)
|
||||
}
|
||||
this.dict.chapterIndex = chapterIndex
|
||||
this.dict.chapterWordIndex = chapterWordIndex
|
||||
}
|
||||
this.setCurrentWord(this.chapter, true, chapterWordIndex)
|
||||
emitter.emit(EventKey.resetWord)
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -1,68 +1,69 @@
|
||||
import {createApp} from 'vue'
|
||||
import Modal from "@/components/Modal/Modal.vue";
|
||||
import Modal, {ModalProps} from "@/components/Modal/Modal.vue";
|
||||
import {AppContext, Component, ComponentPublicInstance, createVNode, getCurrentInstance, render, VNode} from 'vue';
|
||||
|
||||
export class MessageBox {
|
||||
static confirm(
|
||||
content: string,
|
||||
title: string,
|
||||
onOk: () => any = () => void 0,
|
||||
onCancel: () => any = () => void 0,
|
||||
) {
|
||||
let remove = () => {
|
||||
let parent = document.querySelector('.dialog-ctn')
|
||||
parent.remove()
|
||||
}
|
||||
let tempOnCancel = () => {
|
||||
remove()
|
||||
onCancel()
|
||||
static confirm(
|
||||
content: string,
|
||||
title: string,
|
||||
onOk: () => any = () => void 0,
|
||||
onCancel: () => any = () => void 0,
|
||||
config: ModalProps = {}
|
||||
) {
|
||||
let container = document.createElement('div')
|
||||
const close = () => {
|
||||
render(null, container);
|
||||
container.remove()
|
||||
}
|
||||
let tempOnCancel = () => {
|
||||
onCancel()
|
||||
close()
|
||||
}
|
||||
let tempOnOk = () => {
|
||||
onOk()
|
||||
close()
|
||||
}
|
||||
const vNode = createVNode(Modal, {
|
||||
title,
|
||||
content,
|
||||
onCancel: tempOnCancel,
|
||||
onOk: tempOnOk,
|
||||
footer: true,
|
||||
...config
|
||||
});
|
||||
// const appContext = getCurrentInstance()?.appContext;
|
||||
// // 补丁:Component中获取当前组件树的provides
|
||||
// if (appContext) {
|
||||
// const currentProvides = (getCurrentInstance() as any)?.provides;
|
||||
// Reflect.set(appContext, 'provides', {...appContext.provides, ...currentProvides});
|
||||
// }
|
||||
// vNode.appContext = appContext;
|
||||
render(vNode, container);
|
||||
document.body.append(container)
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
render() {
|
||||
return <Modal
|
||||
footer={true}
|
||||
title={title}
|
||||
onOk={onOk}
|
||||
padding={true}
|
||||
onCancel={tempOnCancel}
|
||||
>
|
||||
<div style=' width: 350rem;color: black;'>{content}</div>
|
||||
</Modal>
|
||||
},
|
||||
})
|
||||
let parent = document.createElement('div')
|
||||
parent.classList.add(...['dialog-ctn'])
|
||||
document.body.append(parent)
|
||||
app.mount(parent)
|
||||
}
|
||||
|
||||
static notice(
|
||||
content: string,
|
||||
title: string,
|
||||
) {
|
||||
let remove = () => {
|
||||
let parent = document.querySelector('.dialog-ctn')
|
||||
parent.remove()
|
||||
static notice(
|
||||
content: string,
|
||||
title: string,
|
||||
) {
|
||||
let container = document.createElement('div')
|
||||
let tempOnCancel = () => {
|
||||
render(null, container);
|
||||
container.remove()
|
||||
}
|
||||
const vNode = createVNode(Modal, {
|
||||
title,
|
||||
content,
|
||||
onCancel: tempOnCancel,
|
||||
});
|
||||
// const appContext = getCurrentInstance()?.appContext;
|
||||
// // 补丁:Component中获取当前组件树的provides
|
||||
// if (appContext) {
|
||||
// const currentProvides = (getCurrentInstance() as any)?.provides;
|
||||
// Reflect.set(appContext, 'provides', {...appContext.provides, ...currentProvides});
|
||||
// }
|
||||
// vNode.appContext = appContext;
|
||||
render(vNode, container);
|
||||
document.body.append(container)
|
||||
}
|
||||
let tempOnCancel = () => {
|
||||
remove()
|
||||
}
|
||||
|
||||
const app = createApp({
|
||||
render() {
|
||||
return <Modal
|
||||
footer={false}
|
||||
title={title}
|
||||
padding={true}
|
||||
onCancel={tempOnCancel}
|
||||
>
|
||||
<div style=' width: 350rem;color: black;'>{content}</div>
|
||||
</Modal>
|
||||
},
|
||||
})
|
||||
let parent = document.createElement('div')
|
||||
parent.classList.add(...['dialog-ctn'])
|
||||
document.body.append(parent)
|
||||
app.mount(parent)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user