From 71e3da644eca32a5aa40503e903efb0640748093 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 21 七月 2023 17:00:59 +0800
Subject: [PATCH] 2023-07-21

---
 src/tabviews/custom/components/carousel/prop-card/index.jsx |  127 +++++++++++++++++++++++------------------
 1 files changed, 71 insertions(+), 56 deletions(-)

diff --git a/src/tabviews/custom/components/carousel/prop-card/index.jsx b/src/tabviews/custom/components/carousel/prop-card/index.jsx
index b5806a3..e732b7a 100644
--- a/src/tabviews/custom/components/carousel/prop-card/index.jsx
+++ b/src/tabviews/custom/components/carousel/prop-card/index.jsx
@@ -16,16 +16,13 @@
 
 class PropCard extends Component {
   static propTpyes = {
-    data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
-    config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
-    mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
+    config: PropTypes.object
   }
 
   state = {
     BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
-    sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     data: {$$empty: true},
     BData: null,
     visible: false
@@ -34,11 +31,10 @@
   loaded = false
 
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
-    let _config = fromJS(this.props.config).toJS()
+    const { config } = this.props
 
+    let _config = fromJS(config).toJS()
     let _data = {$$empty: true}
-    let _sync = false
 
     let BID = ''
     let BData = ''
@@ -53,22 +49,20 @@
     }
     
     if (_config.wrap.datatype === 'dynamic') {
-      _sync = _config.setting.sync === 'true'
+      if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
+        _data = window.GLOB.SyncData.get(_config.dataName) || []
 
-      if (_sync && data) {
-        _data = data[_config.dataName] || {$$empty: true}
-        if (Array.isArray(_data)) {
-          _data = _data[0] || {$$empty: true}
+        if (_config.$cache) {
+          Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS())
         }
-        _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 === 'static') {
       this.loaded = true
@@ -93,14 +87,13 @@
     _config.wrap.speed = (_config.wrap.speed || 3) * 1000
 
     this.setState({
-      sync: _sync,
       data: _data,
       BID: BID || '',
       BData: BData || '',
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
-      if (_config.wrap.datatype === 'dynamic' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
+      if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') {
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
@@ -118,6 +111,14 @@
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
 
+    if (config.setting.useMSearch) {
+      MKEmitter.addListener('searchRefresh', this.searchRefresh)
+    }
+
+    if (config.setting.sync === 'true') {
+      MKEmitter.addListener('transferSyncData', this.transferSyncData)
+    }
+
     if (config.timer && config.wrap.datatype === 'dynamic') {
       this.timer = new TimerTask()
       this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
@@ -129,7 +130,7 @@
       Api.getLCacheConfig(config.uuid).then(res => {
         if (!res || this.loaded) return
 
-        let _data = res[0]
+        let _data = res[0] || {$$empty: true}
         _data.$$uuid = _data[config.setting.primaryKey] || ''
 
         this.setState({data: _data})
@@ -146,44 +147,55 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
 
     this.timer && this.timer.stop()
   }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config, BID, BData } = this.state
+  transferSyncData = (syncId) => {
+    const { config } = 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 (Array.isArray(_data)) {
-          _data = _data[0] || {$$empty: true}
-        }
-      }
+    if (config.$syncId !== syncId) return
 
-      _data.$$uuid = _data[config.setting.primaryKey] || ''
-      _data.$$BID = BID || ''
-      _data.$$BData = BData || ''
+    const { BID, BData } = this.state
 
-      this.loaded = true
+    let _data = window.GLOB.SyncData.get(config.dataName) || []
 
-      this.setState({sync: false, data: _data}, () => {
-        if (config.wrap.display === 'modal') {
-          this.openModal()
-        }
-      })
-    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({}, () => {
-        this.loadData()
-      })
+    if (config.$cache) {
+      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS())
     }
+
+    _data = _data[0] || {$$empty: true}
+
+    _data.$$BID = BID || ''
+    _data.$$BData = BData || ''
+    _data.$$uuid = _data[config.setting.primaryKey] || ''
+
+    this.loaded = true
+
+    this.setState({data: _data}, () => {
+      if (config.wrap.display === 'modal') {
+        this.openModal()
+      }
+    })
+
+    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()
+    })
   }
 
   openModal = (ErrCode) => {
@@ -242,12 +254,14 @@
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
   queryModuleParam = (menuId, callback) => {
-    const { mainSearch } = this.props
     const { config } = this.state
 
     if (config.uuid !== menuId) return
 
-    let searches = config.setting.useMSearch && mainSearch ? mainSearch : []
+    let searches = []
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      searches = window.GLOB.SearchBox.get(config.$searchId) || []
+    }
 
     callback({
       arr_field: '',
@@ -266,7 +280,6 @@
   }
 
   async loadData (type) {
-    const { mainSearch } = this.props
     const { config, arr_field, BID, BData } = this.state
 
     if (config.wrap.datatype === 'static') {
@@ -283,10 +296,12 @@
       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
     }
 
@@ -305,7 +320,7 @@
 
       this.loaded = true
       if (config.$cache && config.setting.onload !== 'false') {
-        Api.writeCacheConfig(config.uuid, result.data || '')
+        Api.writeCacheConfig(config.uuid, result.data || [])
       }
 
       if (!result.data || !result.data[0]) {

--
Gitblit v1.8.0