index.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. getHomeListInfo();
  303. }, 1000 * 60 * 10); // 10分钟
  304. return () => {};
  305. }, []);
  306. // 设备增长趋势切换
  307. useEffect(() => {
  308. const timerId = setTimeout(() => {
  309. setDeviceTypeValue((prevValue) => (prevValue === 1 ? 2 : 1));
  310. deviceCharts();
  311. }, 1000 * 60 * 10); // 10分钟
  312. return () => {
  313. clearTimeout(timerId);
  314. };
  315. }, [deviceTypeValue]);
  316. // 用户增长趋势切换
  317. useEffect(() => {
  318. const timerId = setTimeout(() => {
  319. setUserTypeValue((prevValue) => (prevValue === 1 ? 2 : 1));
  320. userCharts();
  321. }, 1000 * 60 * 10); // 10分钟
  322. return () => {
  323. clearTimeout(timerId);
  324. };
  325. }, [userTypeValue]);
  326. return (
  327. <div className={styles.container}>
  328. <PreloadImage
  329. src={dataBoardBg_two}
  330. alt="背景边框"
  331. loading="lazy"
  332. style={{ position: 'absolute', bottom: 0 }}
  333. />
  334. {/* 顶部 */}
  335. <div className={styles.dataTitleItem}>
  336. <PreloadImage src={dataBoardTitle} alt="顶部标题背景" />
  337. <img src={decoration_three} style={{ width: '50%' }} alt="顶部标题背景装饰" />
  338. <div className={styles.title}>山东永续绿建五恒环境科技有限公司</div>
  339. </div>
  340. {/* 中间内容 */}
  341. <div className={styles.dataBoardContent}>
  342. {/* 中间内容-----左侧 */}
  343. {/* 中间内容-----左侧--统计数据 */}
  344. <div className={styles.decoration_left_1}>
  345. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  346. <div className={styles.title_text}>统计数据</div>
  347. <div className={styles.statistics}>
  348. <div className={styles.user_data}>
  349. <div className={styles.statistics_title_text}>
  350. <DoubleRightOutlined style={{ fontSize: '17px', color: '#52ffff' }} />
  351. <span> 用户统计 </span>
  352. </div>
  353. <div className={styles.user_content}>
  354. <div className={styles.user_item}>
  355. <div className={styles.item_title}>注册用户数</div>
  356. <datav.DigitalFlop config={userNum} style={{ width: '170px', height: '50px' }} />
  357. </div>
  358. <div className={styles.user_item}>
  359. <div className={styles.item_title}>家庭数量</div>
  360. <datav.DigitalFlop
  361. config={homeNum}
  362. className={styles.item_content}
  363. style={{ width: '170px', height: '50px' }}
  364. />
  365. </div>
  366. </div>
  367. </div>
  368. <div className={styles.device_data}>
  369. <div className={styles.statistics_title_text}>
  370. <DoubleRightOutlined style={{ fontSize: '17px', color: '#52ffff' }} />
  371. <span> 设备统计 </span>
  372. </div>
  373. <div className={styles.device_content}>
  374. <div className={styles.device_item}>
  375. <div className={styles.qiu}>
  376. <datav.DigitalFlop
  377. config={deviceNum}
  378. className={styles.device_num}
  379. style={{ width: '200px', height: '50px' }}
  380. />
  381. </div>
  382. <div className={styles.device_title}>设备数</div>
  383. </div>
  384. <div className={styles.device_item}>
  385. <div className={styles.qiu}>
  386. <datav.DigitalFlop
  387. config={onlineDeviceNum}
  388. className={styles.device_num}
  389. style={{ width: '200px', height: '50px' }}
  390. />
  391. </div>
  392. <div className={styles.device_title}>在线设备数</div>
  393. </div>
  394. <div className={styles.device_item}>
  395. <div className={styles.qiu}>
  396. <datav.DigitalFlop
  397. config={offlineDeviceNum}
  398. className={styles.device_num}
  399. style={{ width: '200px', height: '50px' }}
  400. />
  401. </div>
  402. <div className={styles.device_title}>离线设备数</div>
  403. </div>
  404. </div>
  405. <div className={styles.device_content}>
  406. <div className={styles.device_item}>
  407. <div className={styles.qiu}>
  408. <datav.DigitalFlop
  409. config={errorDeviceNum}
  410. className={styles.device_num}
  411. style={{ width: '200px', height: '50px' }}
  412. />
  413. </div>
  414. <div className={styles.device_title}>故障设备数</div>
  415. </div>
  416. <div className={styles.device_item}>
  417. <div className={styles.qiu}>
  418. <datav.DigitalFlop
  419. config={masterControlNum}
  420. className={styles.device_num}
  421. style={{ width: '200px', height: '50px' }}
  422. />
  423. </div>
  424. <div className={styles.device_title}>主控数量</div>
  425. </div>
  426. <div className={styles.device_item}>
  427. <div className={styles.qiu}>
  428. <datav.DigitalFlop
  429. config={subControlNum}
  430. className={styles.device_num}
  431. style={{ width: '200px', height: '50px' }}
  432. />
  433. </div>
  434. <div className={styles.device_title}>分控数量</div>
  435. </div>
  436. </div>
  437. </div>
  438. </div>
  439. </div>
  440. {/* 中间内容-----左侧--用户增长趋势*/}
  441. <div className={styles.decoration_left_2}>
  442. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  443. <div className={styles.title_text}>用户增长趋势</div>
  444. <div className={styles.user_charts}>
  445. {userChartsData && userChartsData.length ? (
  446. <Suspense fallback={<div>loading</div>}>
  447. <LineChartsCommon width={450} height={250} data={userChartsData} />
  448. </Suspense>
  449. ) : (
  450. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  451. )}
  452. </div>
  453. </div>
  454. {/* 中间内容-----地图 */}
  455. <div className={styles.decoration_map}>
  456. {/* 数据统计 */}
  457. <div style={{ display: 'flex', justifyContent: 'space-around' }}>
  458. <div className={styles.data_show}>
  459. <PreloadImage src={decoration_five} alt="背景边框" />
  460. <datav.DigitalFlop
  461. config={deviceStatistics}
  462. className={styles.data_show_num}
  463. style={{ width: '200px', height: '50px' }}
  464. />
  465. <div className={styles.data_show_title} style={{ color: '#08c7f1' }}>
  466. 设备数
  467. </div>
  468. </div>
  469. <div className={styles.data_show}>
  470. <PreloadImage src={decoration_five} alt="背景边框" />
  471. <datav.DigitalFlop
  472. config={allRunTime}
  473. className={styles.data_show_num}
  474. style={{ width: '200px', height: '50px' }}
  475. />
  476. <div className={styles.data_show_title} style={{ color: '#ffb026' }}>
  477. 总运行时长(小时)
  478. </div>
  479. </div>
  480. <div className={styles.data_show}>
  481. <PreloadImage src={decoration_five} alt="背景边框" />
  482. <datav.DigitalFlop
  483. config={todayRunTime}
  484. className={styles.data_show_num}
  485. style={{ width: '200px', height: '50px' }}
  486. />
  487. <div className={styles.data_show_title} style={{ color: '#0dde79' }}>
  488. 今日运行时长(小时)
  489. </div>
  490. </div>
  491. </div>
  492. {areaDeviceList && areaDeviceList.length ? (
  493. <Suspense fallback={<div>loading</div>}>
  494. <MapComponent userData={userNum} areaList={areaDeviceList} />
  495. </Suspense>
  496. ) : (
  497. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  498. )}
  499. </div>
  500. {/* 中间内容-----右侧 */}
  501. {/* 中间内容-----右侧--地区设备数量统计 */}
  502. <div className={styles.decoration_right_3}>
  503. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  504. <div className={styles.title_text}>地区设备数量统计</div>
  505. {areaDeviceList && areaDeviceList.length && (
  506. <Suspense fallback={<div>loading</div>}>
  507. <AreaDeviceData data={areaDeviceList} />
  508. </Suspense>
  509. )}
  510. </div>
  511. {/* 中间内容-----右侧--设备增长趋势*/}
  512. <div className={styles.decoration_right_4}>
  513. <PreloadImage src={border} alt="边框" style={{ width: '480px', height: '300px' }} />
  514. <div className={styles.title_text}>设备增长趋势</div>
  515. {deviceChartsData && deviceChartsData.length ? (
  516. <Suspense fallback={<div>loading</div>}>
  517. <LineChartsCommon width={450} height={250} data={deviceChartsData} />
  518. </Suspense>
  519. ) : (
  520. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  521. )}
  522. </div>
  523. </div>
  524. {/* 底部轮播 */}
  525. <div className={styles.dataBottom}>
  526. <div className="swiper-content">
  527. {homeInfo && homeInfo.length ? (
  528. <Slider {...settings} className="swiper-container">
  529. {homeInfo.map((res) => {
  530. return (
  531. <Suspense key={res} fallback={<div>loading</div>}>
  532. <SliderData key={res} data={res} />
  533. </Suspense>
  534. );
  535. })}
  536. </Slider>
  537. ) : (
  538. <datav.Loading style={{ position: 'absolute' }}>Loading...</datav.Loading>
  539. )}
  540. </div>
  541. </div>
  542. </div>
  543. );
  544. };
  545. export default DataBoard;