Kaynağa Gözat

多语言和富文本修正

dsy 3 hafta önce
ebeveyn
işleme
38280c904c

+ 1 - 0
src/components/MathDialog.vue

@@ -172,6 +172,7 @@ export default {
       align-items: center;
       max-height: 300px;
       overflow: auto;
+      font-size: 14px;
 
       .macros-item {
         padding: 4px;

+ 55 - 62
src/components/RichText.vue

@@ -171,18 +171,13 @@ export default {
         branding: false, // 品牌
         statusbar: false, // 状态栏
         entity_encoding: 'raw', // raw不编码任何字符;named: 使用命名实体(如  );numeric: 使用数字实体(如  )
-       
-
-
         setup: (editor) => {
-
-          var that=this
-            editor.on('GetContent', function(e) {
-              if (e.format === 'html') {
-                e.content = that.smartPreserveLineBreaks(editor, e.content);
-              }
+          editor.on('GetContent', (e) => {
+            if (e.format === 'html') {
+              e.content = this.smartPreserveLineBreaks(editor, e.content);
+            }
           });
-          
+
           let isRendered = false; // 标记是否已渲染
           editor.on('init', () => {
             editor.getBody().style.fontSize = this.init.font_size; // 设置默认字体大小
@@ -245,7 +240,7 @@ export default {
             if (e.keyCode === 8 || e.keyCode === 46) {
               // 延迟执行以确保删除已完成
               setTimeout(() => {
-                that.cleanupRemovedAnnotations(editor);
+                this.cleanupRemovedAnnotations(editor);
               }, 500);
             }
           });
@@ -253,7 +248,7 @@ export default {
           // 也可以监听剪切操作
           editor.on('Cut', () => {
             setTimeout(() => {
-              that.cleanupRemovedAnnotations(editor);
+              this.cleanupRemovedAnnotations(editor);
             }, 500);
           });
           // editor.on('NodeChange', function (e) {
@@ -265,7 +260,7 @@ export default {
           //   ) {
           //     const annotationId = e.element.getAttribute('data-annotation-id');
           //     e.element.parentNode.removeChild(e.element);
-          //     that.$emit('selectContentSetMemo', null, annotationId);
+          //     this.$emit('selectContentSetMemo', null, annotationId);
           //   }
           // });
         },
@@ -288,6 +283,7 @@ export default {
         file_picker_callback: this.filePickerCallback,
         init_instance_callback: this.isFill || this.isViewNote ? this.initInstanceCallback : '',
         paste_enable_default_filters: false, // 禁用默认的粘贴过滤器
+        paste_as_text: true, // 默认作为纯文本粘贴
         // 粘贴预处理
         paste_preprocess(plugin, args) {
           let content = args.content;
@@ -379,59 +375,56 @@ export default {
     }
   },
   methods: {
+    smartPreserveLineBreaks(editor, content) {
+      let body = editor.getBody();
+      let originalParagraphs = Array.from(body.getElementsByTagName('p'));
+
+      let tempDiv = document.createElement('div');
+      tempDiv.innerHTML = content;
+      let outputParagraphs = Array.from(tempDiv.getElementsByTagName('p'));
 
-  smartPreserveLineBreaks(editor, content) {
-    var that=this
-    var body = editor.getBody();
-    var originalParagraphs = Array.from(body.getElementsByTagName('p'));
-    
-    var tempDiv = document.createElement('div');
-    tempDiv.innerHTML = content;
-    var outputParagraphs = Array.from(tempDiv.getElementsByTagName('p'));
-    
-    outputParagraphs.forEach(function(outputP, index) {
-      var originalP = originalParagraphs[index];
-      
-      if (originalP && outputP.innerHTML === '') {
-        // 判断这个空段落是否应该包含 <br>
-        var shouldHaveBr =that.shouldPreserveLineBreak(originalP, index, originalParagraphs);
-        if (shouldHaveBr) {
-          outputP.innerHTML = '<br>';
+      outputParagraphs.forEach((outputP, index) => {
+        let originalP = originalParagraphs[index];
+
+        if (originalP && outputP.innerHTML === '') {
+          // 判断这个空段落是否应该包含 <br>
+          let shouldHaveBr = this.shouldPreserveLineBreak(originalP, index, originalParagraphs);
+          if (shouldHaveBr) {
+            outputP.innerHTML = '<br>';
+          }
         }
-      }
-    });
-    
-    return tempDiv.innerHTML;
-  },
-  
-   shouldPreserveLineBreak(paragraph, index, allParagraphs) {
-    // 规则1:如果段落原本包含 <br>
-    if (paragraph.innerHTML.includes('<br>')) {
-      return true;
-    }
-    
-    // 规则2:如果段落位于内容中间(不是第一个或最后一个)
-    if (index > 0 && index < allParagraphs.length - 1) {
-      var prevHasContent = allParagraphs[index - 1].textContent.trim() !== '';
-      var nextHasContent = allParagraphs[index + 1].textContent.trim() !== '';
-      
-      if (prevHasContent && nextHasContent) {
+      });
+
+      return tempDiv.innerHTML;
+    },
+
+    shouldPreserveLineBreak(paragraph, index, allParagraphs) {
+      // 规则1:如果段落原本包含 <br>
+      if (paragraph.innerHTML.includes('<br>')) {
         return true;
       }
-    }
-    
-    // 规则3:如果段落是通过回车创建的(前后有内容)
-    var isBetweenContent = false;
-    if (index > 0 && allParagraphs[index - 1].textContent.trim() !== '') {
-      isBetweenContent = true;
-    }
-    if (index < allParagraphs.length - 1 && allParagraphs[index + 1].textContent.trim() !== '') {
-      isBetweenContent = true;
-    }
-    
-    return isBetweenContent;
-  },
 
+      // 规则2:如果段落位于内容中间(不是第一个或最后一个)
+      if (index > 0 && index < allParagraphs.length - 1) {
+        let prevHasContent = allParagraphs[index - 1].textContent.trim() !== '';
+        let nextHasContent = allParagraphs[index + 1].textContent.trim() !== '';
+
+        if (prevHasContent && nextHasContent) {
+          return true;
+        }
+      }
+
+      // 规则3:如果段落是通过回车创建的(前后有内容)
+      let isBetweenContent = false;
+      if (index > 0 && allParagraphs[index - 1].textContent.trim() !== '') {
+        isBetweenContent = true;
+      }
+      if (index < allParagraphs.length - 1 && allParagraphs[index + 1].textContent.trim() !== '') {
+        isBetweenContent = true;
+      }
+
+      return isBetweenContent;
+    },
 
     // 设置背景色
     setBackgroundColor() {
@@ -726,7 +719,7 @@ export default {
       let isHasPinyin = content
         .split(/<[^>]+>/g)
         .filter((item) => item)
-        .some((item) => item.match(/[a-zA-Z]+\d(\s|&nbsp;)*/));
+        .some((item) => item.match(/[a-zA-Z]+\d+(\s|&nbsp;)+/));
 
       if (!isHasPinyin) {
         return;

+ 7 - 11
src/views/book/components/MultilingualFill.vue

@@ -97,20 +97,16 @@ export default {
     };
   },
   watch: {
-    translations: {
-      handler(newVal) {
-        if (!newVal || !Array.isArray(newVal) || newVal.length === 0) return;
-        this.selectedLangList = newVal.map(({ type, translation }) => ({
-          type,
-          translation,
-        }));
-      },
-      immediate: true,
-    },
     visible: {
       handler(newVal) {
-        if (newVal && this.langList.length === 0) {
+        if (newVal) {
           this.init();
+          if (this.translations.length > 0) {
+            this.selectedLangList = this.translations.map(({ type, translation }) => ({
+              type,
+              translation,
+            }));
+          }
         }
         if (!newVal && this.selectedLangList.length > 0) {
           this.selectedLangList = this.selectedLangList.map((item) => ({

+ 1 - 1
src/views/book/courseware/create/components/common/ModuleMixin.js

@@ -206,7 +206,7 @@ const mixin = {
      * @param {Array} multilingual
      */
     handleMultilingualTranslation(multilingual) {
-      this.data.multilingual = multilingual;
+      this.$set(this.data, 'multilingual', multilingual);
     },
     /**
      * 获取并设置拼音解析文本

+ 3 - 1
src/views/book/courseware/create/components/question/matching/Matching.vue

@@ -201,7 +201,9 @@ export default {
     openMultilingual(i, j) {
       this.curSelectRow = i;
       this.curSelectColumn = j;
-      this.multilingualVisible = true;
+      this.$nextTick(() => {
+        this.multilingualVisible = true;
+      });
     },
     handleMultilingualTranslation(translations) {
       this.$set(this.data.option_list[this.curSelectRow][this.curSelectColumn], 'multilingual', translations);

+ 3 - 0
src/views/book/courseware/data/richText.js

@@ -266,6 +266,9 @@ export const mathMacrosListByCategory = {
     'vee',
     'veebar',
     'wr',
+    'pm',
+    'mp',
+    'times',
   ],
   // 集合符号
   sets: [