关联告警趋势和关联告警列表

This commit is contained in:
mmc
2026-07-20 16:16:49 +08:00
parent c602f08a98
commit a3b30e1f83
3 changed files with 128 additions and 31 deletions

View File

@@ -45,7 +45,8 @@ import { orderTypeConfig, sourceTypeMap } from '../constants';
import { useSelector } from 'react-redux';
import { RootState } from '../store';
import { getUser } from '../api/user';
import utils, { errorLevelOptions, getWorkOrderTypeText, workOrderTypeOptions } from '../lib/utils';
import utils, { errorLevelOptions, getWorkOrderTypeText, levelColorMap, workOrderTypeOptions } from '../lib/utils';
import { getAlarmList } from '../api/alarmApi';
const { Option } = Select;
const { Search } = Input;
@@ -60,6 +61,8 @@ const priorityConfig = {
INFO: { label: '低', color: '#52c41a', bg: '#f6ffed', border: '#52c41a' }
};
// 工单状态数字映射
const orderStatusConfig = {
1: { label: '待处理', textColor: '#1890ff' },
@@ -137,6 +140,12 @@ const WorkOrderPage = () => {
// 排班日历选中日期,默认今天
const [scheduleDate, setScheduleDate] = useState(dayjs().format('YYYY-MM-DD'));
// 近7天关联告警数据
const [weekAlarmList, setWeekAlarmList] = useState([]);
const [alarmChartData, setAlarmChartData] = useState([]);
const [latestThreeAlarm, setLatestThreeAlarm] = useState([]);
@@ -261,6 +270,55 @@ const WorkOrderPage = () => {
});
};
// 获取近7天告警数据(用于工单右侧关联告警模块)
const fetchWeekAlarmData = async () => {
// 计算7天时间范围:今天0点 ~ 6天前0点,合计7天
const end = dayjs().format('YYYY-MM-DD 23:59:59');
const start = dayjs().subtract(6, 'day').format('YYYY-MM-DD 00:00:00');
try {
const res = await getAlarmList({
pageNum: 1,
pageSize: 9999,
startTime: start,
endTime: end,
siteId: stationId
});
if (res.code === 0 || res.code === 200) {
const list = res.rows || [];
setWeekAlarmList(list);
// 截取最新3条告警(按告警时间倒序)
const sortList = [...list].sort((a, b) => dayjs(b.alarmTime).valueOf() - dayjs(a.alarmTime).valueOf());
setLatestThreeAlarm(sortList.slice(0, 3));
// 组装折线图数据:按日期分组 ERROR/WARNING/INFO
const groupMap = {};
// 先初始化7天日期,保证横轴连续不缺天
for (let i = 6; i >= 0; i--) {
const dateStr = dayjs().subtract(i, 'day').format('MM-DD');
groupMap[dateStr] = { ERROR: 0, WARNING: 0, INFO: 0 };
}
list.forEach(item => {
if (!item.alarmTime || !item.alarmLevel) return;
const day = dayjs(item.alarmTime).format('MM-DD');
if (groupMap[day]) {
groupMap[day][item.alarmLevel] += 1;
}
});
// 转为图表数组
const chartArr = Object.entries(groupMap).map(([date, obj]) => ({
date,
ERROR: obj.ERROR,
WARNING: obj.WARNING,
INFO: obj.INFO
}));
setAlarmChartData(chartArr);
}
} catch (err) {
console.error('加载近7天告警失败', err);
}
};
const fetchAllData = async () => {
if (!stationId) return;
@@ -678,9 +736,9 @@ const WorkOrderPage = () => {
useEffect(() => {
fetchAllData();
getWorkOrderList();
}, []);
fetchWeekAlarmData(); // 新增加载7天告警
}, [stationId]);
const cardStyle = {
borderRadius: 12,
@@ -1281,7 +1339,7 @@ const WorkOrderPage = () => {
<Col span={13}>
<div style={{ fontSize: 12, fontWeight: 700, color: '#1D2129', marginBottom: 12 }}>关联告警趋势 <Text type="secondary" style={{ fontSize: 11, fontWeight: 400 }}>(近 7 天)</Text></div>
<UniversalLineChart
data={alarmTrendData}
data={alarmChartData}
xKey="date"
height={130}
backgroundColor="transparent"
@@ -1290,7 +1348,11 @@ const WorkOrderPage = () => {
showGrid={true}
smooth
dot
series={[{ key: 'value', name: '告警数量', color: '#165DFF', strokeWidth: 2 }]}
series={[
{ key: 'ERROR', name: '高告警', color: '#FF4D4F', strokeWidth: 2 },
{ key: 'WARNING', name: '中告警', color: '#FA8C16', strokeWidth: 2 },
{ key: 'INFO', name: '低告警', color: '#52c41a', strokeWidth: 2 },
]}
/>
</Col>
<Col span={11}>
@@ -1299,18 +1361,56 @@ const WorkOrderPage = () => {
<Button type="link" size="small" style={{ fontSize: 11, padding: 0 }}>查看全部</Button>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
{[
{ title: 'INV-05 逆变器告警', time: '05-24 10:24', status: 'error' },
{ title: 'B-12 区块热斑告警', time: '05-24 09:56', status: 'warning' },
{ title: 'B-12 组件温度异常', time: '05-24 09:32', status: 'warning' },
].map((item, idx) => (
<div key={idx} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '6px 8px', background: '#f8fafc', borderRadius: 6 }}>
<div style={{ width: 6, height: 6, borderRadius: '50%', background: item.status === 'error' ? '#F53F3F' : '#F7BA1E' }}></div>
<Text ellipsis style={{ flex: 1, fontSize: 11, fontWeight: 500, color: '#4E5969' }}>{item.title}</Text>
<Text type="secondary" style={{ fontSize: 10, flexShrink: 0 }}>{item.time}</Text>
</div>
))}
{latestThreeAlarm.length === 0 ? (
<Text type="secondary" style={{ fontSize: 11 }}>近7天无告警记录</Text>
) : (
<>
{latestThreeAlarm.map((item, idx) => (
<div
key={idx}
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
padding: '6px 8px',
background: '#f8fafc',
borderRadius: 6
}}
>
<div
style={{
width: 6,
height: 6,
borderRadius: '50%',
background: levelColorMap[item.alarmLevel]
}}
></div>
<Text
ellipsis
style={{
flex: 1,
fontSize: 11,
fontWeight: 500,
color: '#4E5969'
}}
>
{item.alarmTitle}
</Text>
<Text
type="secondary"
style={{
fontSize: 10,
flexShrink: 0
}}
>
{dayjs(item.alarmTime).format('MM-DD HH:mm')}
</Text>
</div>
))}
</>
)}
</div>
</Col>
</Row>
</Card>