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-pie/index.jsx |   85 ++++++++++++++++++++++++++----------------
 1 files changed, 52 insertions(+), 33 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-pie/index.jsx b/src/tabviews/custom/components/chart/antv-pie/index.jsx
index f6893b8..216be2f 100644
--- a/src/tabviews/custom/components/chart/antv-pie/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-pie/index.jsx
@@ -32,16 +32,16 @@
     title: '',                 // 缁勪欢鏍囬
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     plot: null,                // 鍥捐〃璁剧疆
-    data: null,                // 鏁版嵁
     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
     }
 
@@ -83,7 +83,6 @@
 
     this.setState({
       config: _config,
-      data: _data,
       BID: BID || '',
       arr_field: _config.columns.map(col => col.field).join(','),
       plot: _config.plot,
@@ -95,10 +94,12 @@
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
-      } else if (config.setting.sync === 'true' && _data) {
-        this.handleData()
       }
     })
+
+    if (this.data.length > 0) {
+      this.handleData()
+    }
   }
 
   /**
@@ -113,9 +114,12 @@
         _data = nextProps.data[config.dataName] || []
       }
 
-      this.setState({sync: false, data: _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()
@@ -128,7 +132,7 @@
   }
 
   componentDidMount () {
-    const { config } = this.state
+    const { config, sync } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -137,6 +141,17 @@
       this.timer = new TimerTask()
       this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
         this.loadData(true)
+      })
+    }
+
+    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()
+        }
       })
     }
   }
@@ -174,12 +189,18 @@
   }
 
   handleData = () => {
-    const { plot, chartId } = this.state
-    
-    let _element = document.getElementById(chartId)
+    let _element = document.getElementById(this.state.chartId)
     if (_element) {
       _element.innerHTML = ''
     }
+
+    setTimeout(() => {
+      this.viewrender()
+    }, 100)
+  }
+
+  viewrender = () => {
+    const { plot } = this.state
 
     if (plot.shape === 'nest') {
       this.nestrender()
@@ -193,11 +214,10 @@
     const { config, arr_field, search, BID } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
-      this.setState({
-        data: []
-      }, () => {
+      if (!is(fromJS(this.data), fromJS([]))) {
+        this.data = []
         this.handleData()
-      })
+      }
       return
     }
 
@@ -227,19 +247,18 @@
 
     let result = await Api.genericInterface(param)
     if (result.status) {
-      let reset = true
-
-      if (hastimer && is(fromJS(result.data), fromJS(this.state.data))) {
-        reset = false
+      if (config.$cache) {
+        Api.writeCacheConfig(config.uuid, result.data || '')
       }
 
       this.setState({
-        data: result.data,
         loading: false
-      }, () => {
-        if (!reset) return
-        this.handleData()
       })
+
+      if (!is(fromJS(this.data), fromJS(result.data || []))) {
+        this.data = result.data || []
+        this.handleData()
+      }
     } else {
       this.setState({
         loading: false
@@ -267,15 +286,15 @@
    * 3銆佹煴鐘跺浘鏁版嵁琛ラ綈
    */
   getdata = () => {
-    const { data, plot } = this.state
+    const { plot } = this.state
 
-    if (!data) {
+    if (this.data.length === 0) {
       this.setState({empty: true})
       return []
     }
 
     let _data = []
-    let _cdata = fromJS(data).toJS()
+    let _cdata = fromJS(this.data).toJS()
 
     if (plot.repeat === 'average') {
       let _mdata = new Map()
@@ -360,15 +379,15 @@
   }
 
   getnestdata = () => {
-    const { data, plot } = this.state
+    const { plot } = this.state
 
-    if (!data) {
+    if (this.data.length === 0) {
       this.setState({empty: true})
       return []
     }
 
     let _data = []
-    let _cdata = fromJS(data).toJS()
+    let _cdata = fromJS(this.data).toJS()
 
     if (plot.repeat === 'average') {
       let _mdata = new Map()

--
Gitblit v1.8.0