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/card/data-card/index.jsx |  266 +++++++++++++++++++++++++++-------------------------
 1 files changed, 137 insertions(+), 129 deletions(-)

diff --git a/src/tabviews/custom/components/card/data-card/index.jsx b/src/tabviews/custom/components/card/data-card/index.jsx
index 8ab93fe..5b58e10 100644
--- a/src/tabviews/custom/components/card/data-card/index.jsx
+++ b/src/tabviews/custom/components/card/data-card/index.jsx
@@ -5,7 +5,6 @@
 import { DownOutlined } from '@ant-design/icons'
 
 import Api from '@/api'
-import Utils from '@/utils/utils.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import preImg from '@/assets/img/prev.png'
 import nextImg from '@/assets/img/next.png'
@@ -21,9 +20,7 @@
 
 class DataCard extends Component {
   static propTpyes = {
-    data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
-    config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
-    mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
+    config: PropTypes.object
   }
 
   state = {
@@ -39,7 +36,6 @@
     selectKeys: [],            // 澶氶�夋椂閫変腑鍗$墖
     selectedData: [],          // 閫変腑鏁版嵁锛岀敤浜庡伐鍏锋爮鎸夐挳
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
-    sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     card: null,                // 鍗$墖璁剧疆
     data: null,                // 鏁版嵁
     total: null,
@@ -53,9 +49,9 @@
   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 BID = ''
     let BData = ''
 
@@ -119,49 +115,12 @@
     })
 
     _config.subcards = null
-    
-    let _data = null
-    let _sync = _config.setting.sync === 'true'
-
-    if (_sync && data) {
-      _data = data[_config.dataName] || []
-      _sync = false
-    } else if (_sync && initdata) {
-      _data = initdata || []
-      _sync = false
-    }
 
     let selected = 'false'
     if (_config.wrap.selected === 'always' || _config.wrap.selected === 'init' || _config.wrap.selected === 'sign') {
       selected = _config.wrap.selected
     } else {
       _config.wrap.selected = 'false'
-    }
-
-    if (_data) {
-      _data = _data.map((item, index) => {
-        item.key = index
-        item.$$uuid = item[_config.setting.primaryKey] || ''
-        item.$$BID = BID || ''
-        item.$$BData = BData || ''
-        item.$Index = index + 1 + ''
-
-        if (_config.wrap.controlField) {
-          if (_config.wrap.controlVal.includes(item[_config.wrap.controlField] + '')) {
-            item.$disabled = true
-          }
-        }
-        return item
-      })
-
-      if (selected !== 'false') {
-        setTimeout(() => {
-          this.checkTopLine()
-        }, 200)
-        if (selected === 'init') {
-          selected = 'false'
-        }
-      }
     }
 
     let supComs = null
@@ -175,8 +134,6 @@
     _config.wrap.layout = (_config.wrap.layout || 'grid') + '-layout float-' + (_config.wrap.cardFloat || 'left')
 
     _config.wrap.wrapClass =  `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale}`
-
-    this.loaded = _data !== null
 
     let pageOptions = ['10', '25', '50', '100', '500', '1000']
 
@@ -192,6 +149,36 @@
       }
     }
 
+    let _data = null
+    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())
+      }
+
+      _config.setting.sync = 'false'
+
+      _data = _data.map((item, index) => {
+        item.key = index
+        item.$$uuid = item[_config.setting.primaryKey] || ''
+        item.$$BID = BID || ''
+        item.$$BData = BData || ''
+        item.$Index = index + 1 + ''
+
+        if (_config.wrap.controlField) {
+          if (_config.wrap.controlVal.includes(item[_config.wrap.controlField] + '')) {
+            item.$disabled = true
+          }
+        }
+        return item
+      })
+
+      this.loaded = true
+
+      window.GLOB.SyncData.delete(_config.dataName)
+    }
+
     this.setState({
       pageSize: _config.setting.pageSize || 10,
       pageOptions,
@@ -199,20 +186,21 @@
       selected,
       precards,
       nextcards,
-      sync: _sync,
       data: _data,
       BID: BID || '',
       BData: BData || '',
       config: _config,
       card: _card,
-      search: Utils.initMainSearch(_config.search),
+      search: _config.$searches,
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
-      if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') {
+      if (config.setting.sync !== 'true' && _config.setting.onload === 'true') {
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
       }
+
+      this.loaded && this.prevCheck()
     })
   }
 
@@ -221,10 +209,18 @@
 
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('mkCheckAll', this.mkCheckAll)
+    MKEmitter.addListener('refreshLineData', this.refreshLineData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
-    MKEmitter.addListener('refreshLineData', this.refreshLineData)
     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) {
       this.timer = new TimerTask()
@@ -263,61 +259,70 @@
     return !is(fromJS(this.state), fromJS(nextState))
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config, BID, BData, selected } = 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] || []
-        _data = _data.map((item, index) => {
-          item.key = index
-          item.$$uuid = item[config.setting.primaryKey] || ''
-          item.$$BID = BID || ''
-          item.$$BData = BData || ''
-          item.$Index = index + 1 + ''
-
-          if (config.wrap.controlField) {
-            if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) {
-              item.$disabled = true
-            }
-          }
-
-          return item
-        })
-
-        if (selected !== 'false') {
-          setTimeout(() => {
-            this.checkTopLine()
-          }, 200)
-          if (selected === 'init') {
-            this.setState({selected: 'false'})
-          }
-        }
-      }
-
-      this.loaded = true
-
-      this.setState({sync: false, data: _data})
-    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({pageIndex: 1}, () => {
-        this.loadData()
-      })
-    }
-  }
-
   componentWillUnmount () {
     this.setState = () => {
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('mkCheckAll', this.mkCheckAll)
-    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
-    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
     MKEmitter.removeListener('refreshLineData', this.refreshLineData)
+    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()
+  }
+
+  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())
+    }
+
+    _data = _data.map((item, index) => {
+      item.key = index
+      item.$$uuid = item[config.setting.primaryKey] || ''
+      item.$$BID = BID || ''
+      item.$$BData = BData || ''
+      item.$Index = index + 1 + ''
+
+      if (config.wrap.controlField) {
+        if (config.wrap.controlVal.includes(item[config.wrap.controlField] + '')) {
+          item.$disabled = true
+        }
+      }
+
+      return item
+    })
+
+    this.prevCheck()
+
+    this.loaded = true
+
+    this.setState({data: _data})
+
+    window.GLOB.SyncData.delete(config.dataName)
+
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
+  }
+
+  searchRefresh = (searchId) => {
+    const { config } = this.state
+
+    if (config.$searchId !== searchId) return
+    
+    this.setState({pageIndex: 1}, () => {
+      this.loadData()
+    })
   }
 
   /**
@@ -398,6 +403,20 @@
     this.setState({
       data: _data
     })
+  }
+
+  prevCheck = (id) => {
+    const { selected } = this.state
+
+    if (selected === 'false' && !id) return
+
+    setTimeout(() => {
+      this.checkTopLine(id)
+    }, 200)
+
+    if (selected === 'init') {
+      this.setState({selected: 'false'})
+    }
   }
 
   checkTopLine = (id) => {
@@ -616,18 +635,18 @@
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
   queryModuleParam = (menuId, callback) => {
-    const { mainSearch } = this.props
     const { arr_field, config, search, orderBy } = this.state
 
     if (config.uuid !== menuId) return
 
-    let searches = search ? fromJS(search).toJS() : []
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key.toLowerCase())
+    let searches = fromJS(search).toJS()
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || []
+      let keys = config.$s_keys || []
       mainSearch.forEach(item => {
-        if (!keys.includes(item.key.toLowerCase())) {
-          searches.push(item)
-        }
+        if (keys.includes(item.key.toLowerCase())) return
+
+        searches.push(item)
       })
     }
 
@@ -640,7 +659,6 @@
   }
 
   async loadData (id, type) {
-    const { mainSearch } = this.props
     const { config, arr_field, pageIndex, pageSize, search, BID, BData, selected, orderBy } = this.state
 
     if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -657,12 +675,7 @@
       })
       
       if (selected !== 'false' || (id && config.wrap.selected !== 'false')) {
-        setTimeout(() => {
-          this.checkTopLine(id)
-        }, 200)
-        if (selected === 'init') {
-          this.setState({selected: 'false'})
-        }
+        this.prevCheck(id)
       } else {
         MKEmitter.emit('resetSelectLine', config.uuid, '', '')
         if (config.setting.$hasSyncModule) {
@@ -673,17 +686,17 @@
     }
 
     let searches = fromJS(search).toJS()
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key.toLowerCase())
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || []
+      let keys = config.$s_keys || []
       mainSearch.forEach(item => {
-        if (!keys.includes(item.key.toLowerCase())) {
-          searches.push(item)
-        }
+        if (keys.includes(item.key.toLowerCase())) return
+
+        searches.push(item)
       })
     }
 
-    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
     }
 
@@ -705,16 +718,11 @@
 
       this.loaded = true
       if (config.$cache && pageIndex === 1 && config.setting.onload !== 'false') {
-        Api.writeCacheConfig(config.uuid, result.data || '')
+        Api.writeCacheConfig(config.uuid, result.data || [])
       }
 
       if (selected !== 'false' || (id && config.wrap.selected !== 'false')) {
-        setTimeout(() => {
-          this.checkTopLine(id)
-        }, 200)
-        if (selected === 'init') {
-          this.setState({selected: 'false'})
-        }
+        this.prevCheck(id)
       } else {
         MKEmitter.emit('resetSelectLine', config.uuid, '', '')
         if (config.setting.$hasSyncModule) {
@@ -810,16 +818,16 @@
    * @description 鑾峰彇鍗曡鏁版嵁
    */ 
   async loadLinedata (id) {
-    const { mainSearch } = this.props
     const { config, arr_field, pageIndex, pageSize, search, BID, BData, orderBy } = this.state
 
     let searches = fromJS(search).toJS()
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key.toLowerCase())
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      let mainSearch = window.GLOB.SearchBox.get(config.$searchId) || []
+      let keys = config.$s_keys || []
       mainSearch.forEach(item => {
-        if (!keys.includes(item.key.toLowerCase())) {
-          searches.push(item)
-        }
+        if (keys.includes(item.key.toLowerCase())) return
+
+        searches.push(item)
       })
     }
 

--
Gitblit v1.8.0