From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 27 八月 2023 18:37:36 +0800
Subject: [PATCH] 2023-08-27

---
 src/tabviews/custom/components/card/balcony/index.jsx |  255 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 157 insertions(+), 98 deletions(-)

diff --git a/src/tabviews/custom/components/card/balcony/index.jsx b/src/tabviews/custom/components/card/balcony/index.jsx
index 1697e66..8378215 100644
--- a/src/tabviews/custom/components/card/balcony/index.jsx
+++ b/src/tabviews/custom/components/card/balcony/index.jsx
@@ -14,8 +14,7 @@
 
 class BalconyComponent extends Component {
   static propTpyes = {
-    data: PropTypes.array,
-    config: PropTypes.object,
+    config: PropTypes.object
   }
 
   state = {
@@ -23,7 +22,6 @@
     config: null,
     syncConfig: null,
     loading: false,
-    sync: false,
     data: {},
     BData: null,
     syncData: [],
@@ -34,12 +32,9 @@
   loaded = false
 
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
-    let _config = fromJS(this.props.config).toJS()
+    const { config } = this.props
 
-    let _data = { $$empty: true }
-    let _sync = false
-
+    let _config = fromJS(config).toJS()
     let BID = ''
     let BData = ''
 
@@ -52,30 +47,30 @@
       BID = BData.$BID || ''
     }
     
+    let _data = { $$empty: true }
     if (_config.wrap.datatype === 'dynamic') {
-      _sync = _config.setting.sync === 'true'
+      _config.setting.onload = _config.setting.sync === 'true' ? 'false' : 'true'
 
-      if (_sync && data) {
-        _data = data[_config.dataName] || {$$empty: true}
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {$$empty: true}
+      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)
         }
-        _sync = false
+
+        _config.setting.sync = 'false'
+
+        _data = _data[0] || {$$empty: true}
+
         this.loaded = true
-      } else if (_sync && initdata) {
-        _data = initdata
-        if (Array.isArray(_data)) {
-          _data = _data[0] || {$$empty: true}
-        }
-        _sync = false
-        this.loaded = true
+
+        window.GLOB.SyncData.delete(_config.dataName)
       }
-    } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) {
-      _data = window.GLOB.CacheData.get(_config.wrap.publicId)
-      _data = fromJS(_data).toJS()
-      this.loaded = true
-    } else if (_config.wrap.datatype === 'static') {
-      this.loaded = true
+    } else if (_config.wrap.datatype === 'public') {
+      if (window.GLOB.CacheData.has(_config.wrap.publicId)) {
+        _data = window.GLOB.CacheData.get(_config.wrap.publicId)
+        _data = fromJS(_data).toJS()
+      }
     }
 
     _data.$$BID = BID || ''
@@ -84,21 +79,23 @@
       _data.$$uuid = _data[_config.setting.primaryKey] || ''
     }
 
-    if (_config.wrap.position === 'fixed' || _config.wrap.position === 'absolute') {
-      _config.style.position = _config.wrap.position
-      _config.style.zIndex = _config.wrap.position === 'fixed' ? 3 : 2
-      _config.style.left = _config.wrap.left || ''
-      _config.style.right = _config.wrap.right || ''
-      _config.style.top = _config.wrap.top || ''
-      _config.style.bottom = _config.wrap.bottom || ''
-      _config.style.transform = _config.wrap.transform || ''
-      _config.style.width = _config.wrap.realwidth || ''
-    } else {
-      _config.style.zIndex = 1
-      _config.style.left = _config.wrap.left || ''
-      _config.style.right = _config.wrap.right || ''
-      _config.style.top = _config.wrap.top || ''
-      _config.style.bottom = _config.wrap.bottom || ''
+    if (!_config.style.position) {
+      if (_config.wrap.position === 'fixed' || _config.wrap.position === 'absolute') {
+        _config.style.position = _config.wrap.position
+        _config.style.zIndex = _config.wrap.position === 'fixed' ? 3 : 2
+        _config.style.left = _config.wrap.left || ''
+        _config.style.right = _config.wrap.right || ''
+        _config.style.top = _config.wrap.top || ''
+        _config.style.bottom = _config.wrap.bottom || ''
+        _config.style.transform = _config.wrap.transform || ''
+        _config.style.width = _config.wrap.realwidth || ''
+      } else {
+        _config.style.zIndex = 1
+        _config.style.left = _config.wrap.left || ''
+        _config.style.right = _config.wrap.right || ''
+        _config.style.top = _config.wrap.top || ''
+        _config.style.bottom = _config.wrap.bottom || ''
+      }
     }
 
     let show = true
@@ -119,17 +116,9 @@
     this.setState({
       show,
       syncConfig,
-      sync: _sync,
       data: _data,
       BID: BID || '',
-      config: _config,
-      arr_field: _config.columns.map(col => col.field).join(','),
-    }, () => {
-      if (_config.wrap.datatype === 'dynamic' && _config.setting && _config.setting.sync !== 'true') {
-        setTimeout(() => {
-          this.loadData()
-        }, _config.setting.delay || 0)
-      }
+      config: _config
     })
   }
 
@@ -137,29 +126,27 @@
     const { config } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
+    MKEmitter.addListener('refreshLineData', this.refreshLineData)
     MKEmitter.addListener('syncBalconyData', this.syncBalconyData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
 
+    if (config.setting.sync === 'true') {
+      MKEmitter.addListener('transferSyncData', this.transferSyncData)
+    }
+
     if (config.wrap.datatype === 'public') {
       MKEmitter.addListener('mkPublicData', this.mkPublicData)
     }
     
-    if (config.timer && config.wrap.datatype === 'dynamic') {
-      this.timer = new TimerTask()
-      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)})
-    }
+    if (config.wrap.datatype === 'dynamic') {
+      if (config.timer) {
+        this.timer = new TimerTask()
+        this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData('timer')})
+      }
 
