Quellcode durchsuchen

富文本批量应用或取消,表格下划线批量取消

dsy vor 1 Tag
Ursprung
Commit
0e3a3d4cc9

+ 16 - 2
src/components/RichText.vue

@@ -948,7 +948,8 @@ export default {
     /**
      * 设置整体富文本格式
      * @param {string} type 格式名称
-     * @param {string} val 格式值
+     * @param {string|boolean} val 格式值;对于开关型格式(bold/italic/underline/strikethrough 等),
+     *   传 true 表示应用、false 表示取消,其余情况沿用 toggle 切换
      * @param {boolean} [isSetDefault=false] 是否设置为默认格式
      */
     setRichFormat(type, val, isSetDefault = false) {
@@ -1012,7 +1013,20 @@ export default {
         }
 
         default: {
-          editor.formatter.toggle(type);
+          // val 为布尔值时表示明确「应用 / 取消」该格式(批量设置场景,如取消下划线)
+          // 其余情况(未传 val 或传字符串)保持原有的 toggle 行为
+          if (typeof val === 'boolean') {
+            console.log(val);
+
+            if (val) {
+              editor.formatter.apply(type);
+            } else {
+              editor.formatter.remove(type);
+            }
+          } else {
+            editor.formatter.toggle(type);
+          }
+          break;
         }
       }
     },

+ 1 - 1
src/views/book/courseware/create/components/question/table/Table.vue

@@ -48,7 +48,7 @@
             :class="[data.styles.isUnderline ? 'active' : '']"
             @click="
               data.styles.isUnderline = !data.styles.isUnderline;
-              BatchSetFormat('underline');
+              BatchSetFormat('underline', data.styles.isUnderline);
             "
           >
             <SvgIcon icon-class="underline" size="20" />