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-scatter/index.jsx |   57 +++++++++++++++++++++++++++++++--------------------------
 1 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-scatter/index.jsx b/src/tabviews/custom/components/chart/antv-scatter/index.jsx
index a42499a..a36ef44 100644
--- a/src/tabviews/custom/components/chart/antv-scatter/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-scatter/index.jsx
@@ -33,15 +33,15 @@
     chartId: Utils.getuuid(),  // 鍥捐〃Id
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     plot: null,                // 鍥捐〃璁剧疆
-    data: [],                  // 鏁版嵁
     search: null,              // 鎼滅储鏉′欢
     chart: null
   }
 
+  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 = ''
@@ -56,11 +56,11 @@
       BID = BData.$BID || ''
     }
 
-    if (config.setting.sync === 'true' && data) {
-      _data = data[config.dataName] || []
+    if (_sync && data) {
+      this.data = data[config.dataName] || []
       _sync = false
-    } else if (config.setting.sync === 'true' && initdata) {
-      _data = initdata || []
+    } else if (_sync && initdata) {
+      this.data = initdata || []
       _sync = false
     }
 
@@ -74,9 +74,8 @@
 
     this.setState({
       config: _config,
-      data: _data || [],
       BID: BID || '',
-      empty: !_data,
+      empty: this.data.length === 0,
       arr_field: _config.columns.map(col => col.field).join(','),
       plot: _config.plot,
       sync: _sync,
@@ -86,10 +85,12 @@
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
-      } else if (config.setting.sync === 'true' && _data) {
-        this.handleData()
       }
     })
+
+    if (this.data.length > 0) {
+      this.handleData()
+    }
   }
 
   /**
@@ -104,11 +105,12 @@
         _data = nextProps.data[config.dataName] || []
       }
 
-      this.setState({sync: false, data: _data, empty: false})
-
-      if (!is(fromJS(this.state.data), fromJS(_data))) {
+      if (!is(fromJS(this.data), fromJS(_data))) {
+        this.data = _data
         this.handleData()
       }
+
+      this.setState({sync: false, empty: _data.length === 0})
     } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({}, () => {
         this.loadData()
@@ -137,11 +139,14 @@
 
     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, empty: false}, () => {
+        if (!is(fromJS(this.data), fromJS(res))) {
+          this.data = res
           this.handleData()
-        })
+        }
+
+        this.setState({empty: false})
       })
     }
   }
@@ -237,12 +242,12 @@
     const { config, arr_field, BID, search } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
-      this.setState({
-        data: [],
-        empty: false,
-      }, () => {
+      this.setState({ empty: true })
+
+      if (!is(fromJS(this.data), fromJS([]))) {
+        this.data = []
         this.handleData()
-      })
+      }
       return
     }
 
@@ -277,12 +282,12 @@
       }
       
       this.setState({
-        data: result.data || [],
-        empty: false,
+        empty: !result.data || result.data.length === 0,
         loading: false
       })
 
-      if (!is(fromJS(this.state.data), fromJS(result.data || []))) {
+      if (!is(fromJS(this.data), fromJS(result.data || []))) {
+        this.data = result.data || []
         this.handleData()
       }
     } else {
@@ -323,14 +328,14 @@
    * @description 鏁g偣鍥炬覆鏌�
    */
   scatterrender = () => {
-    const { plot, data, chartId } = this.state
+    const { plot, chartId } = this.state
     const chart = new Chart({
       container: chartId,
       autoFit: true,
       height: plot.height
     })
 
-    chart.data(data);
+    chart.data(this.data);
     chart.scale({
       [plot.Xaxis]: { nice: true },
       [plot.Yaxis]: { nice: true },

--
Gitblit v1.8.0