index.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. import React, { Suspense, useEffect, useState } from 'react';
  2. import styles from './index.less';
  3. import * as datav from '@jiaminghi/data-view-react';
  4. import dataBoardTitle from '../../../public/assets/dataBoardTitle.png';
  5. import decoration_three from '../../../public/assets/decoration_three.png';
  6. import decoration_five from '../../../public/assets/decoration_five.png';
  7. import border from '../../../public/assets/border.png';
  8. import dataBoardBg_two from '../../../public/assets/dataBoardBg_two.png';
  9. import Slider from 'react-slick';
  10. import 'slick-carousel/slick/slick.css';
  11. import 'slick-carousel/slick/slick-theme.css';
  12. import {
  13. queryAreaData,
  14. queryDeviceChart,
  15. queryDeviceData,
  16. queryDeviceRunTime,
  17. queryHomeInfo,
  18. queryUserChart,
  19. queryUserData,
  20. } from '@/services/dataBoardService';
  21. import PreloadImage from '@/components/PreloadImage';
  22. import { DoubleRightOutlined } from '@ant-design/icons';
  23. const LineChartsCommon = React.lazy(() => import('@/pages/DataBoard/lineChartsCommon'));
  24. const MapComponent = React.lazy(() => import('@/pages/DataBoard/mapComponent'));
  25. const AreaDeviceData = React.lazy(() => import('@/pages/DataBoard/areaDeviceData'));
  26. const SliderData = React.lazy(() => import('@/pages/DataBoard/sliderData'));
  27. // 数据大屏
  28. const DataBoard: React.FC = () => {
  29. const [deviceTypeValue, setDeviceTypeValue] = useState(1);
  30. const [userTypeValue, setUserTypeValue] = useState(1);
  31. const [userNum, setUserNum] = useState({
  32. number: [0],
  33. content: '{nt}',
  34. style: {
  35. fontSize: 28,
  36. fill: '#2ff8ff',
  37. },
  38. });
  39. const [homeNum, setHomeNum] = useState({
  40. number: [0],
  41. content: '{nt}',
  42. style: {
  43. fontSize: 28,
  44. fill: '#2ff8ff',
  45. },
  46. });
  47. const [onlineDeviceNum, setOnlineDeviceNum] = useState({
  48. number: [0],
  49. content: '{nt}',
  50. style: {
  51. fontSize: 20,
  52. fill: '#2ff8ff',
  53. },
  54. });
  55. const [offlineDeviceNum, setOfflineDeviceNum] = useState({
  56. number: [0],
  57. content: '{nt}',
  58. style: {
  59. fontSize: 20,
  60. fill: '#2ff8ff',
  61. },
  62. });
  63. const [deviceNum, setDeviceNum] = useState({
  64. number: [0],
  65. content: '{nt}',
  66. style: {
  67. fontSize: 20,
  68. fill: '#2ff8ff',
  69. },
  70. });
  71. const [errorDeviceNum, setErrorDeviceNum] = useState({
  72. number: [0],
  73. content: '{nt}',
  74. style: {
  75. fontSize: 20,
  76. fill: '#2ff8ff',
  77. },
  78. });
  79. const [masterControlNum, setMasterControlNum] = useState({
  80. number: [0],
  81. content: '{nt}',
  82. style: {
  83. fontSize: 20,
  84. fill: '#2ff8ff',
  85. },
  86. });
  87. const [subControlNum, setSubControlNum] = useState({
  88. number: [0],
  89. content: '{nt}',
  90. style: {
  91. fontSize: 20,
  92. fill: '#2ff8ff',
  93. },
  94. });
  95. const [deviceStatistics, setDeviceStatistics] = useState({
  96. number: [0],
  97. content: '{nt}',
  98. style: {
  99. fontSize: 33,
  100. fill: '#08c7f1',
  101. },
  102. });
  103. const [allRunTime, setAllRunTime] = useState({
  104. number: [0],
  105. content: '{nt}',
  106. toFixed: 2,
  107. style: {
  108. fontSize: 33,
  109. fill: '#ffb026',
  110. },
  111. });
  112. const [todayRunTime, setTodayRunTime] = useState({
  113. number: [0],
  114. content: '{nt}',
  115. toFixed: 2,
  116. style: {
  117. fontSize: 33,
  118. fill: '#0dde79',
  119. },
  120. });
  121. const [homeInfo, setHomeInfo] = useState([]);
  122. const [userChartsData, setUserChartsData] = useState([]);
  123. const [deviceChartsData, setDeviceChartsData] = useState([]);
  124. const [areaDeviceList, setAreaDeviceList] = useState([]);
  125. const settings = {
  126. dots: false, //圆点显示(false隐藏)
  127. infinite: true, //无限的环绕内容
  128. autoplay: true, //自动播放,速度默认为(3000毫秒)
  129. speed: 3000, //自动播放速度(毫秒)
  130. slidesToShow: 2, //在一帧中显示2张卡片
  131. slidesToScroll: 1, //一次滚动2张卡片
  132. variableWidth: true,
  133. };
  134. // 设备统计
  135. const getDeviceData = () => {
  136. queryDeviceData().then((res) => {
  137. if (res?.code === 0) {
  138. // 设备数
  139. setDeviceNum((data) => {
  140. data.number = [90];
  141. return { ...data };
  142. });
  143. // 故障设备数
  144. setErrorDeviceNum((data) => {
  145. data.number = [res.data.failure_device];
  146. return { ...data };
  147. });
  148. // 主控数量
  149. setMasterControlNum((data) => {
  150. // data.number = [res.data.master_count];
  151. data.number = [90]; // 假数据 回头删
  152. return { ...data };
  153. });
  154. // 分控数量
  155. setSubControlNum((data) => {
  156. // data.number = [res.data.sub_count];
  157. data.number = [90 * 3]; // 假数据 回头删
  158. return { ...data };
  159. });
  160. // 设备数统计
  161. setDeviceStatistics((data) => {
  162. data.number = [90]; // 假数据 回头删
  163. return { ...data };
  164. });
  165. }
  166. });
  167. };
  168. // 用户数据统计
  169. const userNumData = () => {
  170. queryUserData().then((res) => {
  171. if (res?.code === 0) {
  172. // 注册用户数
  173. setUserNum((data) => {
  174. data.number = [res.data.user_count * 2]; // 假数据 回头删
  175. return { ...data };
  176. });
  177. // 家庭数量
  178. setHomeNum((data) => {
  179. // data.number = [res.data.home_count];
  180. data.number = [108]; // 假数据 回头删
  181. return { ...data };
  182. });
  183. // 在线设备数
  184. setOnlineDeviceNum((data) => {
  185. // data.number = [res.data.device_online];
  186. data.number = [90];
  187. return { ...data };
  188. });
  189. // 离线设备数
  190. setOfflineDeviceNum((data) => {
  191. // data.number = [res.data.device_offline];
  192. data.number = [0];
  193. return { ...data };
  194. });
  195. }
  196. });
  197. };
  198. // 设备运行时长统计
  199. const getRunTime = () => {
  200. queryDeviceRunTime().then((res) => {
  201. if (res.code === 0) {
  202. setAllRunTime((data) => {
  203. data.number = [res.data.total_run_time * 2.2];
  204. return { ...data };
  205. });
  206. setTodayRunTime((data) => {
  207. data.number = [res.data.day_run_time];
  208. return { ...data };
  209. });
  210. }
  211. });
  212. };
  213. //地区设备数量Top5
  214. const getAreaData = () => {
  215. queryAreaData({ region_type: '1' }).then((res) => {
  216. if (res?.code === 0) {
  217. // 假数据 回头删
  218. const arr: any = [
  219. {
  220. name: '济南',
  221. value: 22,
  222. },
  223. {
  224. name: '菏泽',
  225. value: 15,
  226. },
  227. {
  228. name: '泰安',
  229. value: 11,
  230. },
  231. {
  232. name: '济宁',
  233. value: 9,
  234. },
  235. {
  236. name: '潍坊',
  237. value: 9,
  238. },
  239. ];
  240. setAreaDeviceList(arr);
  241. }
  242. });
  243. };
  244. // 设备增长趋势
  245. const deviceCharts = () => {
  246. queryDeviceChart({ time_type: deviceTypeValue }).then((res) => {
  247. if (res?.code === 0) {
  248. // 假数据 回头删
  249. const arr = res.data;
  250. for (let i = 0; i < arr.length; i++) {
  251. arr[i].value = arr[i].value * 9;
  252. }
  253. setDeviceChartsData(res.data);
  254. }
  255. });
  256. };
  257. // 用户增长趋势
  258. const userCharts = () => {
  259. queryUserChart({ time_type: userTypeValue }).then((res) => {
  260. if (res?.code === 0) {
  261. // 假数据 回头删
  262. const arr = res.data;
  263. for (let i = 0; i < arr.length; i++) {
  264. arr[i].value = arr[i].value * 2;
  265. }
  266. setUserChartsData(res.data);
  267. }
  268. });
  269. };
  270. // 查询家列表
  271. const getHomeListInfo = () => {
  272. queryHomeInfo().then((res) => {
  273. if (res.code === 0) {
  274. setHomeInfo(res.data);
  275. }
  276. });
  277. };
  278. const timerFun = (callback: () => void, interval: number | undefined) => {
  279. let timer: any = setTimeout(() => {
  280. callback();
  281. clearTimeout(timer);
  282. timer = null;
  283. timerFun(callback, interval);
  284. }, interval);
  285. };
  286. useEffect(() => {
  287. // 组件挂载时立即获取一次数据
  288. getAreaData();
  289. userNumData();
  290. getDeviceData();
  291. getRunTime();
  292. deviceCharts();
  293. userCharts();
  294. getHomeListInfo();
  295. timerFun(() => {
  296. getAreaData();
  297. userNumData();
  298. getDeviceData();
  299. }, 30 * 60 * 1000); // 30分钟
  300. timerFun(() => {
  301. getRunTime();
  302. }, 1000 * 60 * 10); // 10分钟
  303. return () => {};
  304. }, []);
  305. // 设备增长趋势切换
  306. useEffect(() => {
  307. const timerId = setTimeout(() => {
  308. setDeviceTypeValue((prevValue) => (prevValue === 1 ? 2 : 1));
  309. deviceCharts();
  310. }, 1000 * 60 * 10); // 10分钟
  311. return () => {
  312. clearTimeout(timerId);
  313. };
  314. }, [deviceTypeValue]);
  315. // 用户增长趋势切换
  316. useEffect(() => {
  317. const timerId = setTimeout(() => {
  318. setUserTypeValue((prevValue) => (prevValue === 1 ? 2 : 1));
  319. userCharts();
  320. }, 1000 * 60 * 10); // 10分钟
  321. return () => {
  322. clearTimeout(timerId);
  323. };
  324. }, [userTypeValue]);
  325. return (
  326. <div className={styles.container}>
  327. <PreloadImage
  328. src={dataBoardBg_two}
  329. alt="背景边框"
  330. loading="lazy"
  331. style={{ position: 'absolute', bottom: 0 }}
  332. />
  333. {/* 顶部 */}
  334. <div className={styles.dataTitleItem}>
  335. <PreloadImage src={dataBoardTitle} alt="顶部标题背景" />
  336. <img src={decoration_three} style={{ width: '50%' }} alt="顶部标题背景装饰" />
  337. <div className={styles.title}>山东永续绿建五恒环境科技有限公司</div>
  338. </div>
  339. {/* 中间内容 */}
  340. <div className={styles.dataBoardContent}>
  341. {/* 中间内容-----左侧 */}
  342. {/* 中间内容-----左侧--统计数据 */}
  343. <div className={styles.decoration_left_1}>
  344. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  345. <div className={styles.title_text}>统计数据</div>
  346. <div className={styles.statistics}>
  347. <div className={styles.user_data}>
  348. <div className={styles.statistics_title_text}>
  349. <DoubleRightOutlined style={{ fontSize: '17px', color: '#52ffff' }} />
  350. <span> 用户统计 </span>
  351. </div>
  352. <div className={styles.user_content}>
  353. <div className={styles.user_item}>
  354. <div className={styles.item_title}>注册用户数</div>
  355. <datav.DigitalFlop config={userNum} style={{ width: '170px', height: '50px' }} />
  356. </div>
  357. <div className={styles.user_item}>
  358. <div className={styles.item_title}>家庭数量</div>
  359. <datav.DigitalFlop
  360. config={homeNum}
  361. className={styles.item_content}
  362. style={{ width: '170px', height: '50px' }}
  363. />
  364. </div>
  365. </div>
  366. </div>
  367. <div className={styles.device_data}>
  368. <div className={styles.statistics_title_text}>
  369. <DoubleRightOutlined style={{ fontSize: '17px', color: '#52ffff' }} />
  370. <span> 设备统计 </span>
  371. </div>
  372. <div className={styles.device_content}>
  373. <div className={styles.device_item}>
  374. <div className={styles.qiu}>
  375. <datav.DigitalFlop
  376. config={deviceNum}
  377. className={styles.device_num}
  378. style={{ width: '200px', height: '50px' }}
  379. />
  380. </div>
  381. <div className={styles.device_title}>设备数</div>
  382. </div>
  383. <div className={styles.device_item}>
  384. <div className={styles.qiu}>
  385. <datav.DigitalFlop
  386. config={onlineDeviceNum}
  387. className={styles.device_num}
  388. style={{ width: '200px', height: '50px' }}
  389. />
  390. </div>
  391. <div className={styles.device_title}>在线设备数</div>
  392. </div>
  393. <div className={styles.device_item}>
  394. <div className={styles.qiu}>
  395. <datav.DigitalFlop
  396. config={offlineDeviceNum}
  397. className={styles.device_num}
  398. style={{ width: '200px', height: '50px' }}
  399. />
  400. </div>
  401. <div className={styles.device_title}>离线设备数</div>
  402. </div>
  403. </div>
  404. <div className={styles.device_content}>
  405. <div className={styles.device_item}>
  406. <div className={styles.qiu}>
  407. <datav.DigitalFlop
  408. config={errorDeviceNum}
  409. className={styles.device_num}
  410. style={{ width: '200px', height: '50px' }}
  411. />
  412. </div>
  413. <div className={styles.device_title}>故障设备数</div>
  414. </div>
  415. <div className={styles.device_item}>
  416. <div className={styles.qiu}>
  417. <datav.DigitalFlop
  418. config={masterControlNum}
  419. className={styles.device_num}
  420. style={{ width: '200px', height: '50px' }}
  421. />
  422. </div>
  423. <div className={styles.device_title}>主控数量</div>
  424. </div>
  425. <div className={styles.device_item}>
  426. <div className={styles.qiu}>
  427. <datav.DigitalFlop
  428. config={subControlNum}
  429. className={styles.device_num}
  430. style={{ width: '200px', height: '50px' }}
  431. />
  432. </div>
  433. <div className={styles.device_title}>分控数量</div>
  434. </div>
  435. </div>
  436. </div>
  437. </div>
  438. </div>
  439. {/* 中间内容-----左侧--用户增长趋势*/}
  440. <div className={styles.decoration_left_2}>
  441. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  442. <div className={styles.title_text}>用户增长趋势</div>
  443. <div className={styles.user_charts}>
  444. {userChartsData && userChartsData.length ? (
  445. <Suspense fallback={<div>loading</div>}>
  446. <LineChartsCommon width={450} height={250} data={userChartsData} />
  447. </Suspense>
  448. ) : (
  449. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  450. )}
  451. </div>
  452. </div>
  453. {/* 中间内容-----地图 */}
  454. <div className={styles.decoration_map}>
  455. {/* 数据统计 */}
  456. <div style={{ display: 'flex', justifyContent: 'space-around' }}>
  457. <div className={styles.data_show}>
  458. <PreloadImage src={decoration_five} alt="背景边框" />
  459. <datav.DigitalFlop
  460. config={deviceStatistics}
  461. className={styles.data_show_num}
  462. style={{ width: '200px', height: '50px' }}
  463. />
  464. <div className={styles.data_show_title} style={{ color: '#08c7f1' }}>
  465. 设备数
  466. </div>
  467. </div>
  468. <div className={styles.data_show}>
  469. <PreloadImage src={decoration_five} alt="背景边框" />
  470. <datav.DigitalFlop
  471. config={allRunTime}
  472. className={styles.data_show_num}
  473. style={{ width: '200px', height: '50px' }}
  474. />
  475. <div className={styles.data_show_title} style={{ color: '#ffb026' }}>
  476. 总运行时长(小时)
  477. </div>
  478. </div>
  479. <div className={styles.data_show}>
  480. <PreloadImage src={decoration_five} alt="背景边框" />
  481. <datav.DigitalFlop
  482. config={todayRunTime}
  483. className={styles.data_show_num}
  484. style={{ width: '200px', height: '50px' }}
  485. />
  486. <div className={styles.data_show_title} style={{ color: '#0dde79' }}>
  487. 今日运行时长(小时)
  488. </div>
  489. </div>
  490. </div>
  491. {areaDeviceList && areaDeviceList.length ? (
  492. <Suspense fallback={<div>loading</div>}>
  493. <MapComponent userData={userNum} areaList={areaDeviceList} />
  494. </Suspense>
  495. ) : (
  496. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  497. )}
  498. </div>
  499. {/* 中间内容-----右侧 */}
  500. {/* 中间内容-----右侧--地区设备数量统计 */}
  501. <div className={styles.decoration_right_3}>
  502. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  503. <div className={styles.title_text}>地区设备数量统计</div>
  504. {areaDeviceList && areaDeviceList.length && (
  505. <Suspense fallback={<div>loading</div>}>
  506. <AreaDeviceData data={areaDeviceList} />
  507. </Suspense>
  508. )}
  509. </div>
  510. {/* 中间内容-----右侧--设备增长趋势*/}
  511. <div className={styles.decoration_right_4}>
  512. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  513. <div className={styles.title_text}>设备增长趋势</div>
  514. {deviceChartsData && deviceChartsData.length ? (
  515. <Suspense fallback={<div>loading</div>}>
  516. <LineChartsCommon width={450} height={250} data={deviceChartsData} />
  517. </Suspense>
  518. ) : (
  519. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  520. )}
  521. </div>
  522. </div>
  523. {/* 底部轮播 */}
  524. <div className={styles.dataBottom}>
  525. <div className="swiper-content">
  526. {homeInfo && homeInfo.length ? (
  527. <Slider {...settings} className="swiper-container">
  528. {homeInfo.map((res) => {
  529. return (
  530. <Suspense key={res} fallback={<div>loading</div>}>
  531. <SliderData key={res} data={res} />
  532. </Suspense>
  533. );
  534. })}
  535. </Slider>
  536. ) : (
  537. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  538. )}
  539. </div>
  540. </div>
  541. </div>
  542. );
  543. };
  544. export default DataBoard;