Browse Source

修正富文本拼音效果初始化样式未带入问题

zq 2 months ago
parent
commit
e611448e5a

+ 23 - 2
src/views/book/courseware/create/components/base/rich_text/RichText.vue

@@ -584,8 +584,29 @@ export default {
       });
     },
     getBodyStyles() {
-      if (!this.$refs.richText) return {};
-      return this.$refs.richText.getBodyInitialStyles();
+      // 优先从富文本编辑器获取实际渲染的样式
+      if (this.$refs.richText && typeof this.$refs.richText.getBodyInitialStyles === 'function') {
+        const editorStyles = this.$refs.richText.getBodyInitialStyles();
+        if (editorStyles && Object.keys(editorStyles).length > 0) {
+          return editorStyles;
+        }
+      }
+
+      // 如果编辑器未初始化或没有返回样式,则使用教材统一属性
+      const styles = {};
+      const unifiedAttrib = this.data?.unified_attrib || {};
+
+      if (unifiedAttrib.font) {
+        styles['font-family'] = unifiedAttrib.font;
+      }
+      if (unifiedAttrib.font_size) {
+        styles['font-size'] = unifiedAttrib.font_size;
+      }
+      if (unifiedAttrib.text_color) {
+        styles['color'] = unifiedAttrib.text_color;
+      }
+
+      return styles;
     },
   },
 };