diff --git a/components.d.ts b/components.d.ts index ffb49ddf..9631e2f5 100644 --- a/components.d.ts +++ b/components.d.ts @@ -21,11 +21,15 @@ declare module 'vue' { DictModal: typeof import('./src/components/Toolbar/DictModal.vue')['default'] EditAbleText: typeof import('./src/components/EditAbleText.vue')['default'] ElInput: typeof import('element-plus/es')['ElInput'] + ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] ElOption: typeof import('element-plus/es')['ElOption'] ElProgress: typeof import('element-plus/es')['ElProgress'] + ElRadio: typeof import('element-plus/es')['ElRadio'] ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] ElSelect: typeof import('element-plus/es')['ElSelect'] + ElSlider: typeof import('element-plus/es')['ElSlider'] + ElSwitch: typeof import('element-plus/es')['ElSwitch'] FeedbackModal: typeof import('./src/components/Toolbar/FeedbackModal.vue')['default'] Fireworks: typeof import('./src/components/Fireworks.vue')['default'] Footer: typeof import('./src/components/Practice/Footer.vue')['default'] diff --git a/src/components/Add/AddArticle2.vue b/src/components/Add/AddArticle2.vue index 5533e9b0..08b92069 100644 --- a/src/components/Add/AddArticle2.vue +++ b/src/components/Add/AddArticle2.vue @@ -21,6 +21,7 @@ import {useBaseStore} from "@/stores/base.ts"; import {$computed, $ref} from "vue/macros"; import Input from "@/components/Input.vue"; import List from "@/components/List.vue"; +import {v4 as uuidv4} from 'uuid'; interface IProps { selectIndex?: number @@ -32,10 +33,7 @@ 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: '百度'}, @@ -71,12 +69,6 @@ watch(() => props.article, n => { } }) -onMounted(() => { - if (selectIndex > -1) { - article = base.currentEditDict.articles[selectIndex] - } -}) - async function startNetworkTranslate() { if (!article.title.trim()) { return ElMessage.error('请填写标题!') @@ -184,7 +176,7 @@ function save(option: 'save' | 'next') { } let has = base.currentEditDict.articles.find((item: Article) => item.title === article.title) - if (has && selectIndex === -1) { + if (has && !article.id) { return ElMessage.error('已存在同名文章!') } @@ -192,18 +184,22 @@ function save(option: 'save' | 'next') { article.textCustomTranslateIsFormat = true // emit('close') // emit('save', cloneDeep(article)) - if (selectIndex > -1) { - base.currentEditDict.articles[selectIndex] = cloneDeep(article) + if (article.id) { + let rIndex = base.currentEditDict.articles.findIndex(v => v.id === article.id) + if (rIndex > -1) { + base.currentEditDict.articles[rIndex] = cloneDeep(article) + } } else { - base.currentEditDict.articles.push(cloneDeep(article)) + let data = {...article, id: uuidv4()} + base.currentEditDict.articles.push(data) if (option === 'save') { - selectIndex = base.currentEditDict.articles.length - 1 + article = cloneDeep(data) } } if (option === 'next') { - selectIndex = -1 article = cloneDeep(DefaultArticle) } + //TODO 保存完成后滚动到对应位置 ElMessage.success('保存成功!') } @@ -268,41 +264,8 @@ 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(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]) - } - } +function selectArticle(item: Article) { + article = cloneDeep(item) } @@ -315,12 +278,10 @@ function delArticle(item: Article) {