// 核心库 import React from 'react' import { connect } from 'dva' // 组件库 import { Form, Radio, Row, Col, Collapse } from 'antd' import { IFComponent, LayoutCard } from '@woowalker/feui' import CommonChart from '../../Chart/CommonChart' // 工具库 import moment from 'moment' // 样式 import styles from './index.css' const { Panel } = Collapse class EmAppRealTimePage extends React.Component { constructor (props) { super(props) this.state = { data: [], realData: [], showData: [], chartData: {}, heartbertData: [], num: 1, time: moment().add(-6, 'hour').format('YYYY-MM-DD HH:mm:ss') + "," + moment().format('YYYY-MM-DD HH:mm:ss') } this.timer = -1 this._unmounted = false } componentDidMount () { this.getRealTimeData() this.getChartData() } componentWillUnmount () { this._unmounted = true clearTimeout(this.timer) } getRealTimeData = () => { const json = { OrgId: this.props.login.OrgId, Parameter1: this.props.formParam.Parameter1, Parameter2: this.props.login.userId, Parameter3: this.props.data.id, Parameter4: this.props.data.isNode, } this.props.dispatch({ type: 'app/getDataByPost', url: 'EM/Monitoring/GetAppRealTimeData', payload: json }).then(res => { res && !this._unmounted && this.setState({ data: res.Data, realData: res.realData, showData: res.showData, heartbertData: res.heartbertData }) }).finally(() => { if (!this._unmounted) { // 一个接口请求完之后,再定时进行请求 clearTimeout(this.timer) this.timer = setTimeout(this.getRealTimeData, 5000) } }) } getChartData = () => { this.props.dispatch({ type: 'app/getDataByPost', url: 'EM/Monitoring/GetVarIdByApp', payload: { OrgId: this.props.login.OrgId, Parameter3: this.props.data.id, Parameter4: this.props.data.isNode } }).then(res => { if (res) { this.props.dispatch({ type: 'app/getDataByPost', url: 'FM/FMSrcTag/GetchartPageApiEntities', payload: { OrgId: this.props.login.OrgId, Parameter1: this.state.time, Keyword: res } }).then(response => { if (response) { this.setState({ chartData: { xAxis: response.XAxis[0].Data, yAxis: response.YAxis, data: response.Data } }) } }) } }) } handleChange = (e) => { let time = '' const num = e.target.value switch (num) { case 1: time = moment().add(-6, 'hour').format('YYYY-MM-DD HH:mm:ss') + "," + moment().format('YYYY-MM-DD HH:mm:ss') break case 2: time = moment().add(-12, 'hour').format('YYYY-MM-DD HH:mm:ss') + "," + moment().format('YYYY-MM-DD HH:mm:ss') break case 3: time = moment().add(-1, 'day').format('YYYY-MM-DD HH:mm:ss') + "," + moment().format('YYYY-MM-DD HH:mm:ss') break default: break } this.setState({ num, time }, this.getChartData) } render () { let bg_class = styles.electric_bg let status_class = styles.electric_status let curr_class = styles.electric_curr let sum_class = styles.electric_sum switch (this.props.formParam.Parameter1) { case 'Water': bg_class = styles.water_bg status_class = styles.water_status curr_class = styles.water_curr sum_class = styles.water_sum break case 'Hot': bg_class = styles.hot_bg status_class = styles.hot_status curr_class = styles.hot_curr sum_class = styles.hot_sum break case 'Gas': bg_class = styles.gas_bg status_class = styles.gas_status curr_class = styles.gas_curr sum_class = styles.gas_sum break default: break } const { data, realData, chartData, showData } = this.state return (
{ data.map(item => { const color = item.State === 0 ? '#a4abb6' : item.State === 1 ? '#70b603' : '#d9001b' return (
{item.VarName}({item.Unit}) {item.Value}
{ showData.map((attr, attrIndex) => { const value = `${attr.Value}${attr.Unit === 'None' || attr.Unit === null ? '' : attr.Unit}` return

{`${attr.Name}:${value}`}

}) }

{item.ApplianceName}

{item.NodeName}

) }) }
过去六小时 过去十二小时 过去二十四小时 `${item.Name}_${index}`)} style={{ marginTop: '0.15rem' }} > { realData.map((item, index) => { return (
{ item.Items.map((attr, attrIndex) => { const value = `${attr.Value}${attr.Unit === 'None' || attr.Unit === null ? '' : attr.Unit}` return ( {attr.Name}
} style={{ marginBottom: 0 }} >
{value}
) }) }
) }) }
) } } export default connect(({ login }) => ({ login }))(EmAppRealTimePage)