From 474c68f0fea10cc62977c67d186732b3346cdd53 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 17 一月 2023 18:04:45 +0800
Subject: [PATCH] 2023-01-17

---
 src/tabviews/custom/components/chart/antv-G6/index.jsx |  128 +++++++++++++++++++++++++-----------------
 1 files changed, 76 insertions(+), 52 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-G6/index.jsx b/src/tabviews/custom/components/chart/antv-G6/index.jsx
index 8eac201..e856a3d 100644
--- a/src/tabviews/custom/components/chart/antv-G6/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-G6/index.jsx
@@ -804,7 +804,6 @@
 
   state = {
     config: null,
-    data: null,
     BID: '',
     BData: '',
     plot: null,
@@ -814,11 +813,12 @@
     empty: true
   }
 
+  data = []
+
   UNSAFE_componentWillMount () {
     const { config, data, initdata } = this.props
     let _config = fromJS(config).toJS()
 
-    let _data = null
     let _sync = _config.setting.sync === 'true'
 
     let BID = ''
@@ -834,10 +834,10 @@
     }
 
     if (_sync && data) {
-      _data = data[config.dataName] || []
+      this.data = data[config.dataName] || []
       _sync = false
     } else if (_sync && initdata) {
-      _data = initdata || []
+      this.data = initdata || []
       _sync = false
     }
 
@@ -850,7 +850,6 @@
 
     this.setState({
       config: _config,
-      data: _data,
       BID: BID || '',
       BData: BData || '',
       arr_field: _config.columns.map(col => col.field).join(','),
@@ -861,44 +860,13 @@
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
-      } else if (config.setting.sync === 'true' && _data) {
-        this.handleData()
       }
     })
-  }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, 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]
-      }
-
-      this.setState({sync: false, data: _data}, () => {
-        this.handleData()
-      })
-    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({}, () => {
-        this.loadData()
-      })
+    if (this.data.length > 0) {
+      this.handleData()
     }
-  }
-
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.state), fromJS(nextState))
-  }
-
-  componentDidMount () {
-    const { config } = this.state
-    MKEmitter.addListener('reloadData', this.reloadData)
-    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
-
+    
     let that = this
 
     if (config.plot.subtype === 'mindmap') {
@@ -1028,6 +996,53 @@
   }
 
   /**
+   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
+   */
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { sync, 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 (!is(fromJS(this.data), fromJS(_data))) {
+        this.data = _data
+        this.handleData()
+      }
+
+      this.setState({sync: false})
+    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+      this.setState({}, () => {
+        this.loadData()
+      })
+    }
+  }
+
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  componentDidMount () {
+    const { config, sync } = this.state
+    MKEmitter.addListener('reloadData', this.reloadData)
+    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+
+    if (config.$cache && (config.setting.sync !== 'true' || sync)) {
+      Api.getLCacheConfig(config.uuid).then(res => {
+        if (!res || this.data.length > 0) return
+
+        if (!is(fromJS(this.data), fromJS(res))) {
+          this.data = res
+          this.handleData()
+        }
+      })
+    }
+  }
+
+  /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
    */
   componentWillUnmount () {
@@ -1062,11 +1077,10 @@
     const { config, arr_field, BID } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
-      this.setState({
-        data: {}
-      }, () => {
+      if (!is(fromJS(this.data), fromJS([]))) {
+        this.data = []
         this.handleData()
-      })
+      }
       return
     }
 
@@ -1086,14 +1100,18 @@
 
     let result = await Api.genericInterface(param)
     if (result.status) {
-      let data = result.data || []
+      if (config.$cache) {
+        Api.writeCacheConfig(config.uuid, result.data || '')
+      }
 
       this.setState({
-        data,
         loading: false
-      }, () => {
-        this.handleData()
       })
+
+      if (!is(fromJS(this.data), fromJS(result.data || []))) {
+        this.data = result.data || []
+        this.handleData()
+      }
     } else {
       this.setState({
         loading: false
@@ -1114,7 +1132,7 @@
   }
 
   getdata = () => {
-    const { plot, data, config, BData } = this.state
+    const { plot, config, BData } = this.state
     
     let root = {
       label: 'Root',
@@ -1140,7 +1158,7 @@
     let _options = []
     let logMap = new Map()
 
-    data.forEach(item => {
+    this.data.forEach(item => {
       let pval = item[plot.parentField]
       let val = item[plot.valueField]
       let label = item[plot.labelField] || ''
@@ -1256,14 +1274,20 @@
   }
 
   handleData = () => {
-    const { plot, data } = this.state
-
     let _element = document.getElementById(this.state.chartId)
     if (_element) {
       _element.innerHTML = ''
     }
 
-    if (!data || data.length === 0) {
+    setTimeout(() => {
+      this.viewrender()
+    }, 100)
+  }
+
+  viewrender = () => {
+    const { plot } = this.state
+
+    if (this.data.length === 0) {
       this.setState({empty: true})
     } else {
       this.setState({empty: false})

--
Gitblit v1.8.0