diff --git a/components.d.ts b/components.d.ts index 41a66791..ffb49ddf 100644 --- a/components.d.ts +++ b/components.d.ts @@ -16,6 +16,7 @@ declare module 'vue' { BatchAddArticle: typeof import('./src/components/Add/BatchAddArticle.vue')['default'] ChapterDetail: typeof import('./src/components/ChapterDetail.vue')['default'] ChapterList: typeof import('./src/components/ChapterList.vue')['default'] + Close: typeof import('./src/components/Close.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'] @@ -29,6 +30,8 @@ declare module 'vue' { Fireworks: typeof import('./src/components/Fireworks.vue')['default'] Footer: typeof import('./src/components/Practice/Footer.vue')['default'] IconWrapper: typeof import('./src/components/IconWrapper.vue')['default'] + Input: typeof import('./src/components/Input.vue')['default'] + List: typeof import('./src/components/List.vue')['default'] MiniModal: typeof import('./src/components/MiniModal.vue')['default'] Modal: typeof import('./src/components/Modal/Modal.vue')['default'] PopConfirm: typeof import('./src/components/PopConfirm.vue')['default'] diff --git a/package.json b/package.json index a80bfe2b..47f511bf 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "dependencies": { "@opentranslate/baidu": "^1.4.2", "@opentranslate/translator": "^1.4.2", + "@types/uuid": "^9.0.4", "axios": "^1.5.0", "copy-to-clipboard": "^3.3.3", "element-plus": "^2.3.9", @@ -26,6 +27,7 @@ "pinia": "^2.1.6", "swiper": "^10.1.0", "tesseract.js": "^4.1.1", + "uuid": "^9.0.1", "vue": "^3.3.4" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1f430dc3..5e2090ee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ dependencies: '@opentranslate/translator': specifier: ^1.4.2 version: 1.4.2 + '@types/uuid': + specifier: ^9.0.4 + version: 9.0.4 axios: specifier: ^1.5.0 version: 1.5.0 @@ -41,6 +44,9 @@ dependencies: tesseract.js: specifier: ^4.1.1 version: 4.1.1 + uuid: + specifier: ^9.0.1 + version: 9.0.1 vue: specifier: ^3.3.4 version: 3.3.4 @@ -875,6 +881,10 @@ packages: resolution: {integrity: sha512-u95svzDlTysU5xecFNTgfFG5RUWu1A9P0VzgpcIiGZA9iraHOdSzcxMxQ55DyeRaGCSxQi7LxXDI4rzq/MYfdg==} dev: false + /@types/uuid@9.0.4: + resolution: {integrity: sha512-zAuJWQflfx6dYJM62vna+Sn5aeSWhh3OB+wfUEACNcqUSc0AGc5JKl+ycL1vrH7frGTXhJchYjE1Hak8L819dA==} + dev: false + /@types/web-bluetooth@0.0.16: resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==} dev: false @@ -2985,6 +2995,11 @@ packages: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} dev: true + /uuid@9.0.1: + resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==} + hasBin: true + dev: false + /v8-compile-cache-lib@3.0.1: resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} requiresBuild: true diff --git a/src/components/Add/AddArticle2.vue b/src/components/Add/AddArticle2.vue index ee550950..5533e9b0 100644 --- a/src/components/Add/AddArticle2.vue +++ b/src/components/Add/AddArticle2.vue @@ -18,7 +18,9 @@ import {useDisableEventListener} from "@/hooks/event.ts"; import {MessageBox} from "@/utils/MessageBox.tsx"; import BaseIcon from "@/components/BaseIcon.vue"; import {useBaseStore} from "@/stores/base.ts"; -import {$ref} from "vue/macros"; +import {$computed, $ref} from "vue/macros"; +import Input from "@/components/Input.vue"; +import List from "@/components/List.vue"; interface IProps { selectIndex?: number @@ -31,7 +33,9 @@ const props = withDefaults(defineProps(), { const base = useBaseStore() let article = $ref
(cloneDeep(DefaultArticle)) let selectIndex = $ref(props.selectIndex) +let selectItem = $ref(props.selectIndex) let networkTranslateEngine = $ref('baidu') +let searchKey = $ref('') let progress = $ref(0) const TranslateEngineOptions = [ {value: 'baidu', label: '百度'}, @@ -264,26 +268,43 @@ watch(() => article.useTranslateType, () => { } }) +const list = $computed(() => { + if (searchKey) { + return base.currentEditDict.articles.filter((item: Article) => { + //把搜索内容,分词之后,判断是否有这个词,比单纯遍历包含体验更好 + return searchKey.toLowerCase().split(' ').filter(v => v).some(value => { + return item.title.toLowerCase().includes(value) || item.titleTranslate.toLowerCase().includes(value) + }) + }) + } else { + return base.currentEditDict.articles + } +}) + function selectArticle(index: number) { article = cloneDeep(base.currentEditDict.articles[index]) selectIndex = index } -function delArticle(index: number) { - if (index < selectIndex) { - selectIndex-- - } else if (index === selectIndex) { - if (selectIndex === base.currentEditDict.articles.length - 1) { +function delArticle(item: Article) { + let rIndex = base.currentEditDict.articles.findIndex((v: Article) => v.id === item.id) + if (rIndex > -1) { + if (index < selectIndex) { selectIndex-- + } else if (index === selectIndex) { + if (selectIndex === base.currentEditDict.articles.length - 1) { + selectIndex-- + } + } + base.currentEditDict.articles.splice(index, 1) + if (selectIndex < 0) { + article = cloneDeep(DefaultArticle) + } else { + article = cloneDeep(base.currentEditDict.articles[selectIndex]) } } - base.currentEditDict.articles.splice(index, 1) - if (selectIndex < 0) { - article = cloneDeep(DefaultArticle) - } else { - article = cloneDeep(base.currentEditDict.articles[selectIndex]) - } } +