소스 검색

富文本拼音校对可以加横杠,拼音字体更新

zq 1 개월 전
부모
커밋
0676081f22
2개의 변경된 파일64개의 추가작업 그리고 11개의 파일을 삭제
  1. BIN
      public/static/font/pinyin.ttf
  2. 64 11
      src/views/book/courseware/create/components/base/common/CorrectPinyin.vue

BIN
public/static/font/pinyin.ttf


+ 64 - 11
src/views/book/courseware/create/components/base/common/CorrectPinyin.vue

@@ -189,21 +189,74 @@ export default {
     // 将数字拼音转换为声调拼音
     convertTonePinyin() {
       if (!this.numberPinyin) return;
-      let newPinyin = this.numberPinyin
-        .trim()
-        .split(/\s+/)
-        .map((item) => {
-          return handleToneValue(item);
-        })
-        .map((item) =>
-          item.map(({ number, con }) => (number && con ? addTone(Number(number), con) : number || con || '')),
-        )
-        .filter((item) => item.length > 0)
-        .join(' ');
+      let newPinyin = this.handleReplaceTone(this.numberPinyin.replace(/\s+| +/g, ''));
       const leading = (this.dataContent.pinyin.match(/^[ ]+/) || [''])[0];
       const trailing = (this.dataContent.pinyin.match(/[ ]+$/) || [''])[0];
       this.dataContent.pinyin = leading + newPinyin + trailing;
     },
+    handleReplaceTone(e) {
+      let _this = this;
+      let value = e;
+      _this.resArr = [];
+      if (value) {
+        let valueArr = [];
+        value.replace(/\s+/g, ' ');
+        valueArr = value.split(' ');
+        //   let reg = /\s+/g;
+        //   valueArr = value.split(reg);
+
+        valueArr.forEach((item, index) => {
+          this.handleValue(item);
+        });
+        let str = '';
+        _this.resArr.forEach((item) => {
+          str += ' ';
+          item.forEach((sItem) => {
+            if (sItem.number && sItem.con) {
+              let number = Number(sItem.number);
+              let con = sItem.con;
+              let word = addTone(number, con);
+              str += word;
+            } else if (sItem.number) {
+              str += sItem.number;
+            } else if (sItem.con) {
+              str += ` ${sItem.con} `;
+            }
+          });
+        });
+        return str.trim();
+      }
+    },
+    handleValue(valItem) {
+      let reg = /\d/;
+      let reg2 = /[A-Za-z]+\d/g;
+      let numList = [];
+      let valArr = valItem.split('');
+      if (reg2.test(valItem)) {
+        for (let i = 0; i < valArr.length; i++) {
+          let item = valItem[i];
+          if (reg.test(item)) {
+            let numIndex = numList.length === 0 ? 0 : numList[numList.length - 1].index;
+            let con = valItem.substring(numIndex, i);
+            con = con.replace(/\d/g, '');
+            let obj = {
+              index: i,
+              number: item,
+              con,
+              isTran: true,
+            };
+            numList.push(obj);
+          }
+        }
+      } else {
+        numList = [];
+      }
+      if (numList.length === 0) {
+        this.resArr.push([{ con: valItem }]);
+      } else {
+        this.resArr.push(numList);
+      }
+    },
     dialogClose() {
       this.$emit('update:visible', false);
       this.numberPinyin = '';