ReportDumCom.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { Table } from 'antd';
  2. import dayjs from 'dayjs';
  3. import { useEffect, useMemo } from 'react';
  4. import ReactZmage from 'react-zmage';
  5. import styles from '../PatrolReportDetail.less';
  6. import Empty from './Empty';
  7. export default function ReportDumCom(props) {
  8. const { data = [], title, statusCheck, changeStatus } = props;
  9. const errorCount = data?.length || 0;
  10. const columns = [
  11. {
  12. title: '报警时间',
  13. dataIndex: 'event_time',
  14. render: (time) => dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
  15. },
  16. {
  17. title: '设备名称',
  18. dataIndex: 'device_name',
  19. },
  20. {
  21. title: '报警类型',
  22. dataIndex: 'event_type',
  23. // render: type => alarmType[type],
  24. },
  25. {
  26. title: '报警图片',
  27. render: (item) => (
  28. <ReactZmage
  29. controller={{
  30. // 关闭按钮
  31. close: true,
  32. // 旋转按钮
  33. rotate: true,
  34. // 缩放按钮
  35. zoom: false,
  36. // 下载按钮
  37. download: false,
  38. // 翻页按钮
  39. flip: false,
  40. // 多页指示
  41. pagination: false,
  42. }}
  43. backdrop="rgba(255,255,255,0.5)"
  44. style={{ height: '0.9rem' }}
  45. src={item.path}
  46. />
  47. ),
  48. },
  49. ];
  50. const show = useMemo(() => {
  51. if (statusCheck.length != 3) {
  52. // 不显示异常数据时,隐藏次模块
  53. if (!statusCheck.includes(1)) return null;
  54. // 过滤异常并且此模块没有异常数据时,不显示此模块
  55. if (statusCheck.includes(1) && errorCount == 0) return null;
  56. }
  57. return true;
  58. }, [statusCheck, errorCount]);
  59. useEffect(() => {
  60. if (show) {
  61. changeStatus(1);
  62. } else {
  63. changeStatus(0);
  64. }
  65. }, [show]);
  66. if (!show) return null;
  67. return (
  68. <div style={{ marginBottom: '0.3rem' }}>
  69. <div className={styles.tabBarExtraContent}>
  70. <div className={styles.text} style={{ width: '60%' }}>
  71. {title}
  72. </div>
  73. <div className={styles.abnormal}>
  74. <div className={styles.text} style={{ float: 'right' }}>
  75. 异常({errorCount})
  76. </div>
  77. </div>
  78. </div>
  79. <Table
  80. bordered
  81. rowKey="event_time"
  82. columns={columns}
  83. dataSource={data}
  84. locale={{
  85. emptyText: <Empty />,
  86. }}
  87. pagination={false}
  88. />
  89. </div>
  90. );
  91. }