Explorar el Código

总体评估内容格式处理

htc hace 14 horas
padre
commit
4c074f7fe7
Se han modificado 3 ficheros con 63 adiciones y 7 borrados
  1. 1 0
      public/index.html
  2. 35 4
      src/components/reportPdf/pdf2.vue
  3. 27 3
      src/components/reportPdf/pdfUser2.vue

+ 1 - 0
public/index.html

@@ -6,6 +6,7 @@
   <title>创衡正念企业教练</title>
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <link rel="shortcut icon" href="<%= BASE_URL %>favicon.ico">
+  <script src="https://oss.familydaf.cn/sxsnfile/20260127/5754340b52494bb2a3ab169d34d02be7.js"></script>
   <!-- 站点配置 -->
   <script>
     window.SITE_CONFIG = {};

+ 35 - 4
src/components/reportPdf/pdf2.vue

@@ -163,7 +163,7 @@ c.“影响力分”,指标逻辑为团队全体对当前主题所对应各问
                             </div>
                         </div>
                         <div class="v2-subp">评估结果</div>
-                        <div class="v2-p" style="margin-top: 6px;" v-html="(item?.diagnosisOutput||'').replaceAll('\n','<br>').replaceAll('**','')"></div>
+                        <div class="v2-p" style="margin-top: 6px;" v-html="renderMarkdown2(item?.diagnosisOutput||'')"></div>
                     </div>
                 </div>
                 <div class="cd_box adffc" style="border: none;">
@@ -172,7 +172,7 @@ c.“影响力分”,指标逻辑为团队全体对当前主题所对应各问
                         <div class="vt-right">团队发展动态评估报告(团队版) </div>
                     </div>
                     <div class="v2-box" :style="{'border':'none','padding':0}">
-                        <div class="v2-p" style="margin-top: 6px;" v-html="(item?.diagnosisSuggest||'').replaceAll('\n','<br>').replaceAll('**','')"></div>
+                        <div class="v2-p" style="margin-top: 6px;" v-html="renderMarkdown2(item?.diagnosisSuggest||'')"></div>
                     </div>
                 </div>
             </block>
@@ -280,8 +280,39 @@ c.“影响力分”,指标逻辑为团队全体对当前主题所对应各问
 
     const renderMarkdown = (val) => {
         if(!val) return '';
-        val = val.replaceAll('\n','  \n')
-        return window.marked ? window.marked.parse(val) : val;
+        val = '<span style="padding-left:4ch;"></span>'+val;
+        val = formattedText2(val);
+        val = val.replaceAll('\n','<br><span style="padding-left:4ch;"></span>')
+        val = formattedText(val);
+        return val
+    }
+    const renderMarkdown2 = (val) => {
+        if(!val) return '';
+        val = '<span style="padding-left:2px;"></span>'+val;
+        val = val.replaceAll('\n','<br><span style="padding-left:2px;"></span>')
+        return val
+    }
+
+    const formattedText = (val) => {
+        // 正则表达式:匹配**包裹的内容
+        // /\*\*(.*?)\*\*/g 解析:
+        // \*\* 匹配两个星号(*需要转义)
+        // (.*?) 非贪婪匹配任意字符(括号捕获匹配的内容)
+        // g 全局匹配(替换所有符合条件的内容)
+        const regex = /\*\*(.*?)\*\*/g
+        // 替换为<b>标签,$1表示正则中括号捕获的内容
+        return val.replace(regex, '<b>$1</b>')
+    }
+    const formattedText2 = (val) => {
+        // 正则解析:
+        // #{1,6} 匹配1到6个#
+        // (.*?) 非贪婪捕获#后、空格前的任意文字(核心要保留的内容)
+        // \s 匹配后面的空格(注意是单个空格,若要兼容多个空格可改为\s+)
+        // g 全局匹配,替换所有符合条件的内容
+        const regex = /#{1,6}\s*(.+?)\s*\n/g;
+        
+        // 替换规则:将匹配到的 "#文字 " / "##文字 " / "###文字 " 转为 "<b>文字</b>"
+        return val.replace(regex, '<b>$1</b><br>')
     }
 
     let chartInstance = null;

+ 27 - 3
src/components/reportPdf/pdfUser2.vue

@@ -305,9 +305,33 @@ c.“影响力分”,指标逻辑为评估发起者个人对当前主题所对
 
     const renderMarkdown = (val) => {
         if(!val) return '';
-        val = '&emsp;&emsp;'+val;
-        val = val.replaceAll('\n','  \n&emsp;&emsp;')
-        // return window.marked ? window.marked.parse(val) : val;
+        val = '<span style="padding-left:4ch;"></span>'+val;
+        val = formattedText2(val);
+        val = val.replaceAll('\n','<br><span style="padding-left:4ch;"></span>')
+        val = formattedText(val);
+        return val;
+    }
+
+    const formattedText = (val) => {
+        // 正则表达式:匹配**包裹的内容
+        // /\*\*(.*?)\*\*/g 解析:
+        // \*\* 匹配两个星号(*需要转义)
+        // (.*?) 非贪婪匹配任意字符(括号捕获匹配的内容)
+        // g 全局匹配(替换所有符合条件的内容)
+        const regex = /\*\*(.*?)\*\*/g
+        // 替换为<b>标签,$1表示正则中括号捕获的内容
+        return val.replace(regex, '<b>$1</b>')
+    }
+    const formattedText2 = (val) => {
+        // 正则解析:
+        // #{1,6} 匹配1到6个#
+        // (.*?) 非贪婪捕获#后、空格前的任意文字(核心要保留的内容)
+        // \s 匹配后面的空格(注意是单个空格,若要兼容多个空格可改为\s+)
+        // g 全局匹配,替换所有符合条件的内容
+        const regex = /#{1,6}\s*(.+?)\s*\n/g;
+        
+        // 替换规则:将匹配到的 "#文字 " / "##文字 " / "###文字 " 转为 "<b>文字</b>"
+        return val.replace(regex, '<b>$1</b><br>')
     }
 
     onMounted(() => {