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/timeline/normal-timeline/index.jsx |  133 ++++++++++++++++++++++---------------------
 1 files changed, 68 insertions(+), 65 deletions(-)

diff --git a/src/tabviews/custom/components/timeline/normal-timeline/index.jsx b/src/tabviews/custom/components/timeline/normal-timeline/index.jsx
index 2690fad..0d92eb1 100644
--- a/src/tabviews/custom/components/timeline/normal-timeline/index.jsx
+++ b/src/tabviews/custom/components/timeline/normal-timeline/index.jsx
@@ -16,16 +16,13 @@
 
 class NormalTimeline 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: null,                // 鏁版嵁
     BData: '',
     card: null,
@@ -36,16 +33,13 @@
 
   /**
    * @description 鍒濆鍖栧鐞�
-   * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
    */
   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 = null
     let card = null
-    let _sync = _config.setting.sync === 'true'
-
     let BID = ''
     let BData = ''
 
@@ -58,16 +52,15 @@
       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 (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
+      _data = window.GLOB.SyncData.get(_config.dataName) || []
 
-    if (_data) {
-      this.loaded = true
+      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] || ''
@@ -76,6 +69,10 @@
         item.$Index = index + 1 + ''
         return item
       })
+
+      this.loaded = true
+
+      window.GLOB.SyncData.delete(_config.dataName)
     }
 
     _config.search = []
@@ -94,14 +91,13 @@
 
     this.setState({
       card,
-      sync: _sync,
       BID: BID || '',
       BData: BData || '',
       data: _data,
       config: _config,
       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)
@@ -113,10 +109,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()
@@ -149,43 +153,55 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
+    MKEmitter.removeListener('refreshLineData', this.refreshLineData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
-    MKEmitter.removeListener('refreshLineData', this.refreshLineData)
+    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
+  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()
+    })
   }
 
   /**
@@ -246,19 +262,13 @@
    * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
   queryModuleParam = (menuId, callback) => {
-    const { mainSearch } = this.props
     const { arr_field, config } = this.state
 
     if (config.uuid !== menuId) return
 
     let searches = []
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key.toLowerCase())
-      mainSearch.forEach(item => {
-        if (!keys.includes(item.key.toLowerCase())) {
-          searches.push(item)
-        }
-      })
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      searches = window.GLOB.SearchBox.get(config.$searchId) || []
     }
 
     callback({
@@ -270,7 +280,6 @@
   }
 
   async loadData (hastimer) {
-    const { mainSearch } = this.props
     const { config, arr_field, BID, BData } = this.state
     
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -288,17 +297,11 @@
     }
 
     let searches = []
-    if (config.setting.useMSearch && mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key)
-      mainSearch.forEach(item => {
-        if (!keys.includes(item.key)) {
-          searches.push(item)
-        }
-      })
+    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
     }
 
@@ -315,7 +318,7 @@
     if (result.status) {
       this.loaded = true
       if (config.$cache && config.setting.onload !== 'false') {
-        Api.writeCacheConfig(config.uuid, result.data || '')
+        Api.writeCacheConfig(config.uuid, result.data || [])
       }
 
       let data = result.data.map((item, index) => {

--
Gitblit v1.8.0