mock平台

StatisChart.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Created by gxl.gao on 2017/10/25.
  3. */
  4. import React, { Component } from 'react';
  5. // import PropTypes from 'prop-types'
  6. import axios from 'axios';
  7. import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
  8. import { Spin } from 'antd';
  9. class StatisChart extends Component {
  10. static propTypes = {};
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. showLoading: true,
  15. chartDate: {
  16. mockCount: 0,
  17. mockDateList: []
  18. }
  19. };
  20. }
  21. componentWillMount() {
  22. this.getMockData();
  23. }
  24. // 获取mock 请求次数信息
  25. async getMockData() {
  26. let result = await axios.get('/api/plugin/statismock/get');
  27. if (result.data.errcode === 0) {
  28. let mockStatisData = result.data.data;
  29. this.setState({
  30. showLoading: false,
  31. chartDate: { ...mockStatisData }
  32. });
  33. }
  34. }
  35. render() {
  36. const width = 1050;
  37. const { mockCount, mockDateList } = this.state.chartDate;
  38. return (
  39. <div>
  40. <Spin spinning={this.state.showLoading}>
  41. <div className="statis-chart-content">
  42. <h3 className="statis-title">mock 接口访问总数为:{mockCount.toLocaleString()}</h3>
  43. <div className="statis-chart">
  44. <LineChart
  45. width={width}
  46. height={300}
  47. data={mockDateList}
  48. margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
  49. >
  50. <XAxis dataKey="_id" />
  51. <YAxis />
  52. <CartesianGrid strokeDasharray="7 3" />
  53. <Tooltip />
  54. <Legend />
  55. <Line
  56. name="mock统计值"
  57. type="monotone"
  58. dataKey="count"
  59. stroke="#8884d8"
  60. activeDot={{ r: 8 }}
  61. />
  62. </LineChart>
  63. </div>
  64. <div className="statis-footer">过去3个月mock接口调用情况</div>
  65. </div>
  66. </Spin>
  67. </div>
  68. );
  69. }
  70. }
  71. export default StatisChart;