告警中心 初始化
This commit is contained in:
183
src/components/alerts/AlarmHistory.tsx
Normal file
183
src/components/alerts/AlarmHistory.tsx
Normal file
@@ -0,0 +1,183 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card, Table, Tag, Badge, Space, Button,
|
||||
Modal, Descriptions, Form, Select, Input
|
||||
} from 'antd';
|
||||
import { EyeOutlined } from '@ant-design/icons';
|
||||
|
||||
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 AlarmHistory = () => {
|
||||
// 详情弹窗
|
||||
const [detailVisible, setDetailVisible] = useState(false);
|
||||
const [currentAlarm, setCurrentAlarm] = useState<any>(null);
|
||||
|
||||
// 搜索筛选
|
||||
const [list, setList] = useState(mockHistory);
|
||||
const [filteredList, setFilteredList] = useState(mockHistory);
|
||||
const [timeRange, setTimeRange] = useState('today');
|
||||
const [deviceType, setDeviceType] = useState('all');
|
||||
|
||||
// 打开详情
|
||||
const showDetail = (record: any) => {
|
||||
setCurrentAlarm(record);
|
||||
setDetailVisible(true);
|
||||
};
|
||||
|
||||
// 统一筛选逻辑
|
||||
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 handleSearch = (value: string) => {
|
||||
handleFilter(value);
|
||||
};
|
||||
|
||||
// 表格列
|
||||
const columns = [
|
||||
{ title: '告警时间', dataIndex: 'time', width: 180 },
|
||||
{ title: '设备名称', dataIndex: 'deviceName' },
|
||||
{
|
||||
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>;
|
||||
}
|
||||
},
|
||||
{ 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} />;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (_: any, record: any) => (
|
||||
<Button type="link" icon={<EyeOutlined />} onClick={() => showDetail(record)}>
|
||||
查看详情
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<AntdCard title="告警历史">
|
||||
{/* 统一筛选栏:搜索 + 时间 + 设备 */}
|
||||
<Space wrap size={16} style={{ marginBottom: 16, width: '100%' }}>
|
||||
<Search
|
||||
placeholder="搜索设备/内容/级别"
|
||||
style={{ width: 260 }}
|
||||
onSearch={handleSearch}
|
||||
/>
|
||||
|
||||
<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>
|
||||
|
||||
{/* 表格 */}
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={filteredList}
|
||||
pagination={{ pageSize: 10 }}
|
||||
/>
|
||||
</AntdCard>
|
||||
|
||||
{/* 详情弹窗 */}
|
||||
<Modal
|
||||
title="告警历史详情"
|
||||
open={detailVisible}
|
||||
onCancel={() => setDetailVisible(false)}
|
||||
footer={null}
|
||||
width={520}
|
||||
>
|
||||
{currentAlarm && (
|
||||
<Descriptions column={1} bordered>
|
||||
<Descriptions.Item label="告警时间">{currentAlarm.time}</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>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="处理状态">
|
||||
<Badge
|
||||
status={currentAlarm.status === 'processed' ? 'success' : 'default'}
|
||||
text={currentAlarm.status === 'processed' ? '已处理' : '已关闭'}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AlarmHistory;
|
||||
21
src/components/alerts/AlarmOverview.tsx
Normal file
21
src/components/alerts/AlarmOverview.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { Card, Row, Col, Space, Empty } from 'antd';
|
||||
import { AlertOutlined, CloseCircleOutlined, ExclamationCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
|
||||
|
||||
const AntdCard = Card as any;
|
||||
|
||||
const AlarmOverview = () => {
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<Row gutter={16} style={{ marginBottom: 24 }}>
|
||||
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}><AlertOutlined style={{ color: '#1677ff', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>告警总数</div><div style={{ fontWeight: 600 }}>45</div></div></Space></AntdCard></Col>
|
||||
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#fff2f0', borderRadius: 8, padding: 8 }}><CloseCircleOutlined style={{ color: '#ff4d4f', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>严重告警</div><div style={{ fontWeight: 600 }}>12</div></div></Space></AntdCard></Col>
|
||||
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#fff7e6', borderRadius: 8, padding: 8 }}><ExclamationCircleOutlined style={{ color: '#fa8c16', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>警告告警</div><div style={{ fontWeight: 600 }}>20</div></div></Space></AntdCard></Col>
|
||||
<Col span={6}><AntdCard size="small"><Space><div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}><CheckCircleOutlined style={{ color: '#52c41a', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>已处理</div><div style={{ fontWeight: 600 }}>13</div></div></Space></AntdCard></Col>
|
||||
</Row>
|
||||
<AntdCard title="告警地图"><Empty description="告警地图(可接入GIS)" /></AntdCard>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AlarmOverview;
|
||||
138
src/components/alerts/AlarmRealtime.tsx
Normal file
138
src/components/alerts/AlarmRealtime.tsx
Normal file
@@ -0,0 +1,138 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card, Table, Tag, Badge, Space, Button,
|
||||
Modal, Descriptions, Input, Select
|
||||
} from 'antd';
|
||||
import { EyeOutlined } from '@ant-design/icons';
|
||||
|
||||
const AntdCard = Card as any;
|
||||
const { Search } = Input;
|
||||
const { Option } = Select;
|
||||
|
||||
// 模拟数据
|
||||
const mockAlarms = [
|
||||
{ id: 1, deviceName: '1#环境传感器', level: 'warn', content: '温度超过阈值 62℃', time: '2026-05-07 10:24:00', status: 'unprocessed' },
|
||||
{ id: 2, deviceName: '2#阵列区球机', level: 'error', content: '视频信号丢失', time: '2026-05-07 10:20:00', status: 'processing' },
|
||||
{ id: 3, deviceName: '3#电池供电设备', level: 'info', content: '电量低于20%', time: '2026-05-07 09:50:00', status: 'processed' },
|
||||
];
|
||||
|
||||
const AlarmRealtime = () => {
|
||||
// 弹窗控制
|
||||
const [detailVisible, setDetailVisible] = useState(false);
|
||||
const [currentAlarm, setCurrentAlarm] = useState<any>(null);
|
||||
|
||||
// 搜索 + 筛选
|
||||
const [list, setList] = useState(mockAlarms);
|
||||
const [filteredList, setFilteredList] = useState(mockAlarms);
|
||||
|
||||
// 打开详情
|
||||
const showDetail = (record: any) => {
|
||||
setCurrentAlarm(record);
|
||||
setDetailVisible(true);
|
||||
};
|
||||
|
||||
// 搜索筛选
|
||||
const handleSearch = (value: string) => {
|
||||
const res = list.filter(item =>
|
||||
item.deviceName.includes(value) ||
|
||||
item.content.includes(value) ||
|
||||
item.level.includes(value)
|
||||
);
|
||||
setFilteredList(res);
|
||||
};
|
||||
|
||||
// 表格列
|
||||
const columns = [
|
||||
{ title: '时间', dataIndex: 'time', width: 180 },
|
||||
{ title: '设备', dataIndex: 'deviceName' },
|
||||
{
|
||||
title: '级别',
|
||||
render: (l: any) => {
|
||||
const color = l.level === 'warn' ? 'orange' : l.level === 'error' ? 'red' : 'blue';
|
||||
const text = l.level === 'warn' ? '警告' : l.level === 'error' ? '严重' : '提示';
|
||||
return <Tag color={color}>{text}</Tag>;
|
||||
}
|
||||
},
|
||||
{ title: '内容', dataIndex: 'content' },
|
||||
{
|
||||
title: '状态',
|
||||
render: (r: any) => {
|
||||
const statusMap = {
|
||||
unprocessed: { status: 'error', text: '未处理' },
|
||||
processing: { status: 'warning', text: '处理中' },
|
||||
processed: { status: 'success', text: '已处理' },
|
||||
closed: { status: 'default', text: '已关闭' },
|
||||
};
|
||||
const s = statusMap[r.status] || statusMap.unprocessed;
|
||||
return <Badge status={s.status as any} text={s.text} />;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (_: any, record: any) => (
|
||||
<Button type="link" icon={<EyeOutlined />} onClick={() => showDetail(record)}>
|
||||
详情
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<AntdCard
|
||||
title="实时告警"
|
||||
extra={
|
||||
<Search
|
||||
placeholder="搜索设备名称/告警内容"
|
||||
style={{ width: 260 }}
|
||||
onSearch={handleSearch}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{/* 表格 */}
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={filteredList}
|
||||
pagination={{ pageSize: 10 }}
|
||||
/>
|
||||
</AntdCard>
|
||||
|
||||
{/* 告警详情弹窗 */}
|
||||
<Modal
|
||||
title="告警详情"
|
||||
open={detailVisible}
|
||||
onCancel={() => setDetailVisible(false)}
|
||||
footer={null}
|
||||
width={500}
|
||||
>
|
||||
{currentAlarm && (
|
||||
<Descriptions column={1} bordered>
|
||||
<Descriptions.Item label="告警时间">{currentAlarm.time}</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>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="处理状态">
|
||||
<Badge
|
||||
status={
|
||||
currentAlarm.status === 'unprocessed' ? 'error' :
|
||||
currentAlarm.status === 'processing' ? 'warning' : 'success'
|
||||
}
|
||||
text={
|
||||
currentAlarm.status === 'unprocessed' ? '未处理' :
|
||||
currentAlarm.status === 'processing' ? '处理中' : '已处理'
|
||||
}
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AlarmRealtime;
|
||||
181
src/components/alerts/AlarmRules.tsx
Normal file
181
src/components/alerts/AlarmRules.tsx
Normal file
@@ -0,0 +1,181 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Space, Popconfirm, Tag, Badge,
|
||||
Modal, Form, Input, Select, Switch
|
||||
} from 'antd';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||
|
||||
const AntdCard = Card as any;
|
||||
const { Option } = Input;
|
||||
const { Search } = Input;
|
||||
|
||||
// 模拟数据
|
||||
const mockRules = [
|
||||
{ id: 1, name: '温度超温', deviceType: 'sensor', level: 'warn', condition: 'temp > 60', status: true },
|
||||
{ id: 2, name: '视频信号丢失', deviceType: 'camera', level: 'error', condition: 'signal == 0', status: true },
|
||||
{ id: 3, name: '电池低电量', deviceType: 'battery', level: 'info', condition: 'power < 20', status: false },
|
||||
];
|
||||
|
||||
const AlarmRules = () => {
|
||||
const [list, setList] = useState(mockRules);
|
||||
const [filteredList, setFilteredList] = useState(mockRules);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
// 搜索筛选
|
||||
const handleSearch = (value: string) => {
|
||||
const res = list.filter(item =>
|
||||
item.name.includes(value) ||
|
||||
item.deviceType.includes(value) ||
|
||||
item.condition.includes(value)
|
||||
);
|
||||
setFilteredList(res);
|
||||
};
|
||||
|
||||
// 打开新增
|
||||
const openAdd = () => {
|
||||
setEditingId(null);
|
||||
form.resetFields();
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 打开编辑
|
||||
const openEdit = (record: any) => {
|
||||
setEditingId(record.id);
|
||||
form.setFieldsValue(record);
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 保存(新增 + 编辑)
|
||||
const handleSave = () => {
|
||||
form.validateFields().then(values => {
|
||||
if (editingId !== null) {
|
||||
// 编辑
|
||||
const updated = list.map(item =>
|
||||
item.id === editingId ? { ...item, ...values } : item
|
||||
);
|
||||
setList(updated);
|
||||
setFilteredList(updated);
|
||||
} else {
|
||||
// 新增
|
||||
const newRule = { ...values, id: Date.now() };
|
||||
const newList = [...list, newRule];
|
||||
setList(newList);
|
||||
setFilteredList(newList);
|
||||
}
|
||||
setModalVisible(false);
|
||||
});
|
||||
};
|
||||
|
||||
// 删除
|
||||
const handleDelete = (id: number) => {
|
||||
const newList = list.filter(x => x.id !== id);
|
||||
setList(newList);
|
||||
setFilteredList(newList);
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{ title: '规则名称', dataIndex: 'name' },
|
||||
{ title: '设备类型', dataIndex: 'deviceType' },
|
||||
{
|
||||
title: '告警级别',
|
||||
render: (r: any) => {
|
||||
const color = r.level === 'error' ? 'red' : r.level === 'warn' ? 'orange' : 'blue';
|
||||
const text = r.level === 'error' ? '严重' : r.level === 'warn' ? '警告' : '提示';
|
||||
return <Tag color={color}>{text}</Tag>;
|
||||
}
|
||||
},
|
||||
{ title: '触发条件', dataIndex: 'condition' },
|
||||
{
|
||||
title: '状态',
|
||||
render: (r: any) => (
|
||||
<Badge status={r.status ? 'success' : 'error'} text={r.status ? '启用' : '禁用'} />
|
||||
)
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (r: any) => (
|
||||
<Space>
|
||||
<Button type="link" icon={<EditOutlined />} onClick={() => openEdit(r)}>编辑</Button>
|
||||
<Popconfirm
|
||||
title="确定删除这条规则吗?"
|
||||
onConfirm={() => handleDelete(r.id)}
|
||||
>
|
||||
<Button type="link" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<AntdCard
|
||||
title="告警规则"
|
||||
extra={
|
||||
<Space>
|
||||
{/* 修复:使用 Input.Search */}
|
||||
<Search
|
||||
placeholder="搜索规则名称/设备/条件"
|
||||
style={{ width: 260 }}
|
||||
onSearch={handleSearch}
|
||||
/>
|
||||
<Button icon={<PlusOutlined />} type="primary" onClick={openAdd}>
|
||||
新增规则
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={filteredList}
|
||||
pagination={{ pageSize: 10 }}
|
||||
/>
|
||||
</AntdCard>
|
||||
|
||||
{/* 新增/编辑 弹窗 */}
|
||||
<Modal
|
||||
title={editingId ? '编辑告警规则' : '新增告警规则'}
|
||||
open={modalVisible}
|
||||
onCancel={() => setModalVisible(false)}
|
||||
onOk={handleSave}
|
||||
maskClosable={false}
|
||||
>
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item label="规则名称" name="name" rules={[{ required: true, message: '请输入规则名称' }]}>
|
||||
<Input placeholder="例如:温度超温告警" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="设备类型" name="deviceType" rules={[{ required: true }]}>
|
||||
<Select>
|
||||
<Select.Option value="sensor">传感器</Select.Option>
|
||||
<Select.Option value="camera">摄像头</Select.Option>
|
||||
<Select.Option value="battery">电池设备</Select.Option>
|
||||
<Select.Option value="inverter">逆变器</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="告警级别" name="level" rules={[{ required: true }]}>
|
||||
<Select>
|
||||
<Select.Option value="error">严重</Select.Option>
|
||||
<Select.Option value="warn">警告</Select.Option>
|
||||
<Select.Option value="info">提示</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="触发条件" name="condition" rules={[{ required: true }]}>
|
||||
<Input placeholder="例如:temp > 60 / power < 20" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="是否启用" name="status" valuePropName="checked">
|
||||
<Switch checkedChildren="启用" unCheckedChildren="禁用" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AlarmRules;
|
||||
129
src/components/alerts/AlarmStatistics.tsx
Normal file
129
src/components/alerts/AlarmStatistics.tsx
Normal file
@@ -0,0 +1,129 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { Card, Row, Col, Space } from 'antd';
|
||||
import { AreaChartOutlined } from '@ant-design/icons';
|
||||
import * as echarts from 'echarts';
|
||||
|
||||
const AntdCard = Card as any;
|
||||
|
||||
const AlarmStatistics = () => {
|
||||
// 图表 ref
|
||||
const barChartRef = useRef(null);
|
||||
const pieChartRef = useRef(null);
|
||||
|
||||
// 柱状图
|
||||
useEffect(() => {
|
||||
if (!barChartRef.current) return;
|
||||
const barChart = echarts.init(barChartRef.current);
|
||||
barChart.setOption({
|
||||
title: { text: '近7天告警趋势' },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: ['1日', '2日', '3日', '4日', '5日', '6日', '7日']
|
||||
},
|
||||
yAxis: { type: 'value' },
|
||||
series: [
|
||||
{
|
||||
data: [5, 8, 12, 9, 15, 7, 12],
|
||||
type: 'bar',
|
||||
itemStyle: { color: '#1677ff' }
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const resizeFn = () => barChart.resize();
|
||||
window.addEventListener('resize', resizeFn);
|
||||
|
||||
return () => {
|
||||
barChart.dispose();
|
||||
window.removeEventListener('resize', resizeFn);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 饼图
|
||||
useEffect(() => {
|
||||
if (!pieChartRef.current) return;
|
||||
const pieChart = echarts.init(pieChartRef.current);
|
||||
pieChart.setOption({
|
||||
title: { text: '告警级别分布' },
|
||||
tooltip: { trigger: 'item' },
|
||||
series: [
|
||||
{
|
||||
type: 'pie',
|
||||
radius: '50%',
|
||||
data: [
|
||||
{ value: 15, name: '严重告警' },
|
||||
{ value: 30, name: '警告告警' },
|
||||
{ value: 25, name: '提示告警' }
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const resizeFn = () => pieChart.resize();
|
||||
window.addEventListener('resize', resizeFn);
|
||||
|
||||
return () => {
|
||||
pieChart.dispose();
|
||||
window.removeEventListener('resize', resizeFn);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
{/* 顶部统计卡片 保留你原来的图标样式 */}
|
||||
<AntdCard title="告警概览" style={{ marginBottom: 24 }}>
|
||||
<Row gutter={16}>
|
||||
<Col span={8}>
|
||||
<Space>
|
||||
<div style={{ background: '#e6f4ff', padding: 8, borderRadius: 8 }}>
|
||||
<AreaChartOutlined style={{ color: '#1677ff', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ color: '#666' }}>今日告警</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 18 }}>12</div>
|
||||
</div>
|
||||
</Space>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Space>
|
||||
<div style={{ background: '#fff7e6', padding: 8, borderRadius: 8 }}>
|
||||
<AreaChartOutlined style={{ color: '#fa8c16', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ color: '#666' }}>本周告警</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 18 }}>45</div>
|
||||
</div>
|
||||
</Space>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Space>
|
||||
<div style={{ background: '#f6ffed', padding: 8, borderRadius: 8 }}>
|
||||
<AreaChartOutlined style={{ color: '#52c41a', fontSize: 20 }} />
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ color: '#666' }}>本月告警</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 18 }}>128</div>
|
||||
</div>
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 两个图表 左右各一半 并排显示 不空洞 */}
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<AntdCard title="告警趋势统计">
|
||||
<div ref={barChartRef} style={{ width: '100%', height: 350 }} />
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<AntdCard title="告警分类统计">
|
||||
<div ref={pieChartRef} style={{ width: '100%', height: 350 }} />
|
||||
</AntdCard>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AlarmStatistics;
|
||||
168
src/components/alerts/AlarmSubscription.tsx
Normal file
168
src/components/alerts/AlarmSubscription.tsx
Normal file
@@ -0,0 +1,168 @@
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Space, Popconfirm, Tag,
|
||||
Modal, Form, Input, Select
|
||||
} from 'antd';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||
|
||||
const AntdCard = Card as any;
|
||||
const { Option } = Select;
|
||||
const { Search } = Input;
|
||||
|
||||
// 模拟数据
|
||||
const mockSub = [
|
||||
{ id: 1, name: '运维订阅', deviceType: 'all', level: 'all', channels: ['短信'] },
|
||||
{ id: 2, name: '管理员订阅', deviceType: 'sensor', level: 'error', channels: ['短信', '邮件'] },
|
||||
{ id: 3, name: '设备订阅', deviceType: 'camera', level: 'warn', channels: ['APP推送'] },
|
||||
];
|
||||
|
||||
const AlarmSubscription = () => {
|
||||
const [list, setList] = useState(mockSub);
|
||||
const [filteredList, setFilteredList] = useState(mockSub);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [editingId, setEditingId] = useState<number | null>(null);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
// 搜索筛选
|
||||
const handleSearch = (value) => {
|
||||
const res = list.filter(item =>
|
||||
item.name.includes(value) ||
|
||||
item.deviceType.includes(value) ||
|
||||
item.level.includes(value)
|
||||
);
|
||||
setFilteredList(res);
|
||||
};
|
||||
|
||||
// 打开新增
|
||||
const openAdd = () => {
|
||||
setEditingId(null);
|
||||
form.resetFields();
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 打开编辑(回填数据)
|
||||
const openEdit = (record) => {
|
||||
setEditingId(record.id);
|
||||
form.setFieldsValue(record);
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
// 保存(新增+编辑)
|
||||
const handleSave = () => {
|
||||
form.validateFields().then(values => {
|
||||
if (editingId !== null) {
|
||||
// 编辑
|
||||
const updated = list.map(item =>
|
||||
item.id === editingId ? { ...item, ...values } : item
|
||||
);
|
||||
setList(updated);
|
||||
setFilteredList(updated);
|
||||
} else {
|
||||
// 新增
|
||||
const newItem = { ...values, id: Date.now() };
|
||||
const newList = [...list, newItem];
|
||||
setList(newList);
|
||||
setFilteredList(newList);
|
||||
}
|
||||
setModalVisible(false);
|
||||
});
|
||||
};
|
||||
|
||||
// 删除
|
||||
const handleDelete = (id) => {
|
||||
const newList = list.filter(x => x.id !== id);
|
||||
setList(newList);
|
||||
setFilteredList(newList);
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{ title: '订阅名称', dataIndex: 'name' },
|
||||
{ title: '设备类型', dataIndex: 'deviceType' },
|
||||
{ title: '告警级别', dataIndex: 'level' },
|
||||
{
|
||||
title: '通知渠道',
|
||||
render: (r) => r.channels.map(i => <Tag key={i}>{i}</Tag>)
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
render: (r) => (
|
||||
<Space>
|
||||
<Button type="link" icon={<EditOutlined />} onClick={() => openEdit(r)}>编辑</Button>
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(r.id)}>
|
||||
<Button type="link" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<AntdCard
|
||||
title="告警订阅"
|
||||
extra={
|
||||
<Space>
|
||||
<Search
|
||||
placeholder="搜索订阅/设备/级别"
|
||||
style={{ width: 260 }}
|
||||
onSearch={handleSearch}
|
||||
/>
|
||||
<Button icon={<PlusOutlined />} type="primary" onClick={openAdd}>
|
||||
新增订阅
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
dataSource={filteredList}
|
||||
pagination={{ pageSize: 10 }}
|
||||
/>
|
||||
</AntdCard>
|
||||
|
||||
{/* 新增/编辑 弹窗 */}
|
||||
<Modal
|
||||
title={editingId ? '编辑告警订阅' : '新增告警订阅'}
|
||||
open={modalVisible}
|
||||
onCancel={() => setModalVisible(false)}
|
||||
onOk={handleSave}
|
||||
maskClosable={false}
|
||||
>
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item label="订阅名称" name="name" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入订阅名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="设备类型" name="deviceType" rules={[{ required: true }]}>
|
||||
<Select>
|
||||
<Option value="all">全部设备</Option>
|
||||
<Option value="sensor">传感器</Option>
|
||||
<Option value="camera">摄像头</Option>
|
||||
<Option value="battery">电池设备</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="告警级别" name="level" rules={[{ required: true }]}>
|
||||
<Select>
|
||||
<Option value="all">全部级别</Option>
|
||||
<Option value="error">严重</Option>
|
||||
<Option value="warn">警告</Option>
|
||||
<Option value="info">提示</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="通知渠道" name="channels" rules={[{ required: true }]}>
|
||||
<Select mode="multiple" placeholder="请选择通知渠道">
|
||||
<Option value="短信">短信</Option>
|
||||
<Option value="邮件">邮件</Option>
|
||||
<Option value="APP推送">APP推送</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AlarmSubscription;
|
||||
Reference in New Issue
Block a user