Welcome.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { PageContainer } from '@ant-design/pro-components';
  2. import { Button, Card, Col, DatePicker, Form, Row, Space } from 'antd';
  3. import React, { useEffect, useRef, useState } from 'react';
  4. import styles from './Welcome.less';
  5. import { getStatisticData } from '@/services/statistic';
  6. import bookSum from '../../public/assets/book-sum.png';
  7. import totalOnlineNum from '../../public/icons/total_online_num.png';
  8. import activation1 from '../../public/icons/activation_1.png';
  9. import activation2 from '../../public/icons/activation_2.png';
  10. import online1 from '../../public/icons/online_1.png';
  11. import online2 from '../../public/icons/online_2.png';
  12. import { ReloadOutlined, SearchOutlined } from '@ant-design/icons';
  13. import moment from 'moment/moment';
  14. import * as echarts from 'echarts';
  15. const { RangePicker } = DatePicker;
  16. /**
  17. * 首页
  18. * @constructor
  19. */
  20. const Welcome: React.FC = () => {
  21. const [form] = Form.useForm();
  22. const [data, setData] = useState<any>(null);
  23. const [searchData, setSearchData] = useState<object | null>({});
  24. const chartRef: any = useRef();
  25. // 获取数据
  26. const getList = () => {
  27. const params = {
  28. ...searchData,
  29. };
  30. getStatisticData(params).then((res) => {
  31. if (res && res.code === 0) {
  32. setData(res.data);
  33. const chart = echarts.init(chartRef.current);
  34. const region = JSON.parse(res.data.region);
  35. const newData = Object.entries(region).map(([name, value]) => ({ value, name }));
  36. console.log(newData);
  37. const options = {
  38. tooltip: {
  39. trigger: 'item',
  40. },
  41. legend: {
  42. orient: 'vertical',
  43. left: 'left',
  44. },
  45. series: [
  46. {
  47. type: 'pie',
  48. radius: '50%',
  49. data: newData,
  50. emphasis: {
  51. itemStyle: {
  52. shadowBlur: 10,
  53. shadowOffsetX: 0,
  54. shadowColor: 'rgba(0, 0, 0, 0.5)',
  55. },
  56. },
  57. },
  58. ],
  59. };
  60. // 设置图表实例的配置项和数据
  61. chart.setOption(options);
  62. }
  63. });
  64. };
  65. // 初始化
  66. useEffect(() => {
  67. getList();
  68. }, []);
  69. useEffect(() => {
  70. getList();
  71. }, [searchData]);
  72. // 搜索
  73. const onFinish = () => {
  74. const params: any = {};
  75. form.validateFields().then((res) => {
  76. if (res.time) {
  77. params.time_start = moment(res.time[0]).format('YYYY-MM-DD');
  78. params.time_end = moment(res.time[1]).format('YYYY-MM-DD');
  79. }
  80. setSearchData(params);
  81. });
  82. };
  83. // 重置
  84. const onReset = () => {
  85. form.resetFields();
  86. setSearchData(null);
  87. };
  88. return (
  89. <PageContainer>
  90. <Card style={{ marginBottom: '20px' }}>
  91. <Form form={form} layout="inline" onFinish={onFinish}>
  92. <Form.Item name="time" label="时间">
  93. <RangePicker />
  94. </Form.Item>
  95. <Form.Item style={{ marginBottom: '10px' }}>
  96. <Space>
  97. <Button type="primary" htmlType="submit">
  98. <SearchOutlined />
  99. 查询
  100. </Button>
  101. <Button htmlType="button" onClick={onReset}>
  102. <ReloadOutlined />
  103. 重置
  104. </Button>
  105. </Space>
  106. </Form.Item>
  107. </Form>
  108. </Card>
  109. <Card className={styles.container}>
  110. <Row gutter={[30, 20]}>
  111. <Col span={5} xs={24} sm={12} md={12} lg={12} xl={5} xxl={5}>
  112. <div className={styles.itemLeft}>
  113. <span className={styles.leftTitle}>总数</span>
  114. <div className={styles.imgBox}>
  115. <img src={bookSum} alt="" />
  116. </div>
  117. <span className={styles.leftNumber}>{data?.total}</span>
  118. </div>
  119. </Col>
  120. <Col span={3} xs={24} sm={12} md={12} lg={12} xl={3} xxl={3}>
  121. <div className={styles.itemCenter}>
  122. <div className={styles.itemImg}>
  123. <img src={totalOnlineNum} alt="" />
  124. </div>
  125. <div className={styles.itemValue}>{data?.online}</div>
  126. <div className={styles.itemTitle}>总在线数</div>
  127. </div>
  128. </Col>
  129. <Col span={8} xs={24} sm={12} md={12} lg={12} xl={8} xxl={8}>
  130. <div className={styles.itemRight}>
  131. <div className={[styles.imgRightBox, styles.itemRightBg4].join(' ')}>
  132. <div className={styles.itemRightImg}>
  133. <img src={online2} alt="" />
  134. </div>
  135. <span className={styles.itemRightVal}>{data?.wuheng_online}</span>
  136. <span className={styles.itemRightTitle}>五恒在线数</span>
  137. </div>
  138. <div className={[styles.imgRightBox, styles.itemRightBg1].join(' ')}>
  139. <div className={styles.itemRightImg}>
  140. <img src={activation2} alt="" />
  141. </div>
  142. <span className={styles.itemRightVal}>{data?.wuheng}</span>
  143. <span className={styles.itemRightTitle}>激活五恒数</span>
  144. </div>
  145. <div className={[styles.imgRightBox, styles.itemRightBg3].join(' ')}>
  146. <div className={styles.itemRightImg}>
  147. <img src={online1} alt="" />
  148. </div>
  149. <span className={styles.itemRightVal}>{data?.ffx_online}</span>
  150. <span className={styles.itemRightTitle}>分风箱在线数</span>
  151. </div>
  152. <div className={[styles.imgRightBox, styles.itemRightBg2].join(' ')}>
  153. <div className={styles.itemRightImg}>
  154. <img src={activation1} alt="" />
  155. </div>
  156. <span className={styles.itemRightVal}>{data?.ffx}</span>
  157. <span className={styles.itemRightTitle}>激活分风箱数</span>
  158. </div>
  159. </div>
  160. </Col>
  161. <Col span={8} xs={24} sm={12} md={12} lg={12} xl={8} xxl={8}>
  162. <div style={{ width: '700px', height: '450px' }} ref={chartRef} />
  163. </Col>
  164. </Row>
  165. </Card>
  166. </PageContainer>
  167. );
  168. };
  169. export default Welcome;