This commit is contained in:
zyronon
2023-12-03 00:28:07 +08:00
parent 834fce25e6
commit 66fc64b5f7
4 changed files with 265 additions and 226 deletions

View File

@@ -32,13 +32,15 @@ let router = useRouter()
let step = $ref(1)
let loading = $ref(false)
let show = $ref(false)
function close() {
show = false
}
let chapterList2 = $ref([])
const activeId = $computed(() => {
if (dictIsArticle) {
return runtimeStore.editDict.articles?.[runtimeStore.editDict.chapterIndex].id ?? ''
}
return ''
})
async function selectDict(val: { dict: DictResource | Dict, index: number }) {
let item = val.dict
// console.log('item', item)
@@ -93,6 +95,11 @@ async function selectDict(val: { dict: DictResource | Dict, index: number }) {
loading = false
}
function close() {
show = false
}
function changeDict() {
store.changeDict(runtimeStore.editDict)
close()
@@ -185,6 +192,14 @@ function showWordListModal(val: { item: Word, index: number }) {
list: runtimeStore.editDict.chapterWords[val.index]
})
}
function handleChangeArticleChapterIndex(val) {
let rIndex = runtimeStore.editDict.articles.findIndex(v => v.id === val.item.id)
if (rIndex > -1) {
runtimeStore.editDict.chapterIndex = rIndex
}
}
</script>
<template>
@@ -341,11 +356,11 @@ function showWordListModal(val: { item: Word, index: number }) {
v-loading="loading"
:show-border="true"
@title="(val:any) => emitter.emit(EventKey.openArticleListModal,val.item)"
@click="(val:any) => runtimeStore.editDict.chapterIndex = val.index"
:active-index="runtimeStore.editDict.chapterIndex"
@click="handleChangeArticleChapterIndex"
:active-id="activeId"
:list="runtimeStore.editDict.articles">
<template v-slot:prefix="{item,index}">
<input type="radio" :checked="runtimeStore.editDict.chapterIndex === index">
<input type="radio" :checked="activeId === item.id">
</template>
</ArticleList>
<Empty v-else/>

View File

@@ -23,6 +23,10 @@ import {useWindowClick} from "@/hooks/event.ts";
import ArticleList from "@/components/list/ArticleList.vue";
import * as copy from "copy-to-clipboard";
const emit = defineEmits<{
back: []
}>()
const store = useBaseStore()
const settingStore = useSettingStore()
const runtimeStore = useRuntimeStore()
@@ -38,33 +42,9 @@ const isPinDict = $computed(() => {
return [DictType.collect, DictType.wrong, DictType.simple].includes(runtimeStore.editDict.type)
})
function handleCheckedChange(val) {
chapterIndex = val.index
article = val.item
}
function delArticle(index: number) {
runtimeStore.editDict.articles.splice(index, 1)
if (runtimeStore.editDict.articles.length) {
if (chapterIndex >= runtimeStore.editDict.articles.length - 1) {
chapterIndex = runtimeStore.editDict.articles.length - 1
article = runtimeStore.editDict.articles[chapterIndex]
}
if (chapterIndex === index) {
article = runtimeStore.editDict.articles[chapterIndex]
}
} else {
article = cloneDeep(DefaultArticle)
chapterIndex = -1
}
syncMyDictList(runtimeStore.editDict)
ElMessage.success('删除成功!')
}
const emit = defineEmits<{
back: []
}>()
const activeId = $computed(() => {
return runtimeStore.editDict.articles?.[chapterIndex]?.id ?? ''
})
async function getDictDetail(val: {
dict: DictResource | Dict,
@@ -102,6 +82,34 @@ async function getDictDetail(val: {
loading = false
}
function handleCheckedChange(val) {
let rIndex = runtimeStore.editDict.articles.findIndex(v => v.id === val.item.id)
if (rIndex > -1) {
chapterIndex = rIndex
article = val.item
}
}
function delArticle(index: number) {
runtimeStore.editDict.articles.splice(index, 1)
if (runtimeStore.editDict.articles.length) {
if (chapterIndex >= runtimeStore.editDict.articles.length - 1) {
chapterIndex = runtimeStore.editDict.articles.length - 1
article = runtimeStore.editDict.articles[chapterIndex]
}
if (chapterIndex === index) {
article = runtimeStore.editDict.articles[chapterIndex]
}
} else {
article = cloneDeep(DefaultArticle)
chapterIndex = -1
}
syncMyDictList(runtimeStore.editDict)
ElMessage.success('删除成功!')
}
async function resetDict() {
MessageBox.confirm(
'删除所有自定义内容: 章节、排序、单词,并恢复至默认状态,确认恢复?',
@@ -321,9 +329,9 @@ defineExpose({getDictDetail, add, editDict})
:list="runtimeStore.editDict.articles"
@title="handleCheckedChange"
@click="handleCheckedChange"
:active-index="chapterIndex">
:active-id="activeId">
<template v-slot:prefix="{item,index}">
<input type="radio" :checked="chapterIndex === index">
<input type="radio" :checked="activeId === item.id">
</template>
<template v-slot:suffix="{item,index}">
<BaseIcon

View File

@@ -1,7 +1,16 @@
<script setup lang="ts">
import {$ref} from "vue/macros";
import TypingArticle from "./TypingArticle.vue";
import {Article, ArticleWord, DefaultArticle, DisplayStatistics, ShortcutKey, TranslateType, Word} from "@/types.ts";
import {
Article,
ArticleItem,
ArticleWord,
DefaultArticle,
DisplayStatistics,
ShortcutKey,
TranslateType,
Word
} from "@/types.ts";
import {cloneDeep} from "lodash-es";
import TypingWord from "@/pages/practice/practice-word/TypingWord.vue";
import Panel from "../Panel.vue";
@@ -204,10 +213,7 @@ function nextWord(word: ArticleWord) {
}
}
function changePracticeArticle(val: {
item: Article,
index: number
}) {
function changePracticeArticle(val: ArticleItem) {
let rIndex = store.currentDict.articles.findIndex(v => v.id === val.item.id)
if (rIndex > -1) {
store.currentDict.chapterIndex = rIndex

View File

@@ -7,19 +7,19 @@ import myFlag from "@/assets/img/flags/my.png";
import {DefaultChapterWordNumber} from "@/stores/setting.ts";
export type Word = {
"name": string,
"usphone": string,
"ukphone": string,
"trans": string[]
checked?: boolean,
id?: any,
"name": string,
"usphone": string,
"ukphone": string,
"trans": string[]
checked?: boolean,
id?: any,
}
export const DefaultWord: Word = {
name: '',
usphone: '',
ukphone: '',
trans: []
name: '',
usphone: '',
ukphone: '',
trans: []
}
export const PronunciationApi = 'https://dict.youdao.com/dictvoice?audio='
@@ -28,240 +28,250 @@ export type TranslateLanguageType = 'en' | 'zh-CN' | 'ja' | 'de' | 'common' | ''
export type LanguageType = 'en' | 'ja' | 'de' | 'code'
export type DictResource = {
id: string
name: string
description: string
url: string
length: number
category: string
tags: string[]
translateLanguage: TranslateLanguageType
type: DictType
language: LanguageType
id: string
name: string
description: string
url: string
length: number
category: string
tags: string[]
translateLanguage: TranslateLanguageType
type: DictType
language: LanguageType
}
export enum DictType {
collect = 'collect',
simple = 'simple',
wrong = 'wrong',
word = 'word',
customWord = 'customWord',
article = 'article',
customArticle = 'customArticle'
collect = 'collect',
simple = 'simple',
wrong = 'wrong',
word = 'word',
customWord = 'customWord',
article = 'article',
customArticle = 'customArticle'
}
export const DefaultArticleWord: ArticleWord = {
name: '',
usphone: '',
ukphone: '',
trans: [],
nextSpace: true,
isSymbol: false,
symbolPosition: ''
name: '',
usphone: '',
ukphone: '',
trans: [],
nextSpace: true,
isSymbol: false,
symbolPosition: ''
}
export interface ArticleWord extends Word {
nextSpace: boolean,
isSymbol: boolean,
symbolPosition: 'start' | 'end' | '',
nextSpace: boolean,
isSymbol: boolean,
symbolPosition: 'start' | 'end' | '',
}
export interface Sentence {
text: string,
translate: string,
words: ArticleWord[]
text: string,
translate: string,
words: ArticleWord[]
}
export enum TranslateType {
custom = 'custom',
network = 'network',
none = 'none'
custom = 'custom',
network = 'network',
none = 'none'
}
export interface Article {
id: string,
title: string,
titleTranslate: string,
text: string,
textCustomTranslate: string,
textCustomTranslateIsFormat: boolean,//翻译是否格式化
textNetworkTranslate: string,
newWords: Word[],
textAllWords: string[],
sections: Sentence[][],
useTranslateType: TranslateType
id: string,
title: string,
titleTranslate: string,
text: string,
textCustomTranslate: string,
textCustomTranslateIsFormat: boolean,//翻译是否格式化
textNetworkTranslate: string,
newWords: Word[],
textAllWords: string[],
sections: Sentence[][],
useTranslateType: TranslateType
}
export const DefaultArticle: Article = {
// id: nanoid(6),
id: '',
title: '',
titleTranslate: '',
text: '',
textCustomTranslate: '',
textNetworkTranslate: '',
textCustomTranslateIsFormat: false,
newWords: [],
textAllWords: [],
sections: [],
useTranslateType: TranslateType.network
// id: nanoid(6),
id: '',
title: '',
titleTranslate: '',
text: '',
textCustomTranslate: '',
textNetworkTranslate: '',
textCustomTranslateIsFormat: false,
newWords: [],
textAllWords: [],
sections: [],
useTranslateType: TranslateType.network
}
export interface Statistics {
startDate: number,//开始日期
endDate: number//结束日期
spend: number,//花费时间
total: number//单词数量
wrongWordNumber: number//错误数
correctRate: number//正确率
startDate: number,//开始日期
endDate: number//结束日期
spend: number,//花费时间
total: number//单词数量
wrongWordNumber: number//错误数
correctRate: number//正确率
}
export interface DisplayStatistics extends Statistics {
wrongWords: Word[]
inputWordNumber: number//输入数
wrongWords: Word[]
inputWordNumber: number//输入数
}
export const DefaultDisplayStatistics: DisplayStatistics = {
startDate: Date.now(),
endDate: -1,
spend: -1,
total: -1,
correctRate: -1,
wrongWordNumber: -1,
inputWordNumber: -1,
wrongWords: [],
startDate: Date.now(),
endDate: -1,
spend: -1,
total: -1,
correctRate: -1,
wrongWordNumber: -1,
inputWordNumber: -1,
wrongWords: [],
}
export enum Sort {
normal = 0,
random = 1,
reverse = 2
normal = 0,
random = 1,
reverse = 2
}
export const ShortcutKeyMap = {
Show: 'Escape',
Ignore: 'Tab',
Remove: '`',
Collect: 'Enter',
Show: 'Escape',
Ignore: 'Tab',
Remove: '`',
Collect: 'Enter',
}
export const SaveDict = {
key: 'typing-word-dict',
version: 1
key: 'typing-word-dict',
version: 1
}
export const SaveConfig = {
key: 'typing-word-config',
version: 8
key: 'typing-word-config',
version: 8
}
export enum ShortcutKey {
ShowWord = 'ShowWord',
EditArticle = 'EditArticle',
Next = 'Next',
Previous = 'Previous',
ToggleSimple = 'ToggleSimple',
ToggleCollect = 'ToggleCollect',
NextChapter = 'NextChapter',
PreviousChapter = 'PreviousChapter',
RepeatChapter = 'RepeatChapter',
DictationChapter = 'DictationChapter',
PlayWordPronunciation = 'PlayWordPronunciation',
// PlayTranslatePronunciation = 'PlayTranslatePronunciation',
ToggleShowTranslate = 'ToggleShowTranslate',
ToggleDictation = 'ToggleDictation',
OpenSetting = 'OpenSetting',
OpenDictDetail = 'OpenDictDetail',
ToggleTheme = 'ToggleTheme',
ToggleConciseMode = 'ToggleConciseMode',
TogglePanel = 'TogglePanel'
ShowWord = 'ShowWord',
EditArticle = 'EditArticle',
Next = 'Next',
Previous = 'Previous',
ToggleSimple = 'ToggleSimple',
ToggleCollect = 'ToggleCollect',
NextChapter = 'NextChapter',
PreviousChapter = 'PreviousChapter',
RepeatChapter = 'RepeatChapter',
DictationChapter = 'DictationChapter',
PlayWordPronunciation = 'PlayWordPronunciation',
// PlayTranslatePronunciation = 'PlayTranslatePronunciation',
ToggleShowTranslate = 'ToggleShowTranslate',
ToggleDictation = 'ToggleDictation',
OpenSetting = 'OpenSetting',
OpenDictDetail = 'OpenDictDetail',
ToggleTheme = 'ToggleTheme',
ToggleConciseMode = 'ToggleConciseMode',
TogglePanel = 'TogglePanel'
}
export const DefaultShortcutKeyMap = {
[ShortcutKey.EditArticle]: 'Ctrl+E',
[ShortcutKey.ShowWord]: 'Escape',
[ShortcutKey.Previous]: 'Alt+⬅',
[ShortcutKey.Next]: 'Tab',
[ShortcutKey.ToggleSimple]: '`',
[ShortcutKey.ToggleCollect]: 'Enter',
[ShortcutKey.PreviousChapter]: 'Ctrl+⬅',
[ShortcutKey.NextChapter]: 'Ctrl+➡',
[ShortcutKey.RepeatChapter]: 'Ctrl+Enter',
[ShortcutKey.DictationChapter]: 'Alt+Enter',
[ShortcutKey.PlayWordPronunciation]: 'Ctrl+P',
// [ShortcutKey.PlayTranslatePronunciation]: 'Ctrl+O',
[ShortcutKey.ToggleShowTranslate]: 'Ctrl+Z',
[ShortcutKey.ToggleDictation]: 'Ctrl+I',
[ShortcutKey.OpenSetting]: 'Ctrl+S',
[ShortcutKey.ToggleTheme]: 'Ctrl+Q',
[ShortcutKey.OpenDictDetail]: 'Ctrl+J',
[ShortcutKey.ToggleConciseMode]: 'Ctrl+M',
[ShortcutKey.TogglePanel]: 'Ctrl+L',
[ShortcutKey.EditArticle]: 'Ctrl+E',
[ShortcutKey.ShowWord]: 'Escape',
[ShortcutKey.Previous]: 'Alt+⬅',
[ShortcutKey.Next]: 'Tab',
[ShortcutKey.ToggleSimple]: '`',
[ShortcutKey.ToggleCollect]: 'Enter',
[ShortcutKey.PreviousChapter]: 'Ctrl+⬅',
[ShortcutKey.NextChapter]: 'Ctrl+➡',
[ShortcutKey.RepeatChapter]: 'Ctrl+Enter',
[ShortcutKey.DictationChapter]: 'Alt+Enter',
[ShortcutKey.PlayWordPronunciation]: 'Ctrl+P',
// [ShortcutKey.PlayTranslatePronunciation]: 'Ctrl+O',
[ShortcutKey.ToggleShowTranslate]: 'Ctrl+Z',
[ShortcutKey.ToggleDictation]: 'Ctrl+I',
[ShortcutKey.OpenSetting]: 'Ctrl+S',
[ShortcutKey.ToggleTheme]: 'Ctrl+Q',
[ShortcutKey.OpenDictDetail]: 'Ctrl+J',
[ShortcutKey.ToggleConciseMode]: 'Ctrl+M',
[ShortcutKey.TogglePanel]: 'Ctrl+L',
}
export enum TranslateEngine {
Baidu = 0,
Baidu = 0,
}
export const languageCategoryOptions = [
{id: 'article', name: '文章', flag: bookFlag},
{id: 'en', name: '英语', flag: enFlag},
{id: 'ja', name: '日语', flag: jpFlag},
{id: 'de', name: '德语', flag: deFlag},
{id: 'code', name: 'Code', flag: codeFlag},
{id: 'my', name: '我的', flag: myFlag},
{id: 'article', name: '文章', flag: bookFlag},
{id: 'en', name: '英语', flag: enFlag},
{id: 'ja', name: '日语', flag: jpFlag},
{id: 'de', name: '德语', flag: deFlag},
{id: 'code', name: 'Code', flag: codeFlag},
{id: 'my', name: '我的', flag: myFlag},
]
export const DefaultDict: Dict = {
id: '',
name: '',
description: '',
sort: Sort.normal,
originWords: [],//原始单词
words: [],
chapterWordNumber: DefaultChapterWordNumber,//章节单词数量
chapterWords: [],
residueWords: [],//未分配单词
chapterIndex: 0,//章节下标
wordIndex: 0,//单词下标
articles: [],
statistics: [],
isCustom: false,
length: 0,
/*资源属性*/
resourceId: '',
url: '',
category: '',
tags: [],
translateLanguage: 'common',
type: DictType.customWord,
language: 'en',
id: '',
name: '',
description: '',
sort: Sort.normal,
originWords: [],//原始单词
words: [],
chapterWordNumber: DefaultChapterWordNumber,//章节单词数量
chapterWords: [],
residueWords: [],//未分配单词
chapterIndex: 0,//章节下标
wordIndex: 0,//单词下标
articles: [],
statistics: [],
isCustom: false,
length: 0,
/*资源属性*/
resourceId: '',
url: '',
category: '',
tags: [],
translateLanguage: 'common',
type: DictType.customWord,
language: 'en',
}
export interface Dict {
id: string,
name: string,
description: string,
sort: Sort,
originWords: Word[],//原始单词
words: Word[],
chapterWordNumber: number,//章节单词数量
chapterWords: Word[][],
residueWords: Word[],
chapterIndex: number,//章节下标
wordIndex: number,//单词下标
articles: Article[],
statistics: Statistics[],
isCustom: boolean,
length: number,
/*资源属性*/
resourceId: string,
category: string
tags: string[]
language: LanguageType
type: DictType
translateLanguage: TranslateLanguageType
url: string,
id: string,
name: string,
description: string,
sort: Sort,
originWords: Word[],//原始单词
words: Word[],
chapterWordNumber: number,//章节单词数量
chapterWords: Word[][],
residueWords: Word[],
chapterIndex: number,//章节下标
wordIndex: number,//单词下标
articles: Article[],
statistics: Statistics[],
isCustom: boolean,
length: number,
/*资源属性*/
resourceId: string,
category: string
tags: string[]
language: LanguageType
type: DictType
translateLanguage: TranslateLanguageType
url: string,
}
export interface ArticleItem {
item: Article,
index: number
}
export interface WordItem {
item: Article,
index: number
}