-    if (config.$cache && !this.loaded) {
-      Api.getLCacheConfig(config.uuid).then(res => {
-        if (!res || this.loaded) return
-
-        let _data = res[0]
-        _data.$$uuid = _data[config.setting.primaryKey] || ''
-
-        this.setState({data: _data})
-      })
+      this.initExec()
     }
   }
 
@@ -173,37 +160,88 @@
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('mkPublicData', this.mkPublicData)
+    MKEmitter.removeListener('refreshLineData', this.refreshLineData)
     MKEmitter.removeListener('syncBalconyData', this.syncBalconyData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
 
     this.timer && this.timer.stop()
   }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config, BID, BData } = this.state
+  initExec = () => {
+    const { config, BID } = this.state
 
-    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
-      let _data = {$$empty: true}
-      if (nextProps.data && nextProps.data[config.dataName]) {
-        _data = nextProps.data[config.dataName]
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {$$empty: true}
+    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
+
+            let _data = res.data[0] || {$$empty: true}
+            _data.$$uuid = _data[config.setting.primaryKey] || ''
+    
+            this.setState({data: _data})
+          })
+        }
+      } else {
+        if (!this.loaded) {
+          Api.getLCacheConfig(config.uuid, 0, BID).then(res => {
+            if (!res.data || this.loaded) return
+    
+            let _data = res.data[0] || {$$empty: true}
+            _data.$$uuid = _data[config.setting.primaryKey] || ''
+    
+            this.setState({data: _data})
+          })
+        }
+
+        if (config.setting.onload === 'true') {
+          setTimeout(() => {
+            this.loadData('init')
+          }, config.setting.delay || 0)
         }
       }
-
-      _data.$$BID = BID || ''
-      _data.$$BData = BData || ''
-      _data.$$uuid = _data[config.setting.primaryKey] || ''
-
-      this.loaded = true
-
-      this.setState({sync: false, data: _data})
+    } else if (config.setting.onload === 'true') {
+      setTimeout(() => {
+        this.loadData()
+      }, config.setting.delay || 0)
     }
+  }
+
+  transferSyncData = (syncId) => {
+    const { config } = this.state
+
+    if (config.$syncId !== syncId) return
+
+    const { BID, BData } = this.state
+
+    let _data = window.GLOB.SyncData.get(config.dataName) || []
+
+    if (config.$cache) {
+      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID)
+    }
+
+    _data = _data[0] || {$$empty: true}
+
+    _data.$$BID = BID || ''
+    _data.$$BData = BData || ''
+    _data.$$uuid = _data[config.setting.primaryKey] || ''
+
+    this.loaded = true
+
+    this.setState({data: _data})
+
+    window.GLOB.SyncData.delete(config.dataName)
+
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
   }
 
   mkPublicData = (publicId, data) => {
@@ -215,8 +253,6 @@
       _data.$$BID = BID || ''
       _data.$$BData = BData || ''
       _data.$$uuid = _data[config.setting.primaryKey] || ''
-
-      this.loaded = true
 
       this.setState({data: _data})
     }
@@ -243,11 +279,20 @@
       } else {
         this.loadData()
       }
-      
-      if (position === 'popclose') {                                      // 鏍囩鍏抽棴鍒锋柊
-        btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
-      }
     }
+  }
+
+  refreshLineData = (menuId, btn, uuid, count) => {
+    const { config, data } = this.state
+
+    if (config.uuid !== menuId) return
+    
+    let _data = fromJS(data).toJS()
+    _data[btn.field] = count
+
+    this.setState({
+      data: _data
+    })
   }
 
   syncBalconyData = (menuId, data, checked) => {
@@ -293,10 +338,8 @@
     if (config.uuid !== menuId) return
 
     callback({
-      arr_field: '',
       orderBy: '',
       search: [],
-      menuName: config.name
     })
   }
 
@@ -308,8 +351,8 @@
     this.loadData()
   }
 
-  async loadData (hastimer) {
-    const { config, arr_field, BID, BData } = this.state
+  async loadData (type) {
+    const { config, BID, BData } = this.state
 
     if (config.wrap.datatype === 'public') {
       MKEmitter.emit('reloadData', config.wrap.publicId)
@@ -331,22 +374,22 @@
 
     let searches = []
 
-    if (!hastimer) {
+    if (type !== 'timer') {
       this.setState({
         loading: true
       })
     }
 
     let _orderBy = config.setting.order || ''
-    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID)
+    let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 1, BID)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
       let _data = {}
 
       this.loaded = true
-      if (config.$cache && config.setting.onload !== 'false') {
-        Api.writeCacheConfig(config.uuid, result.data || '')
+      if (config.$cache && type === 'init') {
+        Api.writeCacheConfig(config.uuid, result.data || [], BID)
       }
 
       if (!result.data || !result.data[0]) {
@@ -370,16 +413,32 @@
           this.timer && this.timer.stop()
         }
       }
+
+      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
+          })
+        }
+      }
     } else {
       this.setState({
         loading: false
       })
       this.timer && this.timer.stop()
+      
+      if (!result.message) return
       if (result.ErrCode === 'N') {
         Modal.error({
           title: result.message,
         })
-      } else {
+      } else if (result.ErrCode !== '-2') {
         notification.error({
           top: 92,
           message: result.message,

--
Gitblit v1.8.0