소스 검색

优化富文本拼音字号大小

zq 1 개월 전
부모
커밋
143b97d5f9
1개의 변경된 파일10개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 3
      src/components/PinyinText.vue

+ 10 - 3
src/components/PinyinText.vue

@@ -849,9 +849,16 @@ export default {
         this.isAllSetting = false;
       }
 
-      let _fontSize = styles['font-size'] ? styles['font-size'] : null;
-      if (!_fontSize) _fontSize = block.styleObj && block.styleObj.fontSize ? block.styleObj.fontSize : null;
+      // 优先取文字单独的字号
+      let _fontSize = block.styleObj && block.styleObj.fontSize ? block.styleObj.fontSize : null;
+      // 如果没有,取继承的字号
+      if (!_fontSize && item.activeTextStyle && item.activeTextStyle.fontSize) {
+        _fontSize = item.activeTextStyle.fontSize;
+      }
+      // 如果没有,取组件的字号
       if (!_fontSize && this.bodyStyles.fontSize) _fontSize = this.bodyStyles.fontSize;
+      // 如果没有,取全局字号
+      if (!_fontSize && this.fontSize) _fontSize = this.fontSize;
 
       if (_fontSize) {
         // 取出字号里面的数字,做计算处理之后,自动加上原来的单位
@@ -860,7 +867,7 @@ export default {
           const fontSizeValue = parseFloat(fontSizeMatch[1]);
           const fontSizeUnit = fontSizeMatch[2] || 'px';
 
-          // 根据字号大小确定比例:16号及以下75%,16号以上60%
+          // 根据字号大小确定比例:16号及以下75%,16号以上60%
           const ratio = fontSizeValue <= 16 ? 0.75 : 0.6;
           const calculatedSize = Math.round(fontSizeValue * ratio);