From 004176924ce35c96600f5c18e85478944de8bec6 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 14 一月 2023 16:46:50 +0800
Subject: [PATCH] 2023-01-14

---
 src/tabviews/custom/components/chart/custom-chart/index.jsx |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/src/tabviews/custom/components/chart/custom-chart/index.jsx b/src/tabviews/custom/components/chart/custom-chart/index.jsx
index a3f4b6d..cf9f887 100644
--- a/src/tabviews/custom/components/chart/custom-chart/index.jsx
+++ b/src/tabviews/custom/components/chart/custom-chart/index.jsx
@@ -28,7 +28,7 @@
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     plot: null,                // 鍥捐〃璁剧疆
-    data: null,                // 鏁版嵁
+    data: [],                  // 鏁版嵁
     search: null,              // 鎼滅储鏉′欢
   }
 
@@ -63,7 +63,7 @@
 
     this.setState({
       config: _config,
-      data: _data,
+      data: _data || [],
       empty: !_data || _data.length === 0,
       BID: BID || '',
       arr_field: _config.columns.map(col => col.field).join(','),
@@ -93,9 +93,11 @@
         _data = nextProps.data[config.dataName] || []
       }
 
-      this.setState({sync: false, data: _data, empty: _data.length === 0}, () => {
+      this.setState({sync: false, data: _data, empty: _data.length === 0})
+
+      if (!is(fromJS(this.state.data), fromJS(_data))) {
         this.handleData()
-      })
+      }
     } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({}, () => {
         this.loadData()
@@ -108,7 +110,7 @@
   }
 
   componentDidMount () {
-    const { config } = this.state
+    const { config, sync } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -119,6 +121,16 @@
       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) return
+
+        this.setState({data: res, empty: false}, () => {
+          this.handleData()
+        })
       })
     }
   }
@@ -248,20 +260,19 @@
 
     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,
         empty: result.data.length === 0
-      }, () => {
-        if (!reset) return
-        this.handleData()
       })
+
+      if (!is(fromJS(this.state.data), fromJS(result.data || []))) {
+        this.handleData()
+      }
     } else {
       this.setState({
         loading: false
@@ -287,7 +298,7 @@
     
     setTimeout(() => {
       this.viewrender()
-    }, 150)
+    }, 100)
   }
 
   /**

--
Gitblit v1.8.0