index.tsx 17 KB

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