From 4cf3c14e6cd5ababdc6c7fddad1726395ed083b7 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 16 三月 2021 12:21:16 +0800
Subject: [PATCH] 2021-03-16

---
 src/tabviews/custom/components/chart/antv-pie/index.jsx |   75 +++++++++++++++++++++++++++++++++++--
 1 files changed, 70 insertions(+), 5 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-pie/index.jsx b/src/tabviews/custom/components/chart/antv-pie/index.jsx
index df58e29..076dcfd 100644
--- a/src/tabviews/custom/components/chart/antv-pie/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-pie/index.jsx
@@ -5,6 +5,7 @@
 import { connect } from 'react-redux'
 import DataSet from '@antv/data-set'
 import { Spin, Empty, notification } from 'antd'
+import moment from 'moment'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -115,17 +116,78 @@
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+    this.handleTimer()
   }
 
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
    */
   componentWillUnmount () {
+    clearTimeout(this.timer)
     this.setState = () => {
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+  }
+
+  handleTimer = () => {
+    const { config } = this.state
+
+    if (!config.timer) return
+
+    const _change = {
+      '15s': 15000,
+      '30s': 30000,
+      '1min': 60000,
+      '5min': 300000,
+      '10min': 600000,
+      '15min': 900000,
+      '30min': 1800000,
+      '1hour': 3600000
+    }
+
+    let timer = _change[config.timer]
+
+    if (!timer) return
+
+    let _param = {
+      func: 's_get_timers_role',
+      LText: `select '${window.GLOB.appkey || ''}','${config.uuid}'`,
+      timer_type: config.timer,
+      component_id: config.uuid
+    }
+    
+    _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')          // 鏃堕棿鎴�
+    _param.LText = Utils.formatOptions(_param.LText)                   // 鍏抽敭瀛楃鏇挎崲锛宐ase64鍔犲瘑
+    _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)   // md5瀵嗛挜
+
+    Api.getSystemConfig(_param).then(result => {
+      if (!result.status) {
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+        return
+      } else if (result.run_type) {
+        this.setState({timer})
+        this.timer = setTimeout(() => {
+          this.timerTask()
+        }, timer)
+      }
+    })
+  }
+
+  timerTask = () => {
+    const { timer } = this.state
+    if (!timer) return
+    
+    this.loadData(true)
+    
+    this.timer = setTimeout(() => {
+      this.timerTask()
+    }, timer)
   }
 
   reloadData = (menuId) => {
@@ -155,7 +217,7 @@
     this.pierender()
   }
 
-  async loadData () {
+  async loadData (hastimer) {
     const { mainSearch, menuType } = this.props
     const { config, arr_field, search, BID } = this.state
 
@@ -178,9 +240,11 @@
       })
     }
 
-    this.setState({
-      loading: true
-    })
+    if (!hastimer) {
+      this.setState({
+        loading: true
+      })
+    }
 
     let _orderBy = config.setting.order || ''
     let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID, menuType)
@@ -195,7 +259,8 @@
       })
     } else {
       this.setState({
-        loading: false
+        loading: false,
+        timer: null
       })
       notification.error({
         top: 92,

--
Gitblit v1.8.0