VideoAnalysis.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. import ModuleTitle from '@/components/ManagementPage/moduleTitle';
  2. import TabsContent from '@/components/TabsContent';
  3. import ThresholdDetail from '@/components/ThresholdDetail';
  4. import { UnityAction } from '@/utils/utils';
  5. import { Collapse, Empty, Spin, Table, Tabs } from 'antd';
  6. import { useEffect, useMemo, useState } from 'react';
  7. import styles from './VideoAnalysis.less';
  8. const { TabPane } = Tabs;
  9. const { Panel } = Collapse;
  10. const TYPE = {
  11. video: 1,
  12. fill: 2,
  13. water: 3,
  14. };
  15. function VideoAnalysis(props) {
  16. const { videoNum, data, videoData = {}, loading } = props;
  17. const [tab, setTab] = useState('1');
  18. const allCount = Object.values(videoData).reduce(
  19. (total, item) => total + (item?.length || 0),
  20. 0,
  21. );
  22. const [prevKey, setPrevKey] = useState();
  23. const [selectedName, setSelectedName] = useState('');
  24. const errorData = useMemo(() => {
  25. const list1 =
  26. videoData.dumu_list?.map((item) => {
  27. return { ...item, type_name: '视频报警', type: TYPE.video };
  28. }) || [];
  29. const list2 =
  30. videoData.environment_list
  31. ?.filter((item) => item.status)
  32. .map((item) => {
  33. return { ...item, type_name: '环境检测', type: TYPE.fill };
  34. }) || [];
  35. // const list3 =
  36. // videoData.fluid_level_list
  37. // ?.filter((item) => item.status)
  38. // .map((item) => {
  39. // return { ...item, type_name: '液位监测', type: TYPE.water };
  40. // }) || [];
  41. return [...list1, ...list2];
  42. }, [videoData]);
  43. useEffect(() => {
  44. UnityAction.on('SynCam', selectedItem);
  45. UnityAction.on('SynDev', selectedItem);
  46. return () => {
  47. UnityAction.off('SynDev', selectedItem);
  48. UnityAction.off('SynCam', selectedItem);
  49. };
  50. }, [videoData]);
  51. //滚动到相应位置
  52. const selectedItem = (e) => {
  53. setSelectedName(e);
  54. const dom = document.querySelector(`div[data-name="${e}"]`);
  55. if (dom) {
  56. let v = document.getElementById('videoContent');
  57. v.scrollTop = dom.offsetTop;
  58. }
  59. };
  60. const onTabChange = (tab) => {
  61. setTab(tab);
  62. setSelectedName('');
  63. UnityAction.sendMsg('SensorAnalysisType', tab);
  64. };
  65. return (
  66. <Spin spinning={loading}>
  67. <div style={{ height: 'calc(100vh - 5.6rem)', overflow: 'auto' }}>
  68. <TabsContent
  69. small
  70. bold={false}
  71. spacing={2.5}
  72. center={false}
  73. defaultActiveKey="1"
  74. items={[
  75. {
  76. label: `异常(${videoNum})`,
  77. key: '1',
  78. children: (
  79. <AnalysisContent
  80. errorData={errorData}
  81. selectedName={selectedName}
  82. setSelectedName={setSelectedName}
  83. />
  84. ),
  85. },
  86. {
  87. label: `全部(${allCount})`,
  88. key: '2',
  89. children: (
  90. <AllContent
  91. videoData={videoData}
  92. selectedName={selectedName}
  93. setSelectedName={setSelectedName}
  94. />
  95. ),
  96. },
  97. ]}
  98. onChange={onTabChange}
  99. />
  100. </div>
  101. </Spin>
  102. );
  103. }
  104. function AnalysisContent({ errorData, selectedName, setSelectedName }) {
  105. const [prevKey, setPrevKey] = useState();
  106. const handleImgClick = (item) => {
  107. localStorage.setItem('preview', item.path);
  108. UnityAction.sendMsg('SensorPic');
  109. };
  110. const handleCollapse = (item) => {
  111. const key = item.type == TYPE.video ? item.device_name : item.device_code;
  112. const name = item.type == TYPE.video ? 'SynCam' : 'SynDev';
  113. // 清除unity发送过来的选中设备
  114. setSelectedName('');
  115. if (item.key === prevKey) return;
  116. setPrevKey(item.key);
  117. UnityAction.sendMsg(name, key);
  118. };
  119. const renderContent = (key, item) => {
  120. let content = '';
  121. switch (key) {
  122. case 1:
  123. content = (
  124. <>
  125. <div className={styles.label}>画面报警:</div>
  126. <div className={styles.content}>
  127. {item.event_type}
  128. <img
  129. className={styles.img}
  130. src={item.path}
  131. onClick={() => handleImgClick(item)}
  132. />
  133. </div>
  134. </>
  135. );
  136. break;
  137. case 2:
  138. content = (
  139. <>
  140. <div className={styles.contentFlex}>
  141. <div>参数:{item.patrol_name}</div>
  142. <div className={styles.threshold}>
  143. <span>阈值范围:</span>
  144. <div style={{ width: '1.8rem' }}>
  145. <ThresholdDetail
  146. current={item.value || 0}
  147. data={{
  148. JsonNumThreshold: item?.json_num_threshold,
  149. Type: 2,
  150. }}
  151. />
  152. </div>
  153. </div>
  154. <div>
  155. 状态:
  156. {item?.status <= 0 ? (
  157. <span className={styles.textNormal}>正常</span>
  158. ) : item.status == 1 ? (
  159. <span className={styles.textAbnormal}>异常</span>
  160. ) : (
  161. <span className={styles.textWarning}>警告</span>
  162. )}
  163. </div>
  164. </div>
  165. </>
  166. );
  167. break;
  168. case 3:
  169. content = (
  170. <>
  171. <div className={styles.contentFlex}>
  172. <div>原液位:{item.origin_value}</div>
  173. <div> 差值:{item.value} </div>
  174. <div className={styles.threshold}>
  175. <span>阈值范围:</span>
  176. <div style={{ width: '1.8rem' }}>
  177. <ThresholdDetail
  178. current={item.value || 0}
  179. data={{
  180. JsonNumThreshold: item?.json_num_threshold,
  181. Type: 2,
  182. }}
  183. />
  184. </div>
  185. </div>
  186. <div>
  187. 状态:
  188. {item?.status <= 0 ? (
  189. <span className={styles.textNormal}>正常</span>
  190. ) : item.status == 1 ? (
  191. <span className={styles.textAbnormal}>异常</span>
  192. ) : (
  193. <span className={styles.textWarning}>警告</span>
  194. )}
  195. </div>
  196. </div>
  197. </>
  198. );
  199. break;
  200. }
  201. return content;
  202. };
  203. const getClassName = (item) => {
  204. const device =
  205. item.type == TYPE.video ? item.device_name : item.device_code;
  206. if (selectedName && selectedName == device) {
  207. return styles.tableSelect;
  208. } else if (prevKey == item.key) {
  209. return styles.tableSelect;
  210. }
  211. return styles.table;
  212. };
  213. return (
  214. <div
  215. className={styles.page}
  216. style={{ height: 'calc(100vh - 6.3rem)', overflow: 'auto' }}
  217. >
  218. {errorData?.length > 0 ? (
  219. errorData.map((item) => (
  220. <div
  221. data-name={item.device_name}
  222. key={item.key}
  223. onClick={() => handleCollapse(item)}
  224. >
  225. <Collapse
  226. activeKey={item.key}
  227. className={getClassName(item)}
  228. expandIcon={() => (
  229. <div className={styles.typeText}>{item.type_name}</div>
  230. )}
  231. >
  232. <Panel header={item.device_name} key={item.key}>
  233. <div className={styles.box}>
  234. <div className={styles.item}>
  235. {renderContent(item.type, item)}
  236. </div>
  237. </div>
  238. </Panel>
  239. </Collapse>
  240. </div>
  241. ))
  242. ) : (
  243. <Empty />
  244. )}
  245. </div>
  246. );
  247. }
  248. function AllContent({ videoData = {}, selectedName, setSelectedName }) {
  249. const {
  250. environment_list = [],
  251. // fluid_level_list = [],
  252. dumu_list = [],
  253. } = videoData;
  254. // const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  255. const [selectKey, setSelectKey] = useState([]);
  256. const columns1 = [
  257. {
  258. title: '设备名称',
  259. render: (record) => (
  260. <div>
  261. {record.device_name}({record.device_code})
  262. </div>
  263. ),
  264. },
  265. {
  266. title: '参数',
  267. dataIndex: 'patrol_name',
  268. key: 'patrol_name',
  269. },
  270. {
  271. title: '设定值范围',
  272. render: (record) => (
  273. <ThresholdDetail
  274. current={record.value || 0}
  275. data={{
  276. JsonNumThreshold: record?.json_num_threshold,
  277. Type: record.type || 2,
  278. }}
  279. />
  280. ),
  281. },
  282. {
  283. title: '状态',
  284. dataIndex: 'status',
  285. render: (status) => {
  286. switch (status) {
  287. case -1:
  288. case 0:
  289. return (
  290. <div>
  291. <i
  292. className={styles.iconStatus}
  293. style={{ background: '#12CEB3' }}
  294. ></i>
  295. 正常
  296. </div>
  297. );
  298. case 1:
  299. return (
  300. <div>
  301. <i
  302. className={styles.iconStatus}
  303. style={{ background: '#FE5850' }}
  304. ></i>
  305. 异常
  306. </div>
  307. );
  308. case 2:
  309. return (
  310. <div>
  311. <i
  312. className={styles.iconStatus}
  313. style={{ background: '#FFE26D' }}
  314. ></i>
  315. 警告
  316. </div>
  317. );
  318. }
  319. },
  320. },
  321. ];
  322. const columns2 = [
  323. {
  324. title: '设备名称',
  325. render: (record) => (
  326. <div>
  327. {record.device_name}({record.device_code})
  328. </div>
  329. ),
  330. },
  331. {
  332. title: '液位数',
  333. dataIndex: 'origin_value',
  334. key: 'origin_value',
  335. },
  336. {
  337. title: '差值',
  338. dataIndex: 'value',
  339. key: 'value',
  340. },
  341. {
  342. title: '设定值范围',
  343. render: (record) => (
  344. <ThresholdDetail
  345. current={record.value || 0}
  346. data={{
  347. JsonNumThreshold: record?.json_num_threshold,
  348. Type: record.type || 2,
  349. }}
  350. // onClick={() => onClickThreshold(record)}
  351. />
  352. ),
  353. },
  354. {
  355. title: '状态',
  356. dataIndex: 'status',
  357. render: (status) => {
  358. switch (status) {
  359. case -1:
  360. case 0:
  361. return (
  362. <div>
  363. <i
  364. className={styles.iconStatus}
  365. style={{ background: '#12CEB3' }}
  366. ></i>
  367. 正常
  368. </div>
  369. );
  370. case 1:
  371. return (
  372. <div>
  373. <i
  374. className={styles.iconStatus}
  375. style={{ background: '#FE5850' }}
  376. ></i>
  377. 异常
  378. </div>
  379. );
  380. case 2:
  381. return (
  382. <div>
  383. <i
  384. className={styles.iconStatus}
  385. style={{ background: '#FFE26D' }}
  386. ></i>
  387. 警告
  388. </div>
  389. );
  390. }
  391. },
  392. },
  393. ];
  394. const columns3 = [
  395. {
  396. title: '名称',
  397. render: (record) => (
  398. <div>
  399. {record.device_name}({record.device_code})
  400. </div>
  401. ),
  402. },
  403. {
  404. title: '描述',
  405. dataIndex: 'event_type',
  406. key: 'event_type',
  407. },
  408. {
  409. title: '图片',
  410. render: (item) => (
  411. <img
  412. className={styles.img}
  413. src={item.path}
  414. onClick={() => handleImgClick(item)}
  415. />
  416. ),
  417. },
  418. ];
  419. const onSelectRow = (item, type) => {
  420. const key = type == TYPE.video ? item.device_name : item.device_code;
  421. const name = type == TYPE.video ? 'SynCam' : 'SynDev';
  422. setSelectedName('');
  423. if (selectKey === item.key) return;
  424. setSelectKey(item.key);
  425. UnityAction.sendMsg(name, key);
  426. };
  427. const handleImgClick = (item) => {
  428. localStorage.setItem('preview', item.path);
  429. UnityAction.sendMsg('SensorPic');
  430. };
  431. const setRowClassName = (item) => {
  432. const device =
  433. item.type == TYPE.video ? item.device_name : item.device_code;
  434. if (selectedName && selectedName == device) {
  435. return styles.tableSelect;
  436. } else if (selectKey == item.key) {
  437. return styles.tableSelect;
  438. }
  439. return '';
  440. };
  441. return (
  442. <div
  443. className={styles.page}
  444. style={{
  445. height: 'calc(100vh - 6.3rem)',
  446. overflow: 'auto',
  447. // backgroundColor: '#FFFFFF',
  448. }}
  449. >
  450. <div className={styles.box}>
  451. <ModuleTitle title="环境检测" />
  452. <Table
  453. dataSource={environment_list}
  454. columns={columns1}
  455. rowClassName={setRowClassName}
  456. onRow={(record, index) => ({
  457. onClick: () => onSelectRow(record, TYPE.fill),
  458. })}
  459. pagination={false}
  460. scroll={{ y: 400 }}
  461. />
  462. </div>
  463. {/* <div className={`card-box ${styles.box}`}>
  464. <ModuleTitle title="液位检测" />
  465. <Table
  466. dataSource={fluid_level_list}
  467. columns={columns2}
  468. rowClassName={setRowClassName}
  469. onRow={(record, index) => ({
  470. onClick: () => onSelectRow(record, TYPE.water),
  471. })}
  472. pagination={false}
  473. scroll={{ y: 400 }}
  474. />
  475. </div> */}
  476. <div className={styles.box}>
  477. <ModuleTitle title="视频识别" />
  478. <Table
  479. dataSource={dumu_list}
  480. columns={columns3}
  481. rowClassName={setRowClassName}
  482. onRow={(record, index) => ({
  483. onClick: () => onSelectRow(record, TYPE.video),
  484. })}
  485. rowKey="id"
  486. pagination={false}
  487. scroll={{ y: 400 }}
  488. />
  489. </div>
  490. </div>
  491. );
  492. }
  493. export default VideoAnalysis;