Ver código fonte

简繁转换问题。1、不转换标签内样式。2、拼音组件内文本简繁转换

dsy 1 mês atrás
pai
commit
b8b05a90dc

+ 1 - 1
.env

@@ -11,4 +11,4 @@ VUE_APP_BookWebSI = '/GCLSBookWebSI/ServiceInterface'
 VUE_APP_EepServer = '/EEPServer/SI'
 
 #version
-VUE_APP_VERSION = '2026.01.27'
+VUE_APP_VERSION = '2026.01.31'

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "eep_page",
-  "version": "2026.01.27",
+  "version": "2026.01.31",
   "private": true,
   "main": "main.js",
   "description": "智慧梧桐数字教材编辑器",

+ 41 - 0
src/components/CommonPreview.vue

@@ -1055,11 +1055,52 @@ export default {
      */
     convertText(text) {
       if (this.chinese === 'zh-Hant' && this.opencc) {
+        try {
+          if (/<[a-z][\s\S]*>/i.test(text)) {
+            return this.convertHtmlPreserveAttributes(text);
+          }
+        } catch (e) {
+          return text;
+        }
         return this.opencc(text);
       }
       return text;
     },
 
+    /**
+     * 使用OpenCC解析HTML并仅转换文本节点,保留属性(包括内联样式/font-family)保持不变。防止字体名称像“微软雅黑' 正在转换为'微軟雅黑'.
+     */
+    convertHtmlPreserveAttributes(html) {
+      try {
+        const parser = new DOMParser();
+        const doc = parser.parseFromString(html, 'text/html');
+
+        // 跳过这些标记内的转换
+        const skipTags = new Set(['SCRIPT', 'STYLE']);
+
+        const walker = doc.createTreeWalker(doc.body, NodeFilter.SHOW_TEXT, null, false);
+        let node = walker.nextNode();
+        while (node) {
+          const parent = node.parentNode;
+          if (parent && !skipTags.has(parent.nodeName)) {
+            const v = node.nodeValue;
+            if (v && v.trim()) {
+              node.nodeValue = this.opencc(v);
+            }
+          }
+          node = walker.nextNode();
+        }
+
+        return doc.body.innerHTML;
+      } catch (err) {
+        try {
+          return this.opencc(html);
+        } catch (e) {
+          return html;
+        }
+      }
+    },
+
     simulateAnswer(disabled = true) {
       this.$refs.courserware.simulateAnswer(this.isJudgeCorrect, this.isShowAnswer, disabled);
     },

+ 2 - 1
src/components/PinyinText.vue

@@ -20,7 +20,7 @@
             <span v-if="pinyinPosition === 'top'" class="pinyin" :style="{ 'font-size': pinyinSize }">{{
               item.pinyin.replace(/\s+/g, '')
             }}</span>
-            <span class="py-char" :style="textStyle(item)">{{ item.text }}</span>
+            <span class="py-char" :style="textStyle(item)">{{ convertText(item.text) }}</span>
             <span v-if="pinyinPosition !== 'top'" class="pinyin" :style="{ 'font-size': pinyinSize }">{{
               item.pinyin.replace(/\s+/g, '')
             }}</span>
@@ -60,6 +60,7 @@ export default {
   components: {
     CorrectPinyin,
   },
+  inject: ['convertText'],
   props: {
     paragraphList: {
       type: Array,

+ 3 - 3
src/views/personal_workbench/edit_task/edit/UseTemplate.vue

@@ -82,13 +82,13 @@ export default {
       getTitleList: () => this.title_list,
     };
   },
+  inject: ['processHtmlString'],
   props: {
     visible: {
       type: Boolean,
       required: true,
     },
   },
-  inject: ['processHtmlString'],
   data() {
     return {
       loading: false,
@@ -203,7 +203,7 @@ export default {
               let lev = Number(p.title_style_level);
               if (p.is_title !== 'true' || lev < 1 || !_c.content) return;
 
-              let style = this.title_list.find((y) => y.level == lev) || {};
+              let style = this.title_list.find((y) => y.level === lev) || {};
               if (style && style.style) {
                 style = JSON.parse(style.style);
                 let c_text = _c.content;
@@ -221,7 +221,7 @@ export default {
           });
 
           if (content_group_row_list) this.content_group_row_list = JSON.parse(content_group_row_list) || [];
-        }
+        },
       );
     },
     resetStylesMulti(html, config) {

+ 4 - 4
src/views/personal_workbench/project/components/BookUnifiedTitle.vue

@@ -12,7 +12,7 @@
         <el-form ref="form" :model="formModel" label-width="50" size="small">
           <!-- 5列标题级别设置 -->
           <div class="levels-container">
-            <div class="level-column" v-for="(item, index) in titleSettings" :key="index">
+            <div v-for="(item, index) in titleSettings" :key="index" class="level-column">
               <div class="level-header">{{ item.level_title }}</div>
 
               <!-- 字体 -->
@@ -69,7 +69,7 @@
         </el-form>
       </div>
     </div>
-<div style="margin-top:5px;color:#f53f3f">说明:修改设置后,编辑界面需刷新!</div>
+    <div style="margin-top: 5px; color: #f53f3f">说明:修改设置后,编辑界面需刷新!</div>
     <div slot="footer" class="dialog-footer">
       <el-button @click="dialogClose">取 消</el-button>
       <el-button type="primary" @click="saveBookUnifiedTitle">确 定</el-button>
@@ -157,7 +157,7 @@ export default {
           isSuccess = true;
 
           for (let i = 1; i <= 5; i++) {
-            let en = title_list.find((x) => x.level == i);
+            let en = title_list.find((x) => x.level === i);
             let style = en.style ? JSON.parse(en.style) : {};
             let defStyle = this.defaultTitleSettings[i - 1];
             style = Object.assign({}, defStyle, style);
@@ -182,7 +182,7 @@ export default {
         title_list.push(tmp);
       });
 
-      let data = { book_id: this.bookId, title_list: title_list };
+      let data = { book_id: this.bookId, title_list };
 
       SaveTitleStyle(data).then(() => {
         this.$message.success('保存成功');

+ 1 - 0
src/views/personal_workbench/template_list/preview/CommonPreview.vue

@@ -117,6 +117,7 @@ export default {
         cover_image_file_id: null, // 封面图片ID
         cover_image_file_url: '', // 封面图片URL
       },
+      title_list: [],
     };
   },
   computed: {},