Browse Source

解决富文本出现连续空格时会被编码的问题

zq 1 week ago
parent
commit
00317d7393
2 changed files with 12 additions and 3 deletions
  1. 11 3
      src/components/PinyinText.vue
  2. 1 0
      src/components/RichText.vue

+ 11 - 3
src/components/PinyinText.vue

@@ -17,7 +17,7 @@
             }"
             }"
             @click="correctPinyin(item, i, j, k)"
             @click="correctPinyin(item, i, j, k)"
           >
           >
-            <ruby class="py-char" :style="{ 'ruby-position': pinyinPosition === 'top' ? 'over' : 'under' }">
+            <!-- <ruby class="py-char" :style="{ 'ruby-position': pinyinPosition === 'top' ? 'over' : 'under' }">
               {{ item.text }}
               {{ item.text }}
               <rt
               <rt
                 class="pinyin"
                 class="pinyin"
@@ -25,7 +25,10 @@
               >
               >
                 {{ item.pinyin }}
                 {{ item.pinyin }}
               </rt>
               </rt>
-            </ruby>
+            </ruby> -->
+            <span v-if="pinyinPosition === 'top'" class="pinyin">{{ item.pinyin.replace(/\s+/g, '') }}</span>
+            <span class="py-char">{{ item.text }}</span>
+            <span v-if="pinyinPosition !== 'top'" class="pinyin">{{ item.pinyin.replace(/\s+/g, '') }}</span>
           </span>
           </span>
         </div>
         </div>
       </div>
       </div>
@@ -106,15 +109,20 @@ export default {
       .pinyin-text {
       .pinyin-text {
         font-size: 16px;
         font-size: 16px;
 
 
+        > span {
+          display: flex;
+          flex-direction: column;
+        }
+
         .py-char {
         .py-char {
           ruby-align: center;
           ruby-align: center;
         }
         }
 
 
         .pinyin {
         .pinyin {
-          margin-bottom: 4px;
           font-family: 'League';
           font-family: 'League';
           font-size: 12px;
           font-size: 12px;
           font-weight: lighter;
           font-weight: lighter;
+          line-height: 12px;
           color: $font-color;
           color: $font-color;
         }
         }
       }
       }

+ 1 - 0
src/components/RichText.vue

@@ -158,6 +158,7 @@ export default {
         menubar: false, // 菜单栏
         menubar: false, // 菜单栏
         branding: false, // 品牌
         branding: false, // 品牌
         statusbar: false, // 状态栏
         statusbar: false, // 状态栏
+        entity_encoding: 'raw', // raw不编码任何字符;named: 使用命名实体(如 &nbsp;);numeric: 使用数字实体(如 &#160;)
         setup: (editor) => {
         setup: (editor) => {
           let isRendered = false; // 标记是否已渲染
           let isRendered = false; // 标记是否已渲染
           let that = this;
           let that = this;