From 50955551f7aebd3f664d3840ded3d1cb4aed3beb Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 07 二月 2025 17:54:52 +0800
Subject: [PATCH] 2025-02-07

---
 src/tabviews/custom/components/editor/braft-editor/index.jsx |   64 ++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/tabviews/custom/components/editor/braft-editor/index.jsx b/src/tabviews/custom/components/editor/braft-editor/index.jsx
index 2c5ddd6..5729372 100644
--- a/src/tabviews/custom/components/editor/braft-editor/index.jsx
+++ b/src/tabviews/custom/components/editor/braft-editor/index.jsx
@@ -63,6 +63,17 @@
       } else {
         _data = [_data]
       }
+    } else if (config.html) {
+      if (/blank_space_\d+/ig.test(config.html)) {
+        config.html = config.html.replace(/blank_space_\d+/ig, (w) => {
+          let n = +w.replace(/blank_space_/ig, '')
+          if (n) {
+            return new Array(n).fill('&nbsp;').join('')
+          }
+
+          return w
+        })
+      }
     }
 
     if (_config.wrap.minHeight) {
@@ -73,7 +84,7 @@
     }
 
     this.setState({
-      data: _data,
+      data: this.decodeHtml(_data, _config.wrap),
       BID: BID || '',
       config: _config,
     })
@@ -130,7 +141,7 @@
 
     let _data = window.GLOB.SyncData.get(config.dataName) || []
 
-    this.setState({data: _data})
+    this.setState({data: this.decodeHtml(_data, config.wrap)})
 
     window.GLOB.SyncData.delete(config.dataName)
 
@@ -158,7 +169,7 @@
         _data = [_data]
       }
 
-      this.setState({data: _data})
+      this.setState({data: this.decodeHtml(_data, config.wrap)})
     }
   }
 
@@ -224,7 +235,7 @@
     let result = await Api.genericInterface(param)
     if (result.status) {
       this.setState({
-        data: result.data || [],
+        data: this.decodeHtml(result.data, config.wrap),
         loading: false
       })
       
@@ -236,6 +247,46 @@
       
       UtilsDM.queryFail(result)
     }
+  }
+
+  decodeHtml = (data, wrap) => {
+    if (!data || data.length === 0) return []
+
+    data.forEach(item => {
+      item.$html = item[wrap.field] || ''
+      if (item.$html) {
+        if (wrap.encryption === 'true') {
+          try {
+            item.$html = window.decodeURIComponent(window.atob(item.$html))
+          } catch (e) {
+            item.$html = item[wrap.field] || ''
+          }
+        }
+
+        delete item[wrap.field]
+
+        if (/\$[\s\S]+\$/.test(item.$html)) {
+          Object.keys(item).forEach(key => {
+            if (/^\$/.test(key)) return
+            let reg = new RegExp('\\$' + key + '\\$', 'ig')
+            item.$html = item.$html.replace(reg, item[key])
+          })
+        }
+
+        if (/blank_space_\d+/ig.test(item.$html)) {
+          item.$html = item.$html.replace(/blank_space_\d+/ig, (w) => {
+            let n = +w.replace(/blank_space_/ig, '')
+            if (n) {
+              return new Array(n).fill('&nbsp;').join('')
+            }
+
+            return w
+          })
+        }
+      }
+    })
+
+    return data
   }
 
   render() {
@@ -254,11 +305,10 @@
         <NormalHeader config={config}/>
         {config.wrap.datatype === 'static' ? <BraftContent
           value={config.html}
-          encryption={'false'}
         /> : data.map((item, index) => <BraftContent
           key={index}
-          value={item[config.wrap.field] || ''}
-          encryption={config.wrap.encryption}
+          value={item.$html}
+          script={config.wrap.loaded === 'true' ? config.wrap.loadedfunc : ''}
         />)}
       </div>
     )

--
Gitblit v1.8.0