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 |  151 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 98 insertions(+), 53 deletions(-)

diff --git a/src/tabviews/custom/components/editor/braft-editor/index.jsx b/src/tabviews/custom/components/editor/braft-editor/index.jsx
index 163424a..5729372 100644
--- a/src/tabviews/custom/components/editor/braft-editor/index.jsx
+++ b/src/tabviews/custom/components/editor/braft-editor/index.jsx
@@ -1,7 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Spin, notification, Modal } from 'antd'
+import { Spin } from 'antd'
 
 import asyncComponent from '@/utils/asyncComponent'
 import Api from '@/api'
@@ -21,14 +21,14 @@
     BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
-    data: {}                   // 鏁版嵁
+    data: []                   // 鏁版嵁
   }
 
   UNSAFE_componentWillMount () {
     const { config } = this.props
 
     let _config = fromJS(config).toJS()
-    let _data = { $$empty: true }
+    let _data = []
 
     let BID = ''
     let BData = ''
@@ -43,24 +43,48 @@
     }
     
     if (_config.wrap.datatype === 'dynamic') {
-      _config.setting.onload = _config.setting.sync === 'true' ? 'false' : 'true'
+      _config.setting.onload = _config.setting.sync === 'true' ? 'false' : _config.setting.onload || 'true'
 
+      if (_config.setting.supModule && !BID) {
+        _config.setting.onload = 'false'
+      }
+      
       if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
         _data = window.GLOB.SyncData.get(_config.dataName) || []
-        _data = _data[0] || {$$empty: true}
-
         _config.setting.sync = 'false'
   
         window.GLOB.SyncData.delete(_config.dataName)
+      }
+    } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.has(_config.wrap.publicId)) {
+      _data = window.GLOB.CacheData.get(_config.wrap.publicId)
+      _data = fromJS(_data).toJS()
+      if (_data.$$empty) {
+        _data = []
+      } 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) {
       _config.style.minHeight = _config.wrap.minHeight
     }
+    if (_config.wrap.firstTr === 'light') {
+      _config.wrap.tbStyle = 'th-light'
+    }
 
     this.setState({
-      data: _data,
+      data: this.decodeHtml(_data, _config.wrap),
       BID: BID || '',
       config: _config,
     })
@@ -72,16 +96,14 @@
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
 
-    if (config.setting.useMSearch) {
-      MKEmitter.addListener('searchRefresh', this.searchRefresh)
-    }
-
     if (config.setting.sync === 'true') {
       MKEmitter.addListener('transferSyncData', this.transferSyncData)
     }
 
     if (config.wrap.datatype === 'public') {
       MKEmitter.addListener('mkPublicData', this.mkPublicData)
+    } else if (config.setting.useMSearch) {
+      MKEmitter.addListener('searchRefresh', this.searchRefresh)
     }
 
     this.initExec()
@@ -118,9 +140,8 @@
     if (config.$syncId !== syncId) return
 
     let _data = window.GLOB.SyncData.get(config.dataName) || []
-    _data = _data[0] || {$$empty: true}
 
-    this.setState({data: _data})
+    this.setState({data: this.decodeHtml(_data, config.wrap)})
 
     window.GLOB.SyncData.delete(config.dataName)
 
@@ -142,8 +163,13 @@
 
     if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) {
       let _data = fromJS(data).toJS()
+      if (_data.$$empty) {
+        _data = []
+      } else {
+        _data = [_data]
+      }
 
-      this.setState({data: _data})
+      this.setState({data: this.decodeHtml(_data, config.wrap)})
     }
   }
 
@@ -153,7 +179,9 @@
     if (!config.setting.supModule || config.setting.supModule !== MenuID) return
     if (id !== this.state.BID || id !== '') {
       this.setState({ BID: id }, () => {
-        this.loadData()
+        if (config.wrap.datatype !== 'public') {
+          this.loadData()
+        }
       })
     }
   }
@@ -176,13 +204,13 @@
     
     if (config.wrap.datatype === 'static') {
       this.setState({
-        data: {$$empty: true},
+        data: [],
         loading: false
       })
       return
     } else if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
       this.setState({
-        data: {$$empty: true},
+        data: [],
         loading: false
       })
       return
@@ -206,54 +234,68 @@
 
     let result = await Api.genericInterface(param)
     if (result.status) {
-      let _data = result.data || []
-      _data = _data[0] || {$$empty: true}
-
       this.setState({
-        data: _data,
+        data: this.decodeHtml(result.data, config.wrap),
         loading: false
       })
-
-      if (result.message) {
-        if (result.ErrCode === 'Y') {
-          Modal.success({
-            title: result.message
-          })
-        } else if (result.ErrCode === 'S') {
-          notification.success({
-            top: 92,
-            message: result.message,
-            duration: 2
-          })
-        }
-      }
+      
+      UtilsDM.querySuccess(result)
     } else {
       this.setState({
         loading: false
       })
       
-      if (!result.message) return
-      if (result.ErrCode === 'N') {
-        Modal.error({
-          title: result.message
-        })
-      } else if (result.ErrCode !== '-2') {
-        notification.error({
-          top: 92,
-          message: result.message,
-          duration: 10
-        })
-      }
+      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() {
     const { config, loading, data } = this.state
 
-    if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null
+    if (config.wrap.empty === 'hidden' && (!data || data.length === 0)) return null
 
     return (
-      <div className={'custom-braft-editor-box ' + (config.wrap.firstTr || '')} id={'anchor' + config.uuid} style={config.style}>
+      <div className={'custom-braft-editor-box ' + (config.wrap.tbStyle || '')} id={'anchor' + config.uuid} style={config.style}>
         {loading ?
           <div className="loading-mask">
             <div className="ant-spin-blur"></div>
@@ -261,10 +303,13 @@
           </div> : null
         }
         <NormalHeader config={config}/>
-        <BraftContent
-          value={config.wrap.datatype !== 'static' ? (data[config.wrap.field] || '') : config.html}
-          encryption={config.wrap.datatype !== 'static' ? config.wrap.encryption : 'false'}
-        />
+        {config.wrap.datatype === 'static' ? <BraftContent
+          value={config.html}
+        /> : data.map((item, index) => <BraftContent
+          key={index}
+          value={item.$html}
+          script={config.wrap.loaded === 'true' ? config.wrap.loadedfunc : ''}
+        />)}
       </div>
     )
   }

--
Gitblit v1.8.0