告警中心接入 地图iframe接入 机器视频 控制接入

This commit is contained in:
mmc
2026-05-12 17:31:34 +08:00
parent 78ee2d5c09
commit 827822c22d
7 changed files with 693 additions and 654 deletions

View File

@@ -1,92 +1,133 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
Card, Table, Tag, Badge, Space, Button,
Modal, Descriptions, Form, Select, Input
Modal, Descriptions, Form, Select, Input, Pagination, message
} from 'antd';
import { EyeOutlined } from '@ant-design/icons';
import { EyeOutlined, SearchOutlined } from '@ant-design/icons';
import dayjs from 'dayjs';
// 引入你的告警接口
import {
getAlarmList,
getAlarmDetail
} from '../../api/alarmApi.js';
const AntdCard = Card as any;
const { Option } = Select;
const { Search } = Input;
// 模拟历史数据
const mockHistory = [
{ id: 1, deviceName: '1#环境传感器', level: 'warn', content: '温度超过阈值 62℃', time: '2026-05-07 08:10:22', status: 'processed' },
{ id: 2, deviceName: '2#阵列区球机', level: 'error', content: '视频信号丢失', time: '2026-05-06 15:30:11', status: 'closed' },
{ id: 3, deviceName: '3#电池供电设备', level: 'info', content: '电量低于20%', time: '2026-05-05 10:20:15', status: 'processed' },
{ id: 4, deviceName: '1#阵列区球机', level: 'error', content: '存储设备故障', time: '2026-05-04 23:10:00', status: 'closed' },
];
// 级别 + 状态映射(和主页面保持一致)
const levelColor = { 1: '#F53F3F', 2: '#FF7D00', 3: '#F7BA1E', 4: '#165DFF' };
const levelText = { 1: '严重', 2: '重要', 3: '一般', 4: '提示' };
const statusText = { 0: '待处理', 1: '处理中', 2: '已关闭' };
const AlarmHistory = () => {
// 详情弹窗
const [form] = Form.useForm();
// 弹窗
const [detailVisible, setDetailVisible] = useState(false);
const [currentAlarm, setCurrentAlarm] = useState<any>(null);
const [currentAlarm, setCurrentAlarm] = useState(null);
// 搜索筛选
const [list, setList] = useState(mockHistory);
const [filteredList, setFilteredList] = useState(mockHistory);
const [timeRange, setTimeRange] = useState('today');
const [deviceType, setDeviceType] = useState('all');
// 列表 + 分页
const [loading, setLoading] = useState(false);
const [alarmList, setAlarmList] = useState([]);
const [total, setTotal] = useState(0);
const [pageNum, setPageNum] = useState(1);
const [pageSize, setPageSize] = useState(10);
// 打开详情
const showDetail = (record: any) => {
setCurrentAlarm(record);
setDetailVisible(true);
// 查询条件
const [queryParams, setQueryParams] = useState({
deviceName: '',
alarmLevel: '',
handleStatus: '',
timeRange: 'all'
});
// 获取告警历史列表
const fetchList = async () => {
setLoading(true);
try {
const res = await getAlarmList({
pageNum,
pageSize,
...queryParams
});
if (res.code === 200) {
setAlarmList(res.rows || []);
setTotal(res.total || 0);
}
} catch (err) {
message.error('加载历史记录失败');
} finally {
setLoading(false);
}
};
// 统一筛选逻辑
const handleFilter = (searchValue = '') => {
let res = list.filter(item => {
// 时间筛选
const timeMatch = timeRange === 'all' || true; // 后端可替换
// 设备筛选
const deviceMatch = deviceType === 'all' || item.deviceName.includes(deviceType);
// 搜索筛选
const searchMatch = !searchValue ||
item.deviceName.includes(searchValue) ||
item.content.includes(searchValue) ||
item.level.includes(searchValue);
return timeMatch && deviceMatch && searchMatch;
});
setFilteredList(res);
// 获取详情
const showDetail = async (id) => {
try {
const res = await getAlarmDetail(id);
if (res.code === 200) {
setCurrentAlarm(res.data);
setDetailVisible(true);
}
} catch (err) {
message.error('获取详情失败');
}
};
// 搜索
const handleSearch = (value: string) => {
handleFilter(value);
const handleSearch = (values) => {
setQueryParams({ ...values });
setPageNum(1);
};
// 加载
useEffect(() => {
fetchList();
}, [pageNum, pageSize, queryParams]);
// 表格列
const columns = [
{ title: '告警时间', dataIndex: 'time', width: 180 },
{ title: '设备名称', dataIndex: 'deviceName' },
{
title: '告警时间',
dataIndex: 'createTime',
width: 190,
sorter: true
},
{
title: '设备名称',
dataIndex: 'deviceName',
ellipsis: true
},
{
title: '告警级别',
render: (row: any) => {
const color = row.level === 'warn' ? 'orange' : row.level === 'error' ? 'red' : 'blue';
const text = row.level === 'warn' ? '警告' : row.level === 'error' ? '严重' : '提示';
return <Tag color={color}>{text}</Tag>;
}
width: 100,
render: (r) => (
<Tag color={levelColor[r.alarmLevel]} style={{ border: 'none', color: '#fff' }}>
{levelText[r.alarmLevel]}
</Tag>
)
},
{
title: '告警内容',
dataIndex: 'content',
ellipsis: true
},
{ title: '告警内容', dataIndex: 'content' },
{
title: '处理状态',
render: (row: any) => {
const statusMap = {
processed: { status: 'success', text: '已处理' },
closed: { status: 'default', text: '已关闭' },
};
const s = statusMap[row.status] || { status: 'default', text: '未知' };
return <Badge status={s.status as any} text={s.text} />;
}
width: 100,
render: (r) => (
<Badge
status={r.handleStatus === 2 ? 'success' : r.handleStatus === 1 ? 'processing' : 'warning'}
text={statusText[r.handleStatus]}
/>
)
},
{
title: '操作',
render: (_: any, record: any) => (
<Button type="link" icon={<EyeOutlined />} onClick={() => showDetail(record)}>
width: 120,
render: (_, r) => (
<Button type="link" icon={<EyeOutlined />} onClick={() => showDetail(r.id)}>
查看详情
</Button>
)
@@ -95,59 +136,71 @@ const AlarmHistory = () => {
return (
<div style={{ padding: 24 }}>
<AntdCard title="告警历史">
{/* 统一筛选栏:搜索 + 时间 + 设备 */}
<Space wrap size={16} style={{ marginBottom: 16, width: '100%' }}>
<Search
placeholder="搜索设备/内容/级别"
style={{ width: 260 }}
onSearch={handleSearch}
/>
<Card
title="告警历史"
style={{ borderRadius: 8 }}
extra={<span style={{ color: '#888' }}>历史告警记录</span>}
>
{/* 筛选栏 */}
<Form
form={form}
layout="inline"
onFinish={handleSearch}
style={{ marginBottom: 16, flexWrap: 'wrap', gap: 16 }}
>
<Form layout="inline">
<Form.Item label="时间范围">
<Select
value={timeRange}
style={{ width: 160 }}
onChange={(val) => {
setTimeRange(val);
handleFilter();
}}
>
<Option value="today">今日</Option>
<Option value="yesterday">昨日</Option>
<Option value="week">近7天</Option>
<Option value="month">本月</Option>
<Option value="all">全部</Option>
</Select>
</Form.Item>
<Form.Item label="设备类型">
<Select
value={deviceType}
style={{ width: 160 }}
onChange={(val) => {
setDeviceType(val);
handleFilter();
}}
>
<Option value="all">全部设备</Option>
<Option value="传感器">传感器</Option>
<Option value="球机">球机</Option>
<Option value="电池">电池设备</Option>
</Select>
</Form.Item>
</Form>
</Space>
<Form.Item name="alarmLevel" label="告警级别">
<Select placeholder="全部" style={{ width: 130 }} allowClear>
<Option value={1}>严重</Option>
<Option value={2}>重要</Option>
<Option value={3}>一般</Option>
<Option value={4}>提示</Option>
</Select>
</Form.Item>
<Form.Item name="handleStatus" label="处理状态">
<Select placeholder="全部" style={{ width: 130 }} allowClear>
<Option value={0}>待处理</Option>
<Option value={1}>处理中</Option>
<Option value={2}>已关闭</Option>
</Select>
</Form.Item>
<Form.Item>
<Space>
<Button type="primary" htmlType="submit">查询</Button>
<Button htmlType="reset">重置</Button>
</Space>
</Form.Item>
</Form>
{/* 表格 */}
<Table
rowKey="id"
columns={columns}
dataSource={filteredList}
pagination={{ pageSize: 10 }}
dataSource={alarmList}
loading={loading}
pagination={false}
scroll={{ x: 'max-content' }}
/>
</AntdCard>
{/* 分页 */}
<div style={{ textAlign: 'center', marginTop: 16 }}>
<Pagination
current={pageNum}
pageSize={pageSize}
total={total}
onChange={(p, s) => {
setPageNum(p);
setPageSize(s);
}}
showSizeChanger
showQuickJumper
showTotal={(total) => `共 ${total} 条`}
/>
</div>
</Card>
{/* 详情弹窗 */}
<Modal
@@ -155,24 +208,30 @@ const AlarmHistory = () => {
open={detailVisible}
onCancel={() => setDetailVisible(false)}
footer={null}
width={520}
width={580}
destroyOnClose
>
{currentAlarm && (
<Descriptions column={1} bordered>
<Descriptions.Item label="告警时间">{currentAlarm.time}</Descriptions.Item>
<Descriptions.Item label="设备名称">{currentAlarm.deviceName}</Descriptions.Item>
<Descriptions column={1} bordered size="small">
<Descriptions.Item label="告警ID">{currentAlarm.id}</Descriptions.Item>
<Descriptions.Item label="告警时间">{currentAlarm.createTime}</Descriptions.Item>
<Descriptions.Item label="设备ID">{currentAlarm.deviceId}</Descriptions.Item>
<Descriptions.Item label="设备名称">{currentAlarm.deviceName || '-'}</Descriptions.Item>
<Descriptions.Item label="告警内容">{currentAlarm.content}</Descriptions.Item>
<Descriptions.Item label="告警级别">
<Tag color={currentAlarm.level === 'warn' ? 'orange' : currentAlarm.level === 'error' ? 'red' : 'blue'}>
{currentAlarm.level === 'warn' ? '警告' : currentAlarm.level === 'error' ? '严重' : '提示'}
<Tag color={levelColor[currentAlarm.alarmLevel]} style={{ border: 'none', color: '#fff' }}>
{levelText[currentAlarm.alarmLevel]}
</Tag>
</Descriptions.Item>
<Descriptions.Item label="处理状态">
<Badge
status={currentAlarm.status === 'processed' ? 'success' : 'default'}
text={currentAlarm.status === 'processed' ? '已处理' : '已关闭'}
status={currentAlarm.handleStatus === 2 ? 'success' : currentAlarm.handleStatus === 1 ? 'processing' : 'warning'}
text={statusText[currentAlarm.handleStatus]}
/>
</Descriptions.Item>
{currentAlarm.handleRemark && (
<Descriptions.Item label="处理备注">{currentAlarm.handleRemark}</Descriptions.Item>
)}
</Descriptions>
)}
</Modal>