import React, { useEffect, useRef, useState } from 'react'; import { Card, Result, Select, Button } from 'antd'; import * as echarts from 'echarts'; import StandardTable from '@/components/StandardTable'; import styles from './RealtimeMonitoring.less'; import alarm0 from '@/assets/safe_majorHazard/online_monitoring/alarm0.png'; import alarm1 from '@/assets/safe_majorHazard/online_monitoring/alarm1.png'; import alarm2 from '@/assets/safe_majorHazard/online_monitoring/alarm2.png'; import alarm3 from '@/assets/safe_majorHazard/online_monitoring/alarm3.png'; import exportIcon from '@/assets/safe_majorHazard/online_monitoring/export.png'; import deleteIcon from '@/assets/safe_majorHazard/online_monitoring/delete.png'; const RealtimeMonitoring = () => { const chartRef = useRef(null); const [selectedRowKeys, setSelectedRowKeys] = useState([]); const [selectedRows, setSelectedRows] = useState([]); const [loading, setLoading] = useState(false); const [dataSource, setDataSource] = useState([]); const [pagination, setPagination] = useState({ current: 1, pageSize: 5, total: 0, }); useEffect(() => { if (chartRef.current) { const chart = echarts.init(chartRef.current); const option = { color: ['#04A7F3', '#E7C42C', '#EC6941'], legend: { data: ['液位', '温度', '压力'], top: "-3px", left: "center", itemGap: 40, // 图例间距 textStyle: { fontSize: 10 } }, grid: { left: '2%', right: '4%', bottom: '2%', top: '12%', containLabel: true }, xAxis: { type: 'category', boundaryGap: false, data: ['0:00', '2:00', '4:00', '6:00', '8:00', '10:00', '12:00', '14:00', '16:00', '18:00', '20:00', '22:00', '24:00'], axisLabel: { fontSize: 10 } }, yAxis: { type: 'value', min: 0, max: 500, axisLabel: { formatter: '{value}', fontSize: 10 } }, series: [ { name: '液位', type: 'line', smooth: true, lineStyle: { width: 1.5, color: '#04A7F3' }, areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: 'rgba(4, 167, 243, 0.3)' }, { offset: 1, color: 'rgba(4, 167, 243, 0)' } ] } }, symbol: 'none', // 不显示数据点 data: [120, 200, 150, 300, 250, 400, 350, 280, 320, 180, 220, 160, 140] }, { name: '温度', type: 'line', smooth: true, lineStyle: { width: 1.5, color: '#E7C42C' }, areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: 'rgba(231, 196, 44, 0.3)' }, { offset: 1, color: 'rgba(231, 196, 44, 0)' } ] } }, symbol: 'none', data: [80, 120, 100, 180, 160, 220, 200, 150, 170, 90, 110, 85, 75] }, { name: '压力', type: 'line', smooth: true, lineStyle: { width: 1.5, color: '#EC6941' }, areaStyle: { color: { type: 'linear', x: 0, y: 1, x2: 0, y2: 0, colorStops: [ { offset: 0, color: 'rgba(236, 105, 65, 0)' }, { offset: 1, color: 'rgba(236, 105, 65, 0.3)' } ] } }, symbol: 'none', data: [200, 300, 250, 450, 400, 430, 480, 420, 480, 280, 320, 260, 240] } ] }; chart.setOption(option); // 响应式调整 - 使用ResizeObserver监听容器尺寸变化 let resizeTimer = null; const handleResize = () => { // 防抖处理,避免频繁调用resize if (resizeTimer) { clearTimeout(resizeTimer); } resizeTimer = setTimeout(() => { chart.resize(); }, 100); }; // 监听窗口大小变化 window.addEventListener('resize', handleResize); // 监听容器尺寸变化(解决菜单栏伸缩时的自适应问题) let resizeObserver = null; if (window.ResizeObserver) { resizeObserver = new ResizeObserver(() => { // 使用setTimeout确保DOM更新完成后再调整图表 setTimeout(() => { handleResize(); }, 0); }); resizeObserver.observe(chartRef.current); } return () => { window.removeEventListener('resize', handleResize); if (resizeObserver) { resizeObserver.disconnect(); } if (resizeTimer) { clearTimeout(resizeTimer); } chart.dispose(); }; } }, []); // 表格列定义 const columns = [ { title: '编号', dataIndex: 'id', key: 'id', width: 80, render: (text, record, index) => { const page = pagination.current || 1; const pageSize = pagination.pageSize || 5; const number = (page - 1) * pageSize + index + 1; return `0${number}`.slice(-2); } }, { title: '报警时间', dataIndex: 'alarmTime', key: 'alarmTime', width: 150, }, { title: '报警传感器名称', dataIndex: 'sensorName', key: 'sensorName', width: 150, }, { title: '报警类型', dataIndex: 'alarmType', key: 'alarmType', width: 120, }, { title: '报警内容', dataIndex: 'alarmContent', key: 'alarmContent', width: 200, }, { title: '优先级', dataIndex: 'priority', key: 'priority', width: 80, render: (text) => { const colorMap = { '高': '#FF4D4F', '中': '#FAAD14', '低': '#52C41A' }; return {text}; } }, { title: '处理状态', dataIndex: 'status', key: 'status', width: 100, render: (text) => { const statusMap = { '未处理': { color: '#FF4D4F', bg: '#FFF2F0' }, '处理中': { color: '#FAAD14', bg: '#FFFBE6' }, '已处理': { color: '#52C41A', bg: '#F6FFED' } }; const status = statusMap[text] || { color: '#333', bg: '#F5F5F5' }; return ( {text} ); } }, { title: '处理时间', dataIndex: 'processTime', key: 'processTime', width: 150, }, { title: '处理人', dataIndex: 'processor', key: 'processor', width: 100, }, { title: '操作', key: 'action', width: 120, render: (_, record) => (