Monitor.js 6.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Row, Col, Card } from 'antd';
import numeral from 'numeral';

import { NumberInfo, MiniArea, Pie, WaterWave, Gauge } from '../../components/Charts';
import MapChart from '../../components/MapChart';
import TagCloud from '../../components/TagCloud';
import Countdown from '../../components/Countdown';
import { fixedZero } from '../../utils/utils';

import styles from './Monitor.less';

nikogu's avatar
nikogu committed
14 15 16 17 18 19 20 21 22
function getActiveData() {
  const activeData = [];
  for (let i = 0; i < 24; i += 1) {
    activeData.push({
      x: `${fixedZero(i)}:00`,
      y: (i * 50) + (Math.floor(Math.random() * 200)),
    });
  }
  return activeData;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
}

const MapData = [];
for (let i = 0; i < 50; i += 1) {
  MapData.push({
    x: Math.floor(Math.random() * 600),
    y: Math.floor(Math.random() * 400),
    value: Math.floor(Math.random() * 1000) + 500,
  });
}
const targetTime = new Date().getTime() + 3900000;

@connect(state => ({
  monitor: state.monitor,
}))
export default class Monitor extends PureComponent {
nikogu's avatar
nikogu committed
39 40 41 42
  state = {
    activeData: getActiveData(),
  }

43 44 45 46 47
  componentDidMount() {
    this.props.dispatch({
      type: 'monitor/fetchTags',
    });

nikogu's avatar
nikogu committed
48 49 50 51 52 53
    setInterval(() => {
      this.setState({
        activeData: getActiveData(),
      });
    }, 1000);
  }
54
  render() {
nikogu's avatar
nikogu committed
55
    const { activeData = [] } = this.state;
56 57 58 59
    const { monitor } = this.props;
    const { tags } = monitor;

    return (
60
      <div>
61 62
        <Row gutter={24}>
          <Col lg={16} md={24} sm={24} xs={24} style={{ marginBottom: 24 }}>
63
            <Card title="活动实时交易情况" bordered={false}>
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
              <Row>
                <Col sm={6} xs={12}>
                  <NumberInfo
                    subTitle="今日交易总额"
                    total={numeral(124543233).format('0,0')}
                  />
                </Col>
                <Col sm={6} xs={12}>
                  <NumberInfo
                    subTitle="销售目标完成率"
                    total="92%"
                  />
                </Col>
                <Col sm={6} xs={12}>
                  <NumberInfo
                    subTitle="活动剩余时间"
                    total={<Countdown target={targetTime} />}
                  />
                </Col>
                <Col sm={6} xs={12}>
                  <NumberInfo
                    subTitle="每秒交易总额"
                    total={numeral(234).format('0,0')}
                  />
                </Col>
              </Row>
              <div className={styles.mapChart}>
                <MapChart
                  data={MapData}
                />
              </div>
            </Card>
          </Col>
          <Col lg={8} md={24} sm={24} xs={24}>
98
            <Card title="活动情况预测" style={{ marginBottom: 24 }} bordered={false}>
99 100 101 102 103 104 105
              <div className={styles.activeChart}>
                <NumberInfo
                  subTitle="目标评估"
                  total="有望达到预期"
                />
                <div style={{ marginTop: 32 }}>
                  <MiniArea
nikogu's avatar
nikogu committed
106
                    animate={false}
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
                    line
                    color="#5DD1DD"
                    height={84}
                    yAxis={{
                      tickCount: 3,
                      tickLine: false,
                      labels: false,
                      title: false,
                      line: false,
                    }}
                    data={activeData}
                  />
                </div>
                {
                  activeData && (
                    <div className={styles.activeChartGrid}>
                      <p>{[...activeData].sort()[activeData.length - 1].y + 200} 亿元</p>
                      <p>{[...activeData].sort()[Math.floor(activeData.length / 2)].y} 亿元</p>
                    </div>
                  )
                }
                {
                  activeData && (
                    <div className={styles.activeChartLegend}>
                      <span>00:00</span>
                      <span>{activeData[Math.floor(activeData.length / 2)].x}</span>
                      <span>{activeData[activeData.length - 1].x}</span>
                    </div>
                  )
                }
              </div>
            </Card>
139 140 141 142 143 144
            <Card
              title="券核效率"
              style={{ marginBottom: 24 }}
              bodyStyle={{ textAlign: 'center' }}
              bordered={false}
            >
145
              <Gauge
nikogu's avatar
nikogu committed
146
                title="核销率"
147 148 149 150 151 152 153 154
                height={164}
                percent={87}
              />
            </Card>
          </Col>
        </Row>
        <Row gutter={24}>
          <Col sm={8} xs={24}>
155 156 157 158 159
            <Card
              title="各品类占比"
              style={{ marginBottom: 24 }}
              bordered={false}
            >
nikogu's avatar
nikogu committed
160
              <Row gutter={4} style={{ padding: '18px 0 19px 0' }}>
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
                <Col span={8}>
                  <Pie
                    percent={28}
                    subTitle="中式快餐"
                    total="28%"
                    height={129}
                  />
                </Col>
                <Col span={8}>
                  <Pie
                    color="#5DD1DD"
                    percent={22}
                    subTitle="西餐"
                    total="22%"
                    height={129}
                  />
                </Col>
                <Col span={8}>
                  <Pie
                    color="#B5EDC9"
                    percent={32}
                    subTitle="火锅"
                    total="32%"
                    height={129}
                  />
                </Col>
              </Row>
            </Card>
          </Col>
          <Col sm={8} xs={24} style={{ marginBottom: 24 }}>
nikogu's avatar
nikogu committed
191
            <Card title="热门搜索" bordered={false} bodyStyle={{ height: 214 }}>
192 193 194 195 196 197 198
              <TagCloud
                data={tags}
                height={161}
              />
            </Card>
          </Col>
          <Col sm={8} xs={24} style={{ marginBottom: 24 }}>
199
            <Card title="资源剩余" bodyStyle={{ textAlign: 'center' }} bordered={false}>
200 201 202 203 204 205 206 207
              <WaterWave
                height={161}
                title="补贴资金剩余"
                percent={34}
              />
            </Card>
          </Col>
        </Row>
208
      </div>
209 210 211
    );
  }
}