index.tsx 17 KB

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