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/card/prop-card/index.jsx | 81 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/tabviews/custom/components/card/prop-card/index.jsx b/src/tabviews/custom/components/card/prop-card/index.jsx index bce3459..555429a 100644 --- a/src/tabviews/custom/components/card/prop-card/index.jsx +++ b/src/tabviews/custom/components/card/prop-card/index.jsx @@ -3,10 +3,12 @@ import { is, fromJS } from 'immutable' import { connect } from 'react-redux' import { Spin, notification, Col } from 'antd' +import moment from 'moment' -import asyncComponent from '@/utils/asyncComponent' 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' import { modifyTabview } from '@/store/action' import './index.scss' @@ -29,7 +31,8 @@ loading: false, // 鏁版嵁鍔犺浇鐘舵�� activeKey: '', // 閫変腑鏁版嵁 sync: false, // 鏄惁缁熶竴璇锋眰鏁版嵁 - data: {} // 鏁版嵁 + data: {}, // 鏁版嵁 + timer: null // 瀹氭椂鍣ㄦ椂闂撮棿闅� } UNSAFE_componentWillMount () { @@ -111,6 +114,7 @@ MKEmitter.addListener('reloadData', this.reloadData) MKEmitter.addListener('resetSelectLine', this.resetParentParam) MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult) + this.handleTimer() } shouldComponentUpdate (nextProps, nextState) { @@ -118,6 +122,7 @@ } componentWillUnmount () { + clearTimeout(this.timer) this.setState = () => { return } @@ -153,6 +158,65 @@ }) } } + } + + 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) } /** @@ -199,7 +263,7 @@ this.loadData() } - async loadData () { + async loadData (hastimer) { const { mainSearch, menuType } = this.props const { config, arr_field, BID } = this.state @@ -227,9 +291,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, 1, 1, BID, menuType) @@ -246,7 +312,8 @@ }) } else { this.setState({ - loading: false + loading: false, + timer: null }) notification.error({ top: 92, -- Gitblit v1.8.0