chengjie 4 月之前
父节点
当前提交
82b1316719
共有 4 个文件被更改,包括 102 次插入6 次删除
  1. 2 1
      .vscode/settings.json
  2. 25 1
      public/mg/yjbdc_articles.html
  3. 43 4
      src/api/yjbdc/aiController.js
  4. 32 0
      src/api/yjbdc/yjbdcController.js

+ 2 - 1
.vscode/settings.json

@@ -25,5 +25,6 @@
25 25
     "accessibility.signals.terminalBell": {
26 26
         "sound": "off"
27 27
     },
28
-    "terminal.integrated.enableVisualBell": false
28
+    "terminal.integrated.enableVisualBell": false,
29
+    "Lingma.PreferredLanguage forCommitMessage": "简体中文"
29 30
 }

+ 25 - 1
public/mg/yjbdc_articles.html

@@ -535,7 +535,7 @@
535 535
                                 @blur="finishEdit" @keyup.enter="finishEdit" v-focus>
536 536
                         </template>
537 537
                         <template v-else>
538
-                            "{{ selectedArticle.Level }}"
538
+                            "{{ selectedArticle.Level }} {{ getLevelName(selectedArticle.Level) }}"
539 539
                         </template>
540 540
                     </span>
541 541
                 </div>
@@ -693,6 +693,30 @@
693 693
                         this.showToastFlag = false;
694 694
                     }, 3000);
695 695
                 },
696
+                getLevelName(level){
697
+                    let result="";
698
+                    switch(level){
699
+                        case "0":
700
+                            result="A1";
701
+                            break;
702
+                        case "1":
703
+                            result="A2";
704
+                            break;
705
+                        case "2":
706
+                            result="B1";
707
+                            break;
708
+                        case "3":
709
+                            result="B2";
710
+                            break;
711
+                        case "4":
712
+                            result="C1";
713
+                            break;
714
+                        case "5":
715
+                            result="C2";
716
+                            break;
717
+                    }
718
+                    return result;
719
+                },
696 720
             },
697 721
             directives: {
698 722
                 focus: {

+ 43 - 4
src/api/yjbdc/aiController.js

@@ -631,10 +631,16 @@ function validateAndFixJSON(jsonString) {
631 631
 
632 632
 /**
633 633
  * 标准化文章字段,将修正版本的内容应用到标准字段中
634
- * @param {Object} json - 包含文章内容的JSON对象
635
- * @returns {Object} - 返回标准化后的JSON对象
634
+ * @param {string|Object} jsonInput - 包含文章内容的JSON字符串或对象
635
+ * @returns {string|Object} - 返回标准化后的JSON字符串或对象,与输入类型保持一致
636 636
  */
637
-function normalizeArticleFields(json) {
637
+function normalizeArticleFields(jsonInput) {
638
+    // 判断输入是字符串还是对象
639
+    const isString = typeof jsonInput === 'string';
640
+    
641
+    // 如果是字符串,先解析为对象
642
+    let json = isString ? JSON.parse(jsonInput) : jsonInput;
643
+    
638 644
     if (json.ArticleEnglishCorrected){
639 645
         json.ArticleEnglish=json.ArticleEnglishCorrected;
640 646
         delete json.ArticleEnglishCorrected;
@@ -643,7 +649,40 @@ function normalizeArticleFields(json) {
643 649
         json.ArticleChinese=json.ArticleChineseCorrected;
644 650
         delete json.ArticleChineseCorrected;
645 651
     }
646
-    return json;
652
+    
653
+    // 确保ArticleEnglish数组中只包含英文句子,ArticleChinese数组中只包含中文句子
654
+    if (json.ArticleEnglish && Array.isArray(json.ArticleEnglish)) {
655
+        const englishSentences = [];
656
+        const chineseSentences = [];
657
+        
658
+        // 遍历ArticleEnglish数组,分离英文和中文句子
659
+        json.ArticleEnglish.forEach(sentence => {
660
+            // 检查句子是否包含中文字符
661
+            if (/[\u4e00-\u9fa5]/.test(sentence)) {
662
+                chineseSentences.push(sentence);
663
+            } else {
664
+                englishSentences.push(sentence);
665
+            }
666
+        });
667
+        
668
+        // 更新ArticleEnglish数组,只保留英文句子
669
+        json.ArticleEnglish = englishSentences;
670
+        
671
+        // 如果ArticleChinese不存在或不是数组,则创建它
672
+        if (!json.ArticleChinese || !Array.isArray(json.ArticleChinese)) {
673
+            json.ArticleChinese = [];
674
+        }
675
+        
676
+        // 将中文句子添加到ArticleChinese数组中
677
+        chineseSentences.forEach(sentence => {
678
+            if (!json.ArticleChinese.includes(sentence)) {
679
+                json.ArticleChinese.push(sentence);
680
+            }
681
+        });
682
+    }
683
+    
684
+    // 根据输入类型返回相应的结果
685
+    return isString ? JSON.stringify(json) : json;
647 686
 }
648 687
 
649 688
 // 默认导出,保持向后兼容性

+ 32 - 0
src/api/yjbdc/yjbdcController.js

@@ -265,6 +265,38 @@ export async function GenerateArticle(ctx) {
265 265
                 const jsonObj = JSON.parse(result2);
266 266
                 // 增强FormsOfWords,检测文章中单词的变形形式和拼写错误
267 267
                 const enhancedJsonObj = aiController.enhanceFormsOfWords(jsonObj, words);
268
+                
269
+                // 再次确保中文句子被正确分类
270
+                if (enhancedJsonObj.ArticleEnglish && Array.isArray(enhancedJsonObj.ArticleEnglish)) {
271
+                    const englishSentences = [];
272
+                    const chineseSentences = [];
273
+                    
274
+                    // 遍历ArticleEnglish数组,分离英文和中文句子
275
+                    enhancedJsonObj.ArticleEnglish.forEach(sentence => {
276
+                        // 检查句子是否包含中文字符
277
+                        if (/[\u4e00-\u9fa5]/.test(sentence)) {
278
+                            chineseSentences.push(sentence);
279
+                        } else {
280
+                            englishSentences.push(sentence);
281
+                        }
282
+                    });
283
+                    
284
+                    // 更新ArticleEnglish数组,只保留英文句子
285
+                    enhancedJsonObj.ArticleEnglish = englishSentences;
286
+                    
287
+                    // 如果ArticleChinese不存在或不是数组,则创建它
288
+                    if (!enhancedJsonObj.ArticleChinese || !Array.isArray(enhancedJsonObj.ArticleChinese)) {
289
+                        enhancedJsonObj.ArticleChinese = [];
290
+                    }
291
+                    
292
+                    // 将中文句子添加到ArticleChinese数组中
293
+                    chineseSentences.forEach(sentence => {
294
+                        if (!enhancedJsonObj.ArticleChinese.includes(sentence)) {
295
+                            enhancedJsonObj.ArticleChinese.push(sentence);
296
+                        }
297
+                    });
298
+                }
299
+                
268 300
                 // 将增强后的对象转回JSON字符串
269 301
                 result2 = JSON.stringify(enhancedJsonObj);
270 302
                 //console.log("FormsOfWords已增强,添加了单词变形和拼写错误检测");