Просмотр исходного кода

开启拼音之后,拼音样式要跟随标题样式

zq 1 месяц назад
Родитель
Сommit
89f298e1ea

+ 24 - 8
src/components/RichText.vue

@@ -615,6 +615,7 @@ export default {
           }
           editor.fire('change');
           editor.nodeChanged();
+          this.setPinYinStyleForTitle();
         }
       }
     },
@@ -785,6 +786,15 @@ export default {
       }
       editor.fire('change');
       editor.nodeChanged();
+      this.setPinYinStyleForTitle();
+    },
+    //标题类型的富文本,如果开启了拼音,需要同步拼音样式
+    setPinYinStyleForTitle() {
+      if (this.isViewPinyin) {
+        let styles = this.getFirstCharStyles();
+        this.$emit('createParsedTextStyleForTitle', styles);
+        return;
+      }
     },
 
     /**
@@ -967,17 +977,20 @@ export default {
     replaceSpanString(str) {
       return str.replace(/<span\b[^>]*>(.*?)<\/span>/gi, '$1');
     },
-    createParsedTextInfoPinyin(content) {
-      let styles = this.getFirstCharStyles();
-      let text = content.replace(/<[^>]+>/g, '');
-      this.$emit('createParsedTextInfoPinyin', text, styles);
-    },
+    // createParsedTextInfoPinyin(content) {
+    //   let styles = this.getFirstCharStyles();
+    //   let text = content.replace(/<[^>]+>/g, '');
+    //   this.$emit('createParsedTextInfoPinyin', text, styles);
+    // },
     handleRichTextBlur() {
       this.$emit('handleRichTextBlur', this.itemIndex);
       let content = tinymce.get(this.id).getContent();
 
       if (this.isViewPinyin) {
-        this.createParsedTextInfoPinyin(content);
+        // this.createParsedTextInfoPinyin(content);
+        let styles = this.getFirstCharStyles();
+        let text = content.replace(/<[^>]+>/g, '');
+        this.$emit('createParsedTextInfoPinyin', text, styles);
         return;
       }
 
@@ -1203,9 +1216,12 @@ export default {
           styles.color = computed.color;
         }
 
-        if (!styles.bold && (computed.fontWeight === 'bold' || computed.fontWeight === '700')) {
+        if (!styles.bold && (computed.fontWeight === 'bold' || computed.fontWeight >= '700')) {
           styles.bold = true;
           styles.fontWeight = 'bold';
+        } else {
+          styles.bold = false;
+          styles.fontWeight = '';
         }
 
         if (!styles.underline && computed.textDecoration.includes('underline')) {
@@ -1232,7 +1248,7 @@ export default {
         {
           acceptNode: (node) => (node.textContent.trim() ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT),
         },
-        false,
+        false
       );
       return walker.nextNode();
     },

+ 2 - 0
src/layouts/default/index.vue

@@ -21,7 +21,9 @@ export default {
   provide() {
     return {
       processHtmlString: (pElements, styleConfig, isClear) => {
+        pElements = pElements || [];
         pElements.forEach((pElement) => {
+          pElement.innerHTML = pElement.innerText;
           if (isClear) {
             pElement.removeAttribute('style');
           } else {

+ 13 - 0
src/views/book/courseware/create/components/base/rich_text/RichText.vue

@@ -14,6 +14,7 @@
           @view-explanatory-note="viewExplanatoryNote"
           @selectContentSetMemo="selectContentSetMemo"
           @createParsedTextInfoPinyin="createParsedTextInfoPinyin"
+          @createParsedTextStyleForTitle="createParsedTextStyleForTitle"
           @compareAnnotationAndSave="compareAnnotationAndSave"
         />
         <el-button class="btn" @click="openMultilingual">多语言</el-button>
@@ -224,6 +225,18 @@ export default {
         }
       });
     },
+    //开启拼音之后,拼音样式要跟随标题样式
+    createParsedTextStyleForTitle(styles) {
+      if (!styles) return;
+      this.data.paragraph_list.forEach((outerArr, i) =>
+        outerArr.forEach((innerArr, j) =>
+          innerArr.forEach((newItem, k) => {
+            if (!newItem.activeTextStyle) newItem.activeTextStyle = {};
+            Object.assign(newItem.activeTextStyle, styles);
+          })
+        )
+      );
+    },
     parseFClist() {
       this.wordData = { detail: [] };
       this.data.paragraph_list.forEach((item, index) => {