Perfect the module of adding articles
This commit is contained in:
4
components.d.ts
vendored
4
components.d.ts
vendored
@@ -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']
|
||||
|
||||
@@ -20,6 +20,7 @@ import {useBaseStore} from "@/stores/base.ts";
|
||||
import {$ref} from "vue/macros";
|
||||
import List from "@/components/List.vue";
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import {Icon} from "@iconify/vue";
|
||||
|
||||
interface IProps {
|
||||
article?: Article
|
||||
@@ -33,6 +34,7 @@ const base = useBaseStore()
|
||||
let article = $ref<Article>(cloneDeep(props.article))
|
||||
let networkTranslateEngine = $ref('baidu')
|
||||
let progress = $ref(0)
|
||||
let failCount = $ref(0)
|
||||
const TranslateEngineOptions = [
|
||||
{value: 'baidu', label: '百度'},
|
||||
{value: 'youdao', label: '有道'},
|
||||
@@ -112,10 +114,10 @@ function renewSections() {
|
||||
if (article.text.trim()) {
|
||||
renewSectionTexts(article)
|
||||
if (article.useTranslateType === TranslateType.custom) {
|
||||
renewSectionTranslates(article, article.textCustomTranslate)
|
||||
failCount = renewSectionTranslates(article, article.textCustomTranslate)
|
||||
}
|
||||
if (article.useTranslateType === TranslateType.network) {
|
||||
renewSectionTranslates(article, article.textNetworkTranslate)
|
||||
failCount = renewSectionTranslates(article, article.textNetworkTranslate)
|
||||
}
|
||||
} else {
|
||||
article.sections = []
|
||||
@@ -247,7 +249,7 @@ function selectArticle(item: Article) {
|
||||
if (!article?.sections?.length) {
|
||||
renewSections()
|
||||
}
|
||||
console.log('article', article)
|
||||
// console.log('article', article)
|
||||
}
|
||||
|
||||
function add() {
|
||||
@@ -503,8 +505,14 @@ function exportData() {
|
||||
</div>
|
||||
</div>
|
||||
<div class="options" v-if="article.text.trim()">
|
||||
<BaseButton @click="save('save')">保存</BaseButton>
|
||||
<BaseButton @click="save('next')">保存并添加下一篇</BaseButton>
|
||||
<div class="warning">
|
||||
<Icon icon="typcn:warning-outline"/>
|
||||
共有{{ failCount }}句没有翻译!
|
||||
</div>
|
||||
<div class="left">
|
||||
<BaseButton @click="save('save')">保存</BaseButton>
|
||||
<BaseButton @click="save('next')">保存并添加下一篇</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -667,8 +675,22 @@ function exportData() {
|
||||
|
||||
.options {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: $space;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.warning {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 20rem;
|
||||
color: red;
|
||||
gap: $space;
|
||||
|
||||
}
|
||||
|
||||
.left {
|
||||
gap: $space;
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import {getSplitTranslateText, splitEnArticle} from "@/hooks/article.ts";
|
||||
import {Translator} from "@opentranslate/translator/src/translator.ts";
|
||||
|
||||
export function renewSectionTranslates(article: Article, translate: string) {
|
||||
let failCount = 0
|
||||
if (translate.trim()) {
|
||||
let articleTranslate = translate.split('\n')
|
||||
console.log('articleTranslate', articleTranslate)
|
||||
// console.log('articleTranslate', articleTranslate)
|
||||
let count = 0
|
||||
for (let i = 0; i < article.sections.length; i++) {
|
||||
@@ -14,15 +16,22 @@ export function renewSectionTranslates(article: Article, translate: string) {
|
||||
for (let j = 0; j < v.length; j++) {
|
||||
let sentence = v[j]
|
||||
try {
|
||||
sentence.translate = articleTranslate[count]
|
||||
let trans = articleTranslate[count]
|
||||
if (trans) {
|
||||
sentence.translate = trans
|
||||
} else {
|
||||
failCount++
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('没有对应的翻译', sentence.text)
|
||||
failCount++
|
||||
// console.log('没有对应的翻译', sentence.text)
|
||||
}
|
||||
count++
|
||||
}
|
||||
count++
|
||||
}
|
||||
}
|
||||
return failCount
|
||||
}
|
||||
|
||||
export function getSentenceAllTranslateText(article: Article) {
|
||||
|
||||
Reference in New Issue
Block a user