소스 검색

自动翻译默认翻译中文

zq 22 시간 전
부모
커밋
70370fd782
1개의 변경된 파일34개의 추가작업 그리고 24개의 파일을 삭제
  1. 34 24
      src/components/TranslateDialog.vue

+ 34 - 24
src/components/TranslateDialog.vue

@@ -1,6 +1,11 @@
 <template>
-  <el-dialog :title="titleText" :visible.sync="visible" width="600px" :close-on-click-modal="false"
-    @close="dialogClose()">
+  <el-dialog
+    :title="titleText"
+    :visible.sync="visible"
+    width="600px"
+    :close-on-click-modal="false"
+    @close="dialogClose()"
+  >
     <div class="translate-container">
       <div class="translate-section">
         <div class="section-label">原文:</div>
@@ -16,8 +21,9 @@
 
       <div class="translate-section">
         <div class="section-label">译文:</div>
-        <div class="text-content translated-text" :style="{ lineHeight: lang === 'ZH' ? '1' : '1.5' }">{{
-          translateResultText }}</div>
+        <div class="text-content translated-text" :style="{ lineHeight: lang === 'ZH' ? '1' : '1.5' }">
+          {{ translateResultText }}
+        </div>
       </div>
     </div>
 
@@ -32,8 +38,7 @@ import { GetLanguageTypeList, Texttrans } from '@/api/book';
 
 export default {
   name: 'TranslateDialog',
-  components: {
-  },
+  components: {},
   props: {
     open: {
       type: Boolean,
@@ -67,7 +72,7 @@ export default {
       if (!this.translateResultList || this.translateResultList.length === 0) {
         return '';
       }
-      let resultText = this.translateResultList.map(item => item.dst);
+      let resultText = this.translateResultList.map((item) => item.dst);
       return resultText.join('\n');
     },
   },
@@ -86,6 +91,13 @@ export default {
         this.lang = 'ZH';
       }
     },
+    langList(newVal) {
+      if (newVal && newVal.length > 0 && this.initText) {
+        this.$nextTick(() => {
+          this.fetchTranslation();
+        });
+      }
+    },
   },
   methods: {
     dialogClose() {
@@ -97,11 +109,9 @@ export default {
      */
     getLangList() {
       if (!this.bookId) return;
-      GetLanguageTypeList({ book_id: this.bookId, is_contain_zh: 'true' }).then(
-        ({ language_type_list }) => {
-          this.langList = language_type_list;
-        },
-      );
+      GetLanguageTypeList({ book_id: this.bookId, is_contain_zh: 'true' }).then(({ language_type_list }) => {
+        this.langList = language_type_list;
+      });
     },
 
     /**
@@ -123,15 +133,17 @@ export default {
       const params = {
         text: this.initText,
         from: 'zh',
-        to: this.lang
-      }
-      Texttrans(params).then(res => {
-        if (res.status == 1) {
-          this.translateResultList = res.trans_list || [];
-        }
-      }).catch(err => {
-        this.$message.error('翻译失败');
-      });
+        to: this.lang,
+      };
+      Texttrans(params)
+        .then((res) => {
+          if (res.status == 1) {
+            this.translateResultList = res.trans_list || [];
+          }
+        })
+        .catch((err) => {
+          this.$message.error('翻译失败');
+        });
     },
   },
 };
@@ -191,13 +203,11 @@ export default {
     display: flex;
     flex-direction: column;
     row-gap: 8px;
-    padding: 10pX;
+    padding: 10px;
 
     .el-textarea__inner {
       height: 108px;
     }
   }
-
-
 }
 </style>