update dicts

This commit is contained in:
zyronon
2023-10-22 17:56:05 +08:00
parent 8b93f51617
commit de72b26abc
144 changed files with 464 additions and 413 deletions

View File

@@ -2,11 +2,14 @@
import {onMounted, watch} from "vue";
import {useBaseStore} from "@/stores/base.ts";
import {SaveDictKey} from "@/types.ts"
import {DictResource, SaveDictKey} from "@/types.ts"
import Practice from "@/components/Practice/Practice.vue"
import {useEventListener, useStartKeyboardEventListener} from "@/hooks/event.ts";
import {useRuntimeStore} from "@/stores/runtime.ts";
import {useSettingStore} from "@/stores/setting.ts";
import {dictionaryResources} from "@/assets/dictionary.ts";
import {groupBy} from "lodash-es";
import {$ref} from "vue/macros";
const store = useBaseStore()
const runtimeStore = useRuntimeStore()
@@ -43,12 +46,16 @@ useEventListener('keyup', (e: KeyboardEvent) => {
lastItem && lastItem.close()
}
})
onMounted(() => {
})
</script>
<template>
<!-- <Backgorund/>-->
<div class="main-page">
<Practice/>
<Practice/>
<!-- <AddArticle/>-->
<!-- <Side/>-->
</div>

File diff suppressed because it is too large Load Diff

View File

