From f3d4db769ba9b51b799d981511a710fd443d0e08 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 21 四月 2025 12:18:03 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/tabviews/custom/components/code/sand-box/index.jsx |  275 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 191 insertions(+), 84 deletions(-)

diff --git a/src/tabviews/custom/components/code/sand-box/index.jsx b/src/tabviews/custom/components/code/sand-box/index.jsx
index 508932b..0116fe3 100644
--- a/src/tabviews/custom/components/code/sand-box/index.jsx
+++ b/src/tabviews/custom/components/code/sand-box/index.jsx
@@ -10,71 +10,90 @@
 
 class SandBoxComponent 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: [],                  // 鏁版嵁
     html: '',
+    result: {}
   }
 
+  loaded = false
+
   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 = []
+    let BID = ''
+    let BData = ''
 
-      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
-      }
+    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 !== 'static') {
+      _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) || []
+  
+        if (_config.$cache) {
+          Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS(), BID)
+        }
+  
+        _config.setting.sync = 'false'
+  
+        this.loaded = true
+  
+        window.GLOB.SyncData.delete(_config.dataName)
+      }
     }
     
     if (_config.css) {
+      let node = document.getElementById(_config.uuid)
+      node && node.remove()
+
       let ele = document.createElement('style')
+      ele.id = _config.uuid
       ele.innerHTML = _config.css
       document.getElementsByTagName('head')[0].appendChild(ele)
     }
 
     this.setState({
-      sync: _sync,
       data: _data,
       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()
-      }
-      this.renderView()
+      config: _config
     })
   }
 
   componentDidMount () {
+    const { config } = this.state
+
     MKEmitter.addListener('reloadData', this.reloadData)
+
+    if (config.setting.useMSearch) {
+      MKEmitter.addListener('searchRefresh', this.searchRefresh)
+    }
+
+    if (config.setting.sync === 'true') {
+      MKEmitter.addListener('transferSyncData', this.transferSyncData)
+    }
+
+    this.initExec()
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -86,31 +105,98 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
   }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config } = this.state
+  initExec = () => {
+    const { config, BID } = 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 !== 'static') {
+      if (config.$cache) {
+        if (config.$time) {
+          if (!this.loaded) {
+            Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => {
+              if (!res.valid && config.setting.onload === 'true') {
+                setTimeout(() => {
+                  this.loadData('init')
+                }, config.setting.delay || 0)
+              }
+    
+              if (!res.data || this.loaded) return
+  
+              this.setState({data: res.data}, () => {
+                this.renderView()
+              })
+            })
+          } else {
+            this.renderView()
+          }
+        } else {
+          if (!this.loaded) {
+            Api.getLCacheConfig(config.uuid, 0, BID).then(res => {
+              if (!res.data || this.loaded) return
+      
+              this.setState({data: res.data}, () => {
+                this.renderView()
+              })
+            })
+          }
+  
+          if (config.setting.onload === 'true') {
+            setTimeout(() => {
+              this.loadData('init')
+            }, config.setting.delay || 0)
+          } else if (this.loaded) {
+            this.renderView()
+          }
         }
-      }
-
-      this.setState({sync: false, data: _data}, () => {
+      } else if (config.setting.onload === 'true') {
+        setTimeout(() => {
+          this.loadData()
+        }, config.setting.delay || 0)
+      } else if (this.loaded) {
         this.renderView()
-      })
-    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({}, () => {
-        this.loadData()
-      })
+      }
+    } else {
+      this.renderView()
     }
+  }
+
+  transferSyncData = (syncId) => {
+    const { config, BID } = this.state
+
+    if (config.$syncId !== syncId) return
+
+    let _data = window.GLOB.SyncData.get(config.dataName) || []
+
+    if (config.$cache) {
+      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID)
+    }
+
+    if (!is(fromJS(this.state.data), fromJS(_data))) {
+      setTimeout(() => {
+        this.renderView()
+      }, 10)
+    }
+
+    this.setState({data: _data})
+
+    this.loaded = true
+
+    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()
+    })
   }
 
   reloadData = (menuId) => {
@@ -121,28 +207,30 @@
     this.loadData()
   }
 
-  async loadData () {
-    const { mainSearch, menuType } = this.props
-    const { config, arr_field, BID } = this.state
+  async loadData (type) {
+    const { config, BID } = this.state
 
     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
       })
+      this.loaded = true
       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
     }
 
@@ -151,52 +239,71 @@
     })
 
     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] : {}
+      let _data = result.data || []
+
+      this.loaded = true
+      if (config.$cache && type === 'init') {
+        Api.writeCacheConfig(config.uuid, result.data || [], BID)
+      }
+
+      if (!is(fromJS(this.state.data), fromJS(_data))) {
+        setTimeout(() => {
+          this.renderView()
+        }, 10)
+      }
+
+      let _result = {...result}
+      delete _result.data
 
       this.setState({
         data: _data,
+        result: _result,
         loading: false
-      }, () => {
-        this.renderView()
       })
+
+      
+      UtilsDM.querySuccess(result)
     } else {
       this.setState({
         loading: false
       })
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
+
+      UtilsDM.queryFail(result)
     }
   }
 
   renderView = () => {
-    const { data } = this.state
+    const { data, result } = this.state
     const { html, js, wrap, columns } = this.state.config
 
     let _html = html
     if (_html && wrap.datatype !== 'static') {
-      columns.forEach(col => {
-        if (col.field) {
-          let val = (data[col.field] || data[col.field] === 0) ? data[col.field] : ''
-          let reg = new RegExp('@' + col.field + '@', 'ig')
+      if (/@[\u4E00-\u9FA50-9a-zA-Z_]+@/ig.test(_html)) {
+        let _data = data[0] || {}
 
-          _html = _html.replace(reg, val)
-        }
-      })
+        columns.forEach(col => {
+          if (col.field) {
+            let val = _data[col.field] !== undefined ? _data[col.field] : ''
+            let reg = new RegExp('@' + col.field + '@', 'ig')
+  
+            _html = _html.replace(reg, val)
+          }
+        })
+      }
     }
+
     this.setState({html: _html}, () => {
       if (js) {
         try {
-          // eslint-disable-next-line no-eval
-          eval(js)
+          // eslint-disable-next-line
+          let evalfunc = eval('(true && function (data, result, Api, notification, systemType) {' + js + '})')
+          evalfunc(data, result, Api, notification, window.GLOB.systemType)
         } catch (e) {
-          console.warn('JS 鎵ц澶辫触锛�')
+          console.warn(e)
         }
       }
     })
@@ -206,7 +313,7 @@
     const { config, loading, html } = this.state
 
     return (
-      <div className="custom-sand-box" style={{...config.style}}>
+      <div className="custom-sand-box" id={'anchor' + config.uuid} style={{...config.style}}>
         {loading ?
           <div className="loading-mask">
             <div className="ant-spin-blur"></div>

--
Gitblit v1.8.0