Forráskód Böngészése

生词、汉字、生字、汉字结构、对话文章角色拼音、注释等更换生成拼音接口

natasha 1 hete
szülő
commit
e68a4fae5e

+ 31 - 2
src/views/book/courseware/create/components/question/article/NewWord.vue

@@ -316,6 +316,7 @@ import SelectUpload from '@/views/book/courseware/create/components/common/Selec
 import UploadPicture from '../new_word/components/UploadPicture.vue';
 import { getWordTime, prepareTranscribe, fileToBase64Text, getWordTimes } from '@/api/article';
 import { GetStaticResources, TextToAudioFile, GetTextToAudioConfParamList } from '@/api/app';
+import { PinyinBuild_OldFormat } from '@/api/book';
 import RichText from '@/components/RichText.vue';
 import CheckSubtitles from '@/views/book/courseware/create/components/question/voice_matrix/CheckSubtitles.vue';
 import {
@@ -556,7 +557,7 @@ export default {
       }
     },
     // 获取数据
-    handleBlurCon(row) {
+    async handleBlurCon(row) {
       let cons = row.new_word.trim();
       let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
       let data = {
@@ -587,7 +588,35 @@ export default {
           this.loading = false;
         });
 
-      row.pinyin = cnchar.spell(cons, 'array', 'low', 'tone').join(' ');
+      // row.pinyin = cnchar.spell(cons, 'array', 'low', 'tone').join(' ');
+      if (cons) {
+        row.pinyin = await this.handlePinyin(cons);
+      }
+    },
+    // 自动生成拼音
+    handlePinyin(text) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
+      });
     },
     createWordTimes() {
       if (this.data.audio_data.file_id) {

+ 37 - 4
src/views/book/courseware/create/components/question/character/Character.vue

@@ -136,6 +136,7 @@ import ModuleMixin from '../../common/ModuleMixin';
 
 import { getCharacterData, modelList, getOption } from '@/views/book/courseware/data/character';
 import { GetStaticResources, TextToAudioFile } from '@/api/app';
+import { PinyinBuild_OldFormat } from '@/api/book';
 import cnchar from 'cnchar';
 import UploadFile from '../../base/common/UploadFile.vue';
 import SoundRecord from '@/views/book/courseware/create/components/question/fill/components/SoundRecord.vue';
@@ -259,7 +260,10 @@ export default {
         let data = {
           hz_str: str,
         };
-        items.pinyin = cnchar.spell(str, 'array', 'low', 'tone').join(' ');
+        // items.pinyin = cnchar.spell(str, 'array', 'low', 'tone').join(' ');
+        if (str) {
+          items.pinyin = await this.handlePinyin(str);
+        }
         await GetStaticResources(MethodName, data)
           .then((res) => {
             for (let key in res) {
@@ -268,6 +272,7 @@ export default {
               }
             }
             let hzDetailList = res;
+
             arr.forEach((item, index) => {
               let objs = {};
               if (item === '@') {
@@ -324,13 +329,41 @@ export default {
             });
           })
           .catch(() => {});
-        // if (str) {
-        //   this.handleMatic(str, index);
-        // }
+        for (let index = 0; index < arr.length; index++) {
+          if (regex.test(arr[index])) {
+            // 汉字
+            items.content_list[index].pinyin = await this.handlePinyin(arr[index]);
+          }
+        }
       } else {
         this.$message.warning('请先输入内容');
       }
     },
+    // 自动生成拼音
+    handlePinyin(text) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
+      });
+    },
     uploads(file_id, index, file_url) {
       this.data.option_list[index].audio_file_id = {
         file_url,

+ 32 - 2
src/views/book/courseware/create/components/question/character_structure/CharacterStructure.vue

@@ -88,6 +88,7 @@ import {
   isEnable,
 } from '@/views/book/courseware/data/characterStructure';
 import { GetStaticResources } from '@/api/app';
+import { PinyinBuild_OldFormat } from '@/api/book';
 import cnchar from 'cnchar';
 
 export default {
@@ -150,7 +151,7 @@ export default {
       });
       this.data.mind_map.node_list = node_list;
     },
-    handleHanzi(item) {
+    async handleHanzi(item) {
       let cons = item.content.trim();
       let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
       let data = {
@@ -179,9 +180,38 @@ export default {
         })
         .catch(() => {});
 
-      item.pinyin = cnchar.spell(cons, 'array', 'low', 'tone').join(' ');
+      // item.pinyin = cnchar.spell(cons, 'array', 'low', 'tone').join(' ');
+      if (cons) {
+        item.pinyin = await this.handlePinyin(cons);
+      }
+
       this.handleMindMap();
     },
+    // 自动生成拼音
+    handlePinyin(text) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
+      });
+    },
     handleData() {
       let file_id_list = [];
       this.data.structure_img_list.forEach((item) => {

+ 29 - 2
src/views/book/courseware/create/components/question/dialogue_article/ArticleSetting.vue

@@ -175,6 +175,7 @@ import {
   pinyinPositionList,
 } from '@/views/book/courseware/data/dialogueArticle';
 import { GetTextToAudioConfParamList } from '@/api/app';
+import { PinyinBuild_OldFormat } from '@/api/book';
 import cnchar from 'cnchar';
 
 export default {
@@ -218,12 +219,38 @@ export default {
       item[field] = item[field] ? item[field].trim() : '';
     },
     // 生成拼音
-    segWord(item) {
+    async segWord(item) {
       if (!item.fullName) {
         this.$message.warning('姓名不能为空');
         return;
       }
-      this.$set(item, 'fullPinyin', cnchar.spell(item.fullName, 'low', 'tone'));
+      let pinyin = await this.handlePinyin(item.fullName);
+      this.$set(item, 'fullPinyin', pinyin);
+    },
+    // 自动生成拼音
+    handlePinyin(text) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
+      });
     },
     // 角色名分词
     partWord(item) {

+ 36 - 1
src/views/book/courseware/create/components/question/newWord_template/NewWordTemplate.vue

@@ -172,6 +172,7 @@ import {
   isEnable,
 } from '@/views/book/courseware/data/newWordTemplate';
 import { GetStaticResources } from '@/api/app';
+import { PinyinBuild_OldFormat } from '@/api/book';
 
 export default {
   name: 'NewWordTemplatePage',
@@ -227,7 +228,10 @@ export default {
             str += item;
           }
         });
-        items.pinyin = cnchar.spell(str, 'array', 'low', 'tone').join(' ');
+        // items.pinyin = cnchar.spell(str, 'array', 'low', 'tone').join(' ');
+        if (str) {
+          items.pinyin = await this.handlePinyin(str);
+        }
         let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
         let data = {
           hz_str: str,
@@ -319,10 +323,41 @@ export default {
             });
           })
           .catch(() => {});