@@ -113,7 +113,7 @@ onMounted(() => {
emitter.on(EventKey.resetWord, () => {
wrong = input = ''
})
fetch('./dicts/coca20000.json').then(r => {
fetch('./translate/en2zh_CN.json').then(r => {
r.json().then(v => {
console.log('v', v)
allList = v

View File

@@ -2,15 +2,15 @@
import {Icon} from "@iconify/vue";
import {$computed, $ref} from "vue/macros";
import {watch} from "vue";
import {DictionaryResource} from "@/types.ts";
import {DictResource} from "@/types.ts";
const props = defineProps<{
category?: string,
category: string,
groupByTag: any,
selectDictName: string
}>()
const emit = defineEmits<{
selectDict: [index: DictionaryResource],
selectDict: [index: DictResource],
detail: [],
}>()
const tagList = $computed(() => Object.keys(props.groupByTag))
@@ -18,7 +18,6 @@ let currentTag = $ref(tagList[0])
let list = $computed(() => {
return props.groupByTag[currentTag]
})
let step = $ref(0)
watch(() => props.groupByTag, () => {
currentTag = tagList[0]
@@ -27,30 +26,45 @@ watch(() => props.groupByTag, () => {
</script>
<template>
<div class="tags">
<div class="tag" :class="i === currentTag &&'active'"
@click="currentTag = i"
v-for="i in Object.keys(groupByTag)">{{ i }}
<div class="dict-group">
<div class="category">{{ category }}</div>
<div class="tags">
<div class="tag" :class="i === currentTag &&'active'"
@click="currentTag = i"
v-for="i in Object.keys(groupByTag)">{{ i }}
</div>
</div>
</div>
<div class="dict-list">
<div class="dict-item anim"
:class="selectDictName === i.name && 'active'"
@click="emit('selectDict',i)"
v-for="i in list"
>
<div class="name">{{ i.name }}</div>
<div class="desc">{{ i.description }}</div>
<div class="num">{{ i.length }}</div>
<div class="dict-list">
<div class="dict-item anim"
:class="selectDictName === i.name && 'active'"
@click="emit('selectDict',i)"
v-for="i in list"
>
<div class="name">{{ i.name }}</div>
<div class="desc">{{ i.description }}</div>
<div class="num">{{ i.length }}</div>
<Icon icon="octicon:arrow-right-24" v-if="selectDictName === i.name"
@click.stop="emit('detail')"
class="go" width="20" color="#929596"/>
<Icon icon="octicon:arrow-right-24" v-if="selectDictName === i.name"
@click.stop="emit('detail')"
class="go" width="20" color="#929596"/>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
.dict-group {
color: black;
margin-bottom: 40rem;
//border-bottom: 1px dashed gray;
.category {
font-size: 24rem;
padding-bottom: 10rem;
border-bottom: 1px dashed gray;
}
}
.tags {
display: flex;
flex-wrap: wrap;

View File

@@ -2,8 +2,8 @@
import {dictionaryResources} from '@/assets/dictionary.ts'
import {useBaseStore} from "@/stores/base.ts"
import {watch} from "vue"
import {Dict, DictionaryResource, DictType, languageCategoryOptions, Sort, Word} from "@/types.ts"
import {chunk, cloneDeep} from "lodash-es";
import {Dict, DictResource, DictType, languageCategoryOptions, Sort, Word} from "@/types.ts"
import {chunk, cloneDeep, groupBy} from "lodash-es";
import {$computed, $ref} from "vue/macros";
import Modal from "@/components/Modal/Modal.vue";
import BaseButton from "@/components/BaseButton.vue";
@@ -42,6 +42,10 @@ const emit = defineEmits<{
const base = useBaseStore()
const settingStore = useSettingStore()
let currentLanguage = $ref('en')
let currentTranslateLanguage = $ref('common')
let groupByLanguage = groupBy(dictionaryResources, 'language')
let translateLanguageList = $ref([])
let step = $ref(1)
watch(() => props.modelValue, (n: boolean) => {
@@ -51,7 +55,8 @@ watch(() => props.modelValue, (n: boolean) => {
}
})
async function selectDict(item: DictionaryResource) {
async function selectDict(item: DictResource) {
console.log('item',item)
step = 1
let find = base.myDicts.find((v: Dict) => v.name === item.name)
if (find) {
@@ -71,10 +76,11 @@ async function selectDict(item: DictionaryResource) {
...item,
}
if (item.language === 'article') {
if (item.resourceType === 'article') {
data.type = DictType.publicArticle
let r = await fetch(`${item.url}`)
let r = await fetch(`/dicts/${item.language}/${item.resourceType}/${item.translateLanguage}/${item.url}`)
r.json().then(v => {
console.log('v', v)
data.articles = cloneDeep(v.map(v => {
v.id = uuidv4()
return v
@@ -83,7 +89,7 @@ async function selectDict(item: DictionaryResource) {
})
} else {
data.type = DictType.publicDict
let r = await fetch(`${item.url}`)
let r = await fetch(`/dicts/${item.language}/${item.resourceType}/${item.translateLanguage}/${item.url}`)
r.json().then(v => {
data.originWords = v
data.words = v
@@ -108,20 +114,8 @@ function resetChapterList() {
runtimeStore.editDict.chapterWords = chunk(runtimeStore.editDict.words, runtimeStore.editDict.chapterWordNumber)
}
function groupBy<T>(elements: T[], iteratee: (value: T) => string) {
return elements.reduce<Record<string, T[]>>((result, value) => {
const key = iteratee(value)
if (Object.prototype.hasOwnProperty.call(result, key)) {
result[key].push(value)
} else {
result[key] = [value]
}
return result
}, {})
}
function groupByDictTags(dicts: DictionaryResource[]) {
return dicts.reduce<Record<string, DictionaryResource[]>>((result, dict) => {
function groupByDictTags(dictList: DictResource[]) {
return dictList.reduce<Record<string, DictResource[]>>((result, dict) => {
dict.tags.forEach((tag) => {
if (Object.prototype.hasOwnProperty.call(result, tag)) {
result[tag].push(dict)
@@ -133,17 +127,30 @@ function groupByDictTags(dicts: DictionaryResource[]) {
}, {})
}
const groupedByCategoryAndTag = $computed(() => {
const currentLanguageCategoryDicts = dictionaryResources.filter((dict) => dict.language === currentLanguage)
const groupedByCategory = Object.entries(groupBy(currentLanguageCategoryDicts, (dict) => dict.category))
const groupedByCategoryAndTag = groupedByCategory.map(
([category, dicts]) => [category, groupByDictTags(dicts)] as [string, Record<string, DictionaryResource[]>],
)
// console.log('groupedByCategoryAndTag', groupedByCategoryAndTag)
return groupedByCategoryAndTag
const groupByTranslateLanguage = $computed(() => {
let data: any
if (currentLanguage === 'article') {
let articleList = dictionaryResources.filter(v => v.resourceType === 'article')
data = groupBy(articleList, 'translateLanguage')
} else {
data = groupBy(groupByLanguage[currentLanguage], 'translateLanguage')
}
translateLanguageList = Object.keys(data)
currentTranslateLanguage = translateLanguageList[0]
return data
})
let radio1 = $ref('')
const groupedByCategoryAndTag = $computed(() => {
const currentTranslateLanguageDictList = groupByTranslateLanguage[currentTranslateLanguage]
const groupByCategory = groupBy(currentTranslateLanguageDictList, 'category')
let data = []
for (const [key, value] of Object.entries(groupByCategory)) {
data.push([key, groupByDictTags(value)])
}
// console.log('data', data)
return data
})
function clickEvent(e) {
console.log('e', e)
@@ -181,12 +188,20 @@ const dictIsArticle = $computed(() => {
</header>
<div class="page-content">
<div class="dict-list-wrapper">
<div class="translate">
<span>翻译</span>
<el-radio-group v-model="currentTranslateLanguage">
<el-radio v-for="i in translateLanguageList" :label="i">{{ i }}</el-radio>
</el-radio-group>
</div>
<DictGroup
v-for="item in groupedByCategoryAndTag"
:select-dict-name="runtimeStore.editDict.name"
@selectDict="selectDict"
@detail="step = 1"
:groupByTag="item[1]"/>
:groupByTag="item[1]"
:category="item[0]"
/>
</div>
</div>
</div>
@@ -258,15 +273,15 @@ const dictIsArticle = $computed(() => {
</el-radio-group>
</div>
</div>
<!-- <div class="row">-->
<!-- <div class="label">词序</div>-->
<!-- <div class="option">-->
<!-- <el-radio-group v-model="radio1" class="ml-4">-->
<!-- <el-radio label="1" size="large">随机</el-radio>-->
<!-- <el-radio label="2" size="large">正常</el-radio>-->
<!-- </el-radio-group>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="row">-->
<!-- <div class="label">词序</div>-->
<!-- <div class="option">-->
<!-- <el-radio-group v-model="radio1" class="ml-4">-->
<!-- <el-radio label="1" size="large">随机</el-radio>-->
<!-- <el-radio label="2" size="large">正常</el-radio>-->
<!-- </el-radio-group>-->
<!-- </div>-->
<!-- </div>-->
<div class="row">
<div class="label">单词自动发音</div>
<div class="option">
@@ -413,6 +428,15 @@ $header-height: 60rem;
overflow: auto;
height: 100%;
padding-right: $space;
.translate {
color: black;
margin-bottom: 30rem;
& > span {
font-size: 22rem;
}
}
}
}
}

View File

@@ -86,7 +86,7 @@ export async function getNetworkTranslate(
if (translator) {
if (!article.titleTranslate) {
translator.translate(article.title, 'en', 'zh-CN').then(r => {
translator.translate(article.title, 'en', 'common').then(r => {
article.titleTranslate = r.trans.paragraphs[0]
})
}
@@ -97,7 +97,7 @@ export async function getNetworkTranslate(
const translate = async (sentence: Sentence) => {
try {
let r = await translator.translate(sentence.text, 'en', 'zh-CN')
let r = await translator.translate(sentence.text, 'en', 'common')
if (r) {
const cb = () => {
sentence.translate = r.trans.paragraphs[0]

View File

@@ -81,7 +81,10 @@ export const useBaseStore = defineStore('base', {
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '/articles/NCE_2.json',
url: 'NCE_2.json',
translateLanguage: 'common',
language: 'en',
resourceType: "article"
},
{
id:'新概念英语2',
@@ -96,7 +99,10 @@ export const useBaseStore = defineStore('base', {
chapterIndex: 0,
chapterWordIndex: 0,
statistics: [],
url: '/dicts/NCE_2.json',
url: 'nce-new-2.json',
translateLanguage: 'common',
language: 'en',
resourceType: "word"
}
],
current: {
@@ -192,7 +198,8 @@ export const useBaseStore = defineStore('base', {
DictType.customDict,
].includes(this.current.dictType)) {
if (!this.currentDict.originWords.length) {
let r = await fetch(`.${this.currentDict.url}`)
let r = await fetch(`/dicts/${this.currentDict.language}/${this.currentDict.resourceType}/${this.currentDict.translateLanguage}/${this.currentDict.url}`)
// let r = await fetch(`.${this.currentDict.url}`)
r.json().then(v => {
this.currentDict.originWords = cloneDeep(v)
this.currentDict.words = cloneDeep(v)
@@ -207,7 +214,7 @@ export const useBaseStore = defineStore('base', {
DictType.customArticle,
].includes(this.current.dictType)) {
if (!this.currentDict.articles.length) {
let r = await fetch(`.${this.currentDict.url}`)
let r = await fetch(`/dicts/${this.currentDict.language}/${this.currentDict.resourceType}/${this.currentDict.translateLanguage}/${this.currentDict.url}`)
r.json().then((v: any[]) => {
this.currentDict.articles = cloneDeep(v.map(v => {
v.id = uuidv4()

View File

@@ -23,11 +23,11 @@ export const SaveConfigKey = 'typing-word-config'
export const PronunciationApi = 'https://dict.youdao.com/dictvoice?audio='
export type TranslateLanguageType = 'en' | 'zh-CN' | 'ja' | 'de' | ''
export type TranslateLanguageType = 'en' | 'zh-CN' | 'ja' | 'de' | 'common' | ''
export type LanguageType = 'en' | 'ja' | 'de' | 'code'
export type ResourceType = 'word' | 'article'
export type DictionaryResource = {
export type DictResource = {
id: string
name: string
description: string
@@ -36,7 +36,7 @@ export type DictionaryResource = {
url: string
length: number
translateLanguage: TranslateLanguageType
type: ResourceType
resourceType: ResourceType
language: LanguageType
}