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 |  273 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 200 insertions(+), 73 deletions(-)

diff --git a/src/tabviews/custom/components/editor/braft-editor/index.jsx b/src/tabviews/custom/components/editor/braft-editor/index.jsx
index 8b7c537..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 } from 'antd'
+import { Spin } from 'antd'
 
 import asyncComponent from '@/utils/asyncComponent'
 import Api from '@/api'
@@ -14,63 +14,99 @@
 
 class BraftEditorContent extends Component {
   static propTpyes = {
-    BID: PropTypes.any,              // 鐖剁骇Id
-    data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
-    config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
-    mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
-    menuType: PropTypes.any,         // 鑿滃崟绫诲瀷
+    config: PropTypes.object
   }
 
   state = {
     BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
-    sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
-    data: {}                   // 鏁版嵁
+    data: []                   // 鏁版嵁
   }
 
   UNSAFE_componentWillMount () {
-    const { data, initdata, BID } = this.props
-    let _config = fromJS(this.props.config).toJS()
+    const { config } = this.props
 
-    let _data = {}
-    let _sync = false
-    
-    if (_config.setting && _config.wrap.datatype !== 'static') {
-      _sync = _config.setting.sync === 'true'
+    let _config = fromJS(config).toJS()
+    let _data = []
 
-      if (_sync && data) {
-        _data = data[_config.dataName] || {}
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {}
-        }
-        _sync = false
-      } else if (_sync && initdata) {
-        _data = initdata || {}
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {}
-        }
-        _sync = false
-      }
+    let BID = ''
+    let BData = ''
+
+    if (_config.setting.supModule) {
+      BData = window.GLOB.CacheData.get(_config.setting.supModule)
     } else {
-      _data = {}
+      BData = window.GLOB.CacheData.get(_config.$pageId)
+    }
+    if (BData) {
+      BID = BData.$BID || ''
+    }
+    
+    if (_config.wrap.datatype === 'dynamic') {
+      _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) || []
+        _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({
-      sync: _sync,
-      data: _data,
+      data: this.decodeHtml(_data, _config.wrap),
       BID: BID || '',
       config: _config,
-      arr_field: _config.columns.map(col => col.field).join(','),
-    }, () => {
-      if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
-        this.loadData()
-      }
     })
   }
 
   componentDidMount () {
+    const { config } = this.state
+
     MKEmitter.addListener('reloadData', this.reloadData)
+    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+
+    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()
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -82,27 +118,70 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('mkPublicData', this.mkPublicData)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
+    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
   }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config } = this.state
+  initExec = () => {
+    const { config } = this.state
 
-    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
-      let _data = {}
-      if (nextProps.data && nextProps.data[config.dataName]) {
-        _data = nextProps.data[config.dataName]
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0]
-        }
+    if (config.wrap.datatype === 'dynamic' && config.setting.onload === 'true') {
+      setTimeout(() => {
+        this.loadData()
+      }, config.setting.delay || 0)
+    }
+  }
+
+  transferSyncData = (syncId) => {
+    const { config } = this.state
+
+    if (config.$syncId !== syncId) return
+
+    let _data = window.GLOB.SyncData.get(config.dataName) || []
+
+    this.setState({data: this.decodeHtml(_data, config.wrap)})
+
+    window.GLOB.SyncData.delete(config.dataName)
+
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
+  }
+
+  searchRefresh = (searchId) => {
+    const { config } = this.state
+
+    if (config.$searchId !== searchId) return
+    
+    this.setState({}, () => {
+      this.loadData()
+    })
+  }
+
+  mkPublicData = (publicId, data) => {
+    const { config } = this.state
+
+    if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) {
+      let _data = fromJS(data).toJS()
+      if (_data.$$empty) {
+        _data = []
+      } else {
+        _data = [_data]
       }
 
-      this.setState({sync: false, data: _data})
-    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({}, () => {
-        this.loadData()
+      this.setState({data: this.decodeHtml(_data, config.wrap)})
+    }
+  }
+
+  resetParentParam = (MenuID, id) => {
+    const { config } = this.state
+
+    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
+    if (id !== this.state.BID || id !== '') {
+      this.setState({ BID: id }, () => {
+        if (config.wrap.datatype !== 'public') {
+          this.loadData()
+        }
       })
     }
   }
@@ -116,27 +195,33 @@
   }
 
   async loadData () {
-    const { mainSearch, menuType } = this.props
-    const { config, arr_field, BID } = this.state
+    const { config, BID } = this.state
 
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.emit('reloadData', config.wrap.publicId)
+      return
+    }
+    
     if (config.wrap.datatype === 'static') {
       this.setState({
-        data: {},
+        data: [],
         loading: false
       })
       return
     } else if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
       this.setState({
-        data: {},
+        data: [],
         loading: false
       })
       return
     }
 
-    let searches = config.setting.useMSearch && mainSearch ? mainSearch : []
+    let searches = []
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      searches = window.GLOB.SearchBox.get(config.$searchId) || []
+    }
 
-    let requireFields = searches.filter(item => item.required && item.value === '')
-    if (requireFields.length > 0) {
+    if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) {
       return
     }
 
@@ -145,33 +230,72 @@
     })
 
     let _orderBy = config.setting.order || ''
-    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType)
+    let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 1, BID)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
-      let _data = result.data && result.data[0] ? result.data[0] : {}
-
       this.setState({
-        data: _data,
+        data: this.decodeHtml(result.data, config.wrap),
         loading: false
       })
+      
+      UtilsDM.querySuccess(result)
     } else {
       this.setState({
         loading: false
       })
-      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.length === 0)) return null
+
     return (
-      <div className="custom-braft-editor-box" 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>
@@ -179,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