From 913ea012f420311d18cc875934bae6b4ce3b2d13 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 16 一月 2023 14:44:28 +0800
Subject: [PATCH] 2023-01-16

---
 src/tabviews/custom/components/chart/antv-G6/index.jsx |   51 ++++++++++++++++++++++++++-------------------------
 1 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-G6/index.jsx b/src/tabviews/custom/components/chart/antv-G6/index.jsx
index 47db6f9..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: [],
     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,11 +860,12 @@
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
-      } else if (config.setting.sync === 'true' && _data) {
-        this.handleData()
       }
     })
 
+    if (this.data.length > 0) {
+      this.handleData()
+    }
     
     let that = this
 
@@ -1008,11 +1008,12 @@
         _data = nextProps.data[config.dataName]
       }
 
-      this.setState({sync: false, data: _data})
-
-      if (!is(fromJS(this.state.data), fromJS(_data))) {
+      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()
@@ -1031,11 +1032,12 @@
 
     if (config.$cache && (config.setting.sync !== 'true' || sync)) {
       Api.getLCacheConfig(config.uuid).then(res => {
-        if (!res) return
+        if (!res || this.data.length > 0) return
 
-        this.setState({data: res})
-
-        this.handleData()
+        if (!is(fromJS(this.data), fromJS(res))) {
+          this.data = res
+          this.handleData()
+        }
       })
     }
   }
@@ -1072,14 +1074,13 @@
 
   async loadData () {
     const { mainSearch } = this.props
-    const { config, arr_field, BID, data } = this.state
+    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
     }
 
@@ -1104,11 +1105,11 @@
       }
 
       this.setState({
-        data: result.data || [],
         loading: false
       })
 
-      if (!is(fromJS(data), fromJS(result.data || []))) {
+      if (!is(fromJS(this.data), fromJS(result.data || []))) {
+        this.data = result.data || []
         this.handleData()
       }
     } else {
@@ -1131,7 +1132,7 @@
   }
 
   getdata = () => {
-    const { plot, data, config, BData } = this.state
+    const { plot, config, BData } = this.state
     
     let root = {
       label: 'Root',
@@ -1157,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] || ''
@@ -1284,9 +1285,9 @@
   }
 
   viewrender = () => {
-    const { plot, data } = this.state
+    const { plot } = this.state
 
-    if (data.length === 0) {
+    if (this.data.length === 0) {
       this.setState({empty: true})
     } else {
       this.setState({empty: false})

--
Gitblit v1.8.0