From eb0c4703ec7cd21dc921ae113b7e3be69c641c1d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 17 九月 2021 15:18:06 +0800
Subject: [PATCH] 2021-09-17

---
 src/tabviews/custom/components/card/balcony/index.jsx |   71 +++++++++++++++++++++++++++++++++--
 1 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/src/tabviews/custom/components/card/balcony/index.jsx b/src/tabviews/custom/components/card/balcony/index.jsx
index 2842c8a..aec9138 100644
--- a/src/tabviews/custom/components/card/balcony/index.jsx
+++ b/src/tabviews/custom/components/card/balcony/index.jsx
@@ -2,8 +2,10 @@
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
 import { Spin, notification, Checkbox } from 'antd'
+import moment from 'moment'
 
 import Api from '@/api'
+import Utils from '@/utils/utils.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
@@ -111,6 +113,7 @@
     MKEmitter.addListener('syncBalconyData', this.syncBalconyData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
+    this.handleTimer()
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -118,6 +121,7 @@
   }
 
   componentWillUnmount () {
+    clearTimeout(this.timer)
     this.setState = () => {
       return
     }
@@ -148,6 +152,56 @@
 
       this.setState({sync: false, data: _data})
     }
+  }
+
+  handleTimer = () => {
+    const { config } = this.state
+
+    if (!config.timer) return
+
+    const _change = { '5s': 5000, '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)
   }
 
   /**
@@ -225,7 +279,7 @@
     this.loadData()
   }
 
-  async loadData () {
+  async loadData (hastimer) {
     const { menuType } = this.props
     const { config, arr_field, BID, BData } = this.state
 
@@ -243,9 +297,11 @@
 
     let searches = []
 
-    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, 1, 1, BID, menuType)
@@ -260,6 +316,13 @@
         data: _data,
         loading: false
       })
+
+      if (config.timer && config.clearField) {
+        let vals = (config.clearValue || '').split(',')
+        if (vals.includes(_data[config.clearField])) {
+          clearTimeout(this.timer)
+        }
+      }
     } else {
       this.setState({
         loading: false,

--
Gitblit v1.8.0