ReportDumCom.js 2.5 KB

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