+        for (let index = 0; index < arr.length; index++) {
+          if (regex.test(arr[index])) {
+            // 汉字
+            items.content_list[index].pinyin = await this.handlePinyin(arr[index]);
+          }
+        }
       } else {
         this.$message.warning('请先输入内容');
       }
     },
+    // 自动生成拼音
+    handlePinyin(text) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
+      });
+    },
   },
 };
 </script>

+ 33 - 3
src/views/book/courseware/create/components/question/new_word/NewWord.vue

@@ -421,7 +421,7 @@ import { getNewWordData, getOption } from '@/views/book/courseware/data/newWord'
 import SelectUpload from '@/views/book/courseware/create/components/common/SelectUpload.vue';
 import { GetStaticResources, TextToAudioFile } from '@/api/app';
 import cnchar from 'cnchar';
-import { ChapterGetBookChapterStruct } from '@/api/book';
+import { ChapterGetBookChapterStruct, PinyinBuild_OldFormat } from '@/api/book';
 import { getWordTime, prepareTranscribe, fileToBase64Text, getWordTimes } from '@/api/article';
 import { addTone, handleToneValue } from '@/views/book/courseware/data/common';
 export default {
@@ -632,7 +632,7 @@ export default {
       }
     },
     // 获取数据
-    handleBlurCon(row) {
+    async handleBlurCon(row) {
       let cons = row.new_word.trim();
       let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
       let data = {
@@ -663,9 +663,39 @@ export default {
           this.loading = false;
         });
 
-      row.pinyin = cnchar.spell(cons, 'array', 'low', 'tone').join(' ');
+      // row.pinyin = cnchar.spell(cons, 'array', 'low', 'tone').join(' ');
+      if (cons) {
+        row.pinyin = await this.handlePinyin(cons);
+      }
+
       this.handleMindMap();
     },
+    // 自动生成拼音
+    handlePinyin(text) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
+      });
+    },
+
     handleMindMap() {
       // 思维导图数据
       let node_list = [];

+ 58 - 17
src/views/book/courseware/create/components/question/notes/Notes.vue

@@ -169,30 +169,71 @@ export default {
       });
       this.data.mind_map.node_list = node_list;
     },
-    handleBlurCon(i) {
+    async handleBlurCon(i) {
       let text = this.data.option[i].con.replace(/<[^>]+>/g, '');
-      this.data.option[i].pinyin = cnchar
-        .spell(
+      if (text) {
+        this.data.option[i].pinyin = await this.handlePinyins(
           text,
-          'array',
-          this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case === 'true' ? 'high' : 'low',
-          'tone',
-        )
-        .join(' ');
+          this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case,
+        );
+      }
+      // this.data.option[i].pinyin = cnchar
+      //   .spell(
+      //     text,
+      //     'array',
+      //     this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case === 'true' ? 'high' : 'low',
+      //     'tone',
+      //   )
+      //   .join(' ');
 
       this.handleMindMap();
     },
-    handlePinyin() {
-      this.data.option.forEach((item) => {
+    async handlePinyin() {
+      for (const item of this.data.option) {
         let text = item.con.replace(/<[^>]+>/g, '');
-        item.pinyin = cnchar
-          .spell(
+        if (text) {
+          item.pinyin = await this.handlePinyins(
             text,
-            'array',
-            this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case === 'true' ? 'high' : 'low',
-            'tone',
-          )
-          .join(' ');
+            this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case,
+          );
+        }
+      }
+      // this.data.option.forEach((item) => {
+      //   let text = item.con.replace(/<[^>]+>/g, '');
+
+      // item.pinyin = cnchar
+      //   .spell(
+      //     text,
+      //     'array',
+      //     this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case === 'true' ? 'high' : 'low',
+      //     'tone',
+      //   )
+      //   .join(' ');
+      // });
+    },
+    // 自动生成拼音
+    handlePinyins(text, flag) {
+      let data = {
+        text: text,
+        is_rich_text: 'false',
+        is_first_sentence_first_hz_pinyin_first_char_upper_case: flag ? flag : 'false',
+        is_fill_space: 'false',
+        is_custom_fc: 'false',
+      };
+      return new Promise((resolve, reject) => {
+        PinyinBuild_OldFormat(data).then((res) => {
+          if (res.parsed_text) {
+            let mergedData = '';
+            res.parsed_text.paragraph_list.map((outerArr, i) =>
+              outerArr.map((innerArr, j) =>
+                innerArr.map((newItem, k) => {
+                  mergedData += newItem.pinyin + ' ';
+                }),
+              ),
+            );
+            resolve(mergedData);
+          }
+        });
       });
     },
     handleMultilingual() {