PortalTraffic.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React from "react";
  2. import { Spin } from "antd";
  3. import { connect } from "dva";
  4. import RadioButtonGroup from "./RadioButtonGroup";
  5. import TrafficLineChart from "./TrafficLineChart";
  6. import PanelNav from "./PanelNav";
  7. import styles from "../styles/portal_traffic.less";
  8. import { color } from "echarts";
  9. const relation = {
  10. viewNumList: {
  11. name: "海外门户浏览量",
  12. color: "#7ECEF4",
  13. index: "viewNum",
  14. },
  15. visitorNumList: {
  16. name: "海外门户访客数",
  17. color: "#036EB8",
  18. index: "visitorNum",
  19. },
  20. viewNumCNList: {
  21. name: "分销门户浏览量",
  22. color: "#004E9D",
  23. index: "viewNum",
  24. },
  25. visitorNumCNList: {
  26. name: "分销门户访客数",
  27. color: "#4032A6",
  28. index: "visitorNum",
  29. },
  30. };
  31. const PortalTraffic = ({ data, options, current, loading, dispatch }) => {
  32. const onChange = (val) => {
  33. dispatch({
  34. type: "bigscreen/setPortalTrafficData",
  35. payload: { current: val },
  36. });
  37. dispatch({
  38. type: "bigscreen/load_portal_traffic",
  39. });
  40. };
  41. const parseTrafficData = (lineData) => {
  42. const legendData = [];
  43. let xAxisData = [];
  44. const seriesData = [];
  45. Object.keys(relation).forEach((key) => {
  46. if (lineData[key]) {
  47. legendData.push(relation[key].name);
  48. xAxisData = lineData[key].map((item) => item.statsTime);
  49. seriesData.push({
  50. name: relation[key].name,
  51. type: "line",
  52. smooth: false,
  53. showSymbol: true,
  54. symbolSize: 10,
  55. symbol: "circle",
  56. itemStyle: { color: relation[key].color },
  57. lineStyle: { width: 2 },
  58. data: lineData[key].map((item) => item[relation[key].index]),
  59. });
  60. }
  61. });
  62. return {
  63. legendData,
  64. xAxisData,
  65. seriesData,
  66. };
  67. };
  68. return (
  69. <div className={styles.traffic}>
  70. <div className={styles.traffic_header}>
  71. <PanelNav title="门户流量" />
  72. <div className={styles.traffic_header_conditions}>
  73. <RadioButtonGroup
  74. options={options}
  75. label={current}
  76. onChange={onChange}
  77. />
  78. </div>
  79. </div>
  80. <div className={styles.traffic_content}>
  81. <TrafficLineChart {...parseTrafficData(data)} />
  82. </div>
  83. </div>
  84. );
  85. };
  86. export default connect(({ bigscreen }) => ({
  87. data: bigscreen.portalTrafficData.data,
  88. options: bigscreen.portalTrafficData.options,
  89. current: bigscreen.portalTrafficData.current,
  90. loading: bigscreen.portalTrafficData.loading,
  91. }))(PortalTraffic);