From 93ace1795e0e9b1a443b1c447a646fa8932f9678 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 21 七月 2023 20:43:25 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/tabviews/custom/components/card/table-card/index.jsx |  165 ++++++++++++++++++++++++++++++-------------------------
 1 files changed, 90 insertions(+), 75 deletions(-)

diff --git a/src/tabviews/custom/components/card/table-card/index.jsx b/src/tabviews/custom/components/card/table-card/index.jsx
index c23e2c7..ed2f53c 100644
--- a/src/tabviews/custom/components/card/table-card/index.jsx
+++ b/src/tabviews/custom/components/card/table-card/index.jsx
@@ -5,7 +5,6 @@
 import { DownOutlined } from '@ant-design/icons'
 
 import Api from '@/api'
-import Utils from '@/utils/utils.js'
 import asyncComponent from '@/utils/asyncComponent'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import MKEmitter from '@/utils/events.js'
@@ -17,9 +16,7 @@
 
 class TableCard extends Component {
   static propTpyes = {
-    data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
-    config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
-    mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
+    config: PropTypes.object
   }
 
   state = {
@@ -29,7 +26,6 @@
     search: null,              // 鎼滅储鏉′欢
     pageIndex: 1,              // 椤电爜
     total: 0,                  // 鎬绘暟
-    sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     data: null,                // 鏁版嵁
     BData: ''
   }
@@ -41,12 +37,9 @@
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
    */
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
-    let _config = fromJS(this.props.config).toJS()
+    const { config } = this.props
 
-    let _data = null
-    let _sync = _config.setting.sync === 'true'
-
+    let _config = fromJS(config).toJS()
     let BID = ''
     let BData = ''
 
@@ -57,25 +50,6 @@
     }
     if (BData) {
       BID = BData.$BID || ''
-    }
-
-    if (_config.setting.sync === 'true' && data) {
-      _data = data[_config.dataName] || []
-      _sync = false
-    } else if (_config.setting.sync === 'true' && initdata) {
-      _data = initdata || []
-      _sync = 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 + ''
-        return item
-      })
     }
 
     let showHeader = false
@@ -92,18 +66,39 @@
       _config.wrap.contentHeight = showHeader ? 'calc(100% - 45px)' : '100%'
     }
 
-    this.loaded = _data !== null
+    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 + ''
+        return item
+      })
+
+      this.loaded = true
+
+      window.GLOB.SyncData.delete(_config.dataName)
+    }
 
     this.setState({
-      sync: _sync,
       BID: BID || '',
       BData: BData || '',
       data: _data,
       config: _config,
-      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)
@@ -115,10 +110,18 @@
     const { config } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
+    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()
@@ -156,43 +159,56 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
-    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()
   }
 
-  /**
-   * @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 = []
-      if (nextProps.data && nextProps.data[config.dataName]) {
-        _data = nextProps.data[config.dataName] || []
-      }
+    if (config.$syncId !== syncId) return
 
-      _data = _data.map((item, index) => {
-        item.key = index
-        item.$$uuid = item[config.setting.primaryKey] || ''
-        item.$$BID = BID || ''
-        item.$$BData = BData || ''
-        item.$Index = index + 1 + ''
-        return item
-      })
+    const { BID, BData } = this.state
 
-      this.loaded = true
+    let _data = window.GLOB.SyncData.get(config.dataName) || []
 
-      this.setState({sync: false, data: _data})
-    } 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.map((item, index) => {
+      item.key = index
+      item.$$uuid = item[config.setting.primaryKey] || ''
+      item.$$BID = BID || ''
+      item.$$BData = BData || ''
+      item.$Index = index + 1 + ''
+
+      return item
+    })
+
+    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({}, () => {
+      this.loadData()
+    })
   }
 
   /**
@@ -253,18 +269,18 @@
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
   queryModuleParam = (menuId, callback) => {
-    const { mainSearch } = this.props
     const { arr_field, config, search } = 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())
+    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)
       })
     }
 
@@ -277,7 +293,6 @@
   }
 
   async loadData (type) {
-    const { mainSearch } = this.props
     const { config, arr_field, pageIndex, search, BID, BData } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -291,17 +306,17 @@
     }
 
     let searches = search ? fromJS(search).toJS() : []
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key)
+    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)) {
-          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
     }
 
@@ -323,7 +338,7 @@
 
       this.loaded = true
       if (config.$cache && pageIndex === 1 && config.setting.onload !== 'false') {
-        Api.writeCacheConfig(config.uuid, result.data || '')
+        Api.writeCacheConfig(config.uuid, result.data || [])
       }
 
       let data = []

--
Gitblit v1.8.0