From ba1dbdfbb1636da86f4539e87b34d1e8b757716f Mon Sep 17 00:00:00 2001 From: zyronon Date: Tue, 22 Jul 2025 00:14:51 +0800 Subject: [PATCH] feat:save --- js_node/fail.txt | 3 -- js_node/failDict.txt | 5 --- js_node/failWord.txt | 29 ------------ js_node/从原始词典提取单词.cjs | 37 --------------- js_node/将失败单词查出全量单词信息.cjs | 37 --------------- src/pages/pc/components/BaseTable.vue | 8 ++-- src/pages/pc/components/Book.vue | 10 ++++- src/pages/pc/word/DictDetail.vue | 20 +++++++-- src/pages/pc/word/WordHomePage.vue | 62 +++++++++++++++++++++----- src/utils/index.ts | 2 +- 10 files changed, 81 insertions(+), 132 deletions(-) delete mode 100644 js_node/fail.txt delete mode 100644 js_node/failDict.txt delete mode 100644 js_node/failWord.txt delete mode 100644 js_node/从原始词典提取单词.cjs delete mode 100644 js_node/将失败单词查出全量单词信息.cjs diff --git a/js_node/fail.txt b/js_node/fail.txt deleted file mode 100644 index 22eed8b5..00000000 --- a/js_node/fail.txt +++ /dev/null @@ -1,3 +0,0 @@ -[ - "an" -] \ No newline at end of file diff --git a/js_node/failDict.txt b/js_node/failDict.txt deleted file mode 100644 index 127aa4ff..00000000 --- a/js_node/failDict.txt +++ /dev/null @@ -1,5 +0,0 @@ -{ - "韦氏词根词典": [ - "philippic" - ] -} \ No newline at end of file diff --git a/js_node/failWord.txt b/js_node/failWord.txt deleted file mode 100644 index 174cdca9..00000000 --- a/js_node/failWord.txt +++ /dev/null @@ -1,29 +0,0 @@ -[ - { - "id": 1330, - "word": "an", - "trans": [ - { - "pos": "indefinite article", - "cn": "一(个)〔用于以元音开头的单词前〕", - "en": "used when the following word begins with a vowel sound" - } - ], - "phonetic0": "ən,æn", - "phonetic1": "ə ; æn", - "sentences": [ - { - "v": "一个橘子", - "tran": "an orange" - }, - { - "v": "一次X光检查", - "tran": "an X-ray" - } - ], - "relWords": [], - "phrases": [], - "synos": [], - "memory": "" - } -] \ No newline at end of file diff --git a/js_node/从原始词典提取单词.cjs b/js_node/从原始词典提取单词.cjs deleted file mode 100644 index 609abdbf..00000000 --- a/js_node/从原始词典提取单词.cjs +++ /dev/null @@ -1,37 +0,0 @@ -let path = require("path"); -let fs = require("fs"); - -//词典来自:https://github.com/kajweb/dict -//下载json词典,放到dict目录下 - -let read = './dict/' -let save = "./res/"; - -//判断是不是目录 -const dirs = fs.readdirSync(read) -dirs.forEach(dictName => { - formatDict(read, dictName) -}) - -// formatDict(read, 'BEC_2.json') - -function formatDict(path, name) { - try { - let newObj = [] - let str = fs.readFileSync(path + name, "utf8"); - let list = str.split('\n') - list.map(v => { - if (!v) return - let item = JSON.parse(v) - // console.log('v', item.headWord) - newObj.push(item.headWord) - }) - - // fs.writeFileSync(save + name, JSON.stringify(newObj, null, 2)); - fs.writeFileSync(save + name.replace('.json', '_word.json'), JSON.stringify(newObj)); - console.log(name, newObj.length) - } catch (e) { - console.log('err', name, e) - } -} - diff --git a/js_node/将失败单词查出全量单词信息.cjs b/js_node/将失败单词查出全量单词信息.cjs deleted file mode 100644 index 4935f0e1..00000000 --- a/js_node/将失败单词查出全量单词信息.cjs +++ /dev/null @@ -1,37 +0,0 @@ -let path = require("path"); -let fs = require("fs"); -const axios = require('axios') - -let str = fs.readFileSync('./save/allNew.min.json', "utf8"); -let failStr = fs.readFileSync('./fail.txt', "utf8"); - -let failList = JSON.parse(failStr) -let list = JSON.parse(str) - -async function sleep(val) { - return new Promise(resolve => { - setTimeout(resolve, val) - }) -} - -let s = [] - -function fail(word) { - s.push(word) - console.log('失败:', s.length) - fs.writeFileSync('./failWord.txt', JSON.stringify(s, null, 2)); -} - -// console.log('failList',failList) -async function test() { - for (let i = 0; i < list.length; i++) { - // for (let i = 0; i < 3000; i++) { - let v = list[i] - if (failList.includes(v.word)) { - console.log('进度', v.word) - fail(v) - } - } -} - -test() diff --git a/src/pages/pc/components/BaseTable.vue b/src/pages/pc/components/BaseTable.vue index fe6a073f..57c4f129 100644 --- a/src/pages/pc/components/BaseTable.vue +++ b/src/pages/pc/components/BaseTable.vue @@ -71,11 +71,11 @@ let selectAll = $computed(() => { }) function toggleSelect(item) { - let rIndex = selectIds.findIndex(v => v === item.word) + let rIndex = selectIds.findIndex(v => v === item.id) if (rIndex > -1) { selectIds.splice(rIndex, 1) } else { - selectIds.push(item.word) + selectIds.push(item.id) } } @@ -83,7 +83,7 @@ function toggleSelectAll() { if (selectAll) { selectIds = [] } else { - selectIds = currentList.map(v => v.word) + selectIds = currentList.map(v => v.id) } } @@ -118,7 +118,7 @@ const s = useSlots() defineRender( () => { const d = (item) => toggleSelect(item)} size="large"/> diff --git a/src/pages/pc/components/Book.vue b/src/pages/pc/components/Book.vue index 1b419700..c5120a36 100644 --- a/src/pages/pc/components/Book.vue +++ b/src/pages/pc/components/Book.vue @@ -7,6 +7,11 @@ defineProps<{ quantifier?: string isAdd: boolean showCheckbox?: boolean + checked?: boolean +}>() + +defineEmits<{ + check: [] }>() @@ -19,7 +24,10 @@ defineProps<{
{{ item?.description }}
{{ item?.length }}{{ quantifier }}
- +
-import {getDefaultWord} from "@/types"; +import {getDefaultDict, getDefaultWord} from "@/types"; import type {Word} from "@/types"; import BasePage from "@/pages/pc/components/BasePage.vue"; @@ -17,7 +17,7 @@ import BaseButton from "@/components/BaseButton.vue"; import {useRoute, useRouter} from "vue-router"; import {useBaseStore} from "@/stores/base.ts"; import EditBook from "@/pages/pc/article/components/EditBook.vue"; -import {_nextTick} from "@/utils"; +import {_getDictDataByUrl, _nextTick} from "@/utils"; const runtimeStore = useRuntimeStore() const base = useBaseStore() @@ -270,9 +270,18 @@ const showBookDetail = computed(() => { onMounted(() => { if (route.query?.isAdd) { isAdd = true + runtimeStore.editDict = getDefaultDict() } else { if (!runtimeStore.editDict.id) { router.push("/word") + } else { + if (!runtimeStore.editDict.words.length && !runtimeStore.editDict.custom) { + loading = true + _getDictDataByUrl(runtimeStore.editDict).then(r => { + loading = false + runtimeStore.editDict = r + }) + } } } }) @@ -282,7 +291,12 @@ function formClose() { else router.back() } -function addMyStudyList() { +async function addMyStudyList() { + base.word.bookList.slice(3).map(v => { + if (!v.custom) { + v.words = [] + } + }) let rIndex = base.word.bookList.findIndex(v => v.name === runtimeStore.editDict.name) if (rIndex > -1) { base.word.studyIndex = rIndex diff --git a/src/pages/pc/word/WordHomePage.vue b/src/pages/pc/word/WordHomePage.vue index c3b176d8..f34f89fe 100644 --- a/src/pages/pc/word/WordHomePage.vue +++ b/src/pages/pc/word/WordHomePage.vue @@ -8,7 +8,7 @@ import BaseIcon from "@/components/BaseIcon.vue"; import Dialog from "@/pages/pc/components/dialog/Dialog.vue"; import {_getAccomplishDate, _getAccomplishDays, _getDictDataByUrl, useNav} from "@/utils"; import BasePage from "@/pages/pc/components/BasePage.vue"; -import {Dict, DictResource} from "@/types.ts"; +import {Dict, DictResource, getDefaultDict} from "@/types.ts"; import {onMounted} from "vue"; import {getCurrentStudyWord} from "@/hooks/dict.ts"; import {EventKey, useEvent} from "@/utils/eventBus.ts"; @@ -16,6 +16,7 @@ import DictListPanel from "@/pages/pc/components/DictListPanel.vue"; import {cloneDeep} from "lodash-es"; import {useRuntimeStore} from "@/stores/runtime.ts"; import Book from "@/pages/pc/components/Book.vue"; +import PopConfirm from "@/pages/pc/components/PopConfirm.vue"; const store = useBaseStore() const router = useRouter() @@ -74,19 +75,39 @@ function selectDict(e) { getDictDetail(e.dict) } -async function goDictDetail2(val: Dict) { - runtimeStore.editDict = cloneDeep(val) - nav('dict-detail', {}) -} - async function getDictDetail(val: DictResource) { - let r = await _getDictDataByUrl(val) - runtimeStore.editDict = cloneDeep(r) + runtimeStore.editDict = getDefaultDict(val) nav('dict-detail', {}) } let dictListRef = $ref() +let isMultiple = $ref(false) +let selectIds = $ref([]) +function handleBatchDel() { + selectIds.forEach(id => { + let r = store.word.bookList.findIndex(v => v.id === id) + if (r !== -1) { + if (store.word.studyIndex === r) { + store.word.studyIndex = -1 + } + if (store.word.studyIndex > r) { + store.word.studyIndex-- + } + store.word.bookList.splice(r, 1) + } + }) + ElMessage.success("删除成功!") +} + +function toggleSelect(item) { + let rIndex = selectIds.findIndex(v => v === item.id) + if (rIndex > -1) { + selectIds.splice(rIndex, 1) + } else { + selectIds.push(item.id) + } +} @@ -162,8 +183,22 @@ let dictListRef = $ref()
我的词典
-
-
管理词典
+
+ + + + +
{{ isMultiple ? '取消' : '管理词典' }} +
创建个人词典
@@ -171,8 +206,11 @@ let dictListRef = $ref() + :checked="selectIds.includes(item.id)" + @check="() => toggleSelect(item)" + :show-checkbox="isMultiple && j>=3" + v-for="(item,j) in store.word.bookList" + @click="getDictDetail(item)"/>
diff --git a/src/utils/index.ts b/src/utils/index.ts index 8d5c5e27..2ffa13ca 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -288,7 +288,7 @@ export function _parseLRC(lrc: string): { start: number, end: number, text: stri return parsed; } -export async function _getDictDataByUrl(val: DictResource) { +export async function _getDictDataByUrl(val: DictResource): Promise { let dictResourceUrl = `./dicts/${val.language}/word/${val.url}`.replace('.json', '_v2.json'); let s = await getDictFile(dictResourceUrl) let words = cloneDeep(s.map(v => {