This commit is contained in:
mmc
2026-05-07 17:09:19 +08:00
parent 9cf26ce2bd
commit 5ef889e435
5 changed files with 439 additions and 112 deletions

View File

@@ -1,21 +1,157 @@
import React from 'react';
import { Card, Row, Col, Space, Empty } from 'antd';
import { AlertOutlined, CloseCircleOutlined, ExclamationCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
import React, { useState } from 'react';
import {
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
Statistic, Typography, Tabs
} from 'antd';
import {
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined
} from '@ant-design/icons';
const AntdCard = Card as any;
const { RangePicker } = DatePicker;
const { Text } = Typography;
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>
);
// 级别 + 状态颜色
const levelColor = {
严重: 'red',
重要: 'orange',
一般: 'gold',
提示: 'blue'
};
export default AlarmOverview;
const statusColor = {
处理中: 'processing',
待处理: 'warning',
已关闭: 'success'
};
// 模拟数据
const mockAlerts = [
{ id: 'DEVICE_OFFLINE_CAM-02', content: '设备离线', device: 'CAM-02', level: '提示', time: '2026-04-28 17:22:04', duration: '1小时23分', status: '待处理', handler: '-' },
{ id: 'INV_TEMP_HIGH_INV-A02', content: '逆变器温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 17:21:54', duration: '1小时23分', status: '待处理', handler: '-' },
{ id: 'AL-20260428-001', content: 'INV-A02 温度过高', device: 'INV-A02', level: '重要', time: '2026-04-28 10:54:45', duration: '36分钟', status: '待处理', handler: '-' },
{ id: 'AL-20260428-002', content: 'CMB-A01 组串电流异常', device: 'CMB-A01', level: '一般', time: '2026-04-28 10:32:45', duration: '52分钟', status: '处理中', handler: '张运维' },
{ id: 'AL-20260428-003', content: 'CAM-02 视频离线', device: 'CAM-02', level: '提示', time: '2026-04-28 09:32:45', duration: '0分钟', status: '待处理', handler: '-' },
];
export default function AlarmCenterPage() {
const [selectedAlert, setSelectedAlert] = useState<any>(mockAlerts[0]);
const [detailVisible, setDetailVisible] = useState(true);
const columns = [
{ title: '告警编号', dataIndex: 'id', width: 180 },
{ title: '告警内容', dataIndex: 'content', ellipsis: true },
{ title: '来源设备', dataIndex: 'device', width: 120 },
{ title: '告警级别', dataIndex: 'level', width: 100, render: l => <Tag color={levelColor[l]}>{l}</Tag> },
{ title: '发生时间', dataIndex: 'time', width: 160 },
{ title: '持续时长', dataIndex: 'duration', width: 100 },
{ title: '处理状态', dataIndex: 'status', width: 100, render: s => <Tag color={statusColor[s]}>{s}</Tag> },
{ title: '负责人', dataIndex: 'handler', width: 100 },
{
title: '操作', width: 120,
render: (_, record) => (
<Space>
<Button type="link" onClick={() => { setSelectedAlert(record); setDetailVisible(true); }}>查看</Button>
<Button type="link">更多</Button>
</Space>
)
}
];
return (
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '0 24px 24px' }}>
{/* ===================== 统一宽度容器 ===================== */}
<div style={{ display: 'flex', gap: 16, marginTop: 16 }}>
{/* ===================== 左侧:所有模块宽度完全一致 ===================== */}
<div style={{ flex: 1 }}>
{/* 筛选卡片 */}
<Card style={{ borderRadius: 8, border: 'none', marginBottom: 16 }} bodyStyle={{ padding: '16px' }}>
<Row gutter={16} align="middle">
<Col><Select placeholder="告警级别" style={{ width: 120 }} /></Col>
<Col><Select placeholder="告警类型" style={{ width: 120 }} /></Col>
<Col><Select placeholder="设备类型" style={{ width: 120 }} /></Col>
<Col><RangePicker placeholder={['开始', '结束']} style={{ width: 240 }} /></Col>
<Col><Select placeholder="处理状态" style={{ width: 120 }} /></Col>
<Col flex="auto"><Input placeholder="搜索告警编号/内容/设备" style={{ width: '100%' }} /></Col>
<Col><Space><Button>重置</Button><Button type="primary">查询</Button></Space></Col>
</Row>
</Card>
{/* 统计卡片 */}
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="今日告警总数" value={5} prefix={<BellOutlined style={{ color: '#ff4d4f' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>昨日 28</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="严重告警" value={0} prefix={<ExclamationCircleOutlined style={{ color: '#ff4d4f' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>重要 2</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="处理中" value={1} prefix={<ClockCircleOutlined style={{ color: '#faad14' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>待处理 4</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="已关闭" value={0} prefix={<CheckCircleOutlined style={{ color: '#52c41a' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>闭环完成</div></Card></Col>
<Col span={4}><Card bordered={false} style={{ borderRadius: 8 }}><Statistic title="平均响应" value="49分钟" prefix={<ClockCircleOutlined style={{ color: '#1890ff' }} />} valueStyle={{ fontSize: 22 }} /><div style={{ fontSize: 12, color: '#999' }}>时间估算</div></Card></Col>
</Row>
{/* 告警列表(宽度 = 筛选卡片 完全一致) */}
<Card bordered={false} style={{ borderRadius: 8 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<div>
<Typography.Text strong style={{ fontSize: 16 }}>告警列表(共8条)</Typography.Text><br />
<Text type="secondary" style={{ fontSize: 12 }}>点击告警查看详情</Text>
</div>
</div>
<Table
rowKey="id"
columns={columns}
dataSource={mockAlerts}
pagination={{ pageSize: 8 }}
scroll={{ x: '100%' }}
style={{ width: '100%' }}
/>
</Card>
</div>
{/* ===================== 右侧详情面板 ===================== */}
{detailVisible && selectedAlert && (
<div style={{ width: 360, flexShrink: 0 }}>
<Card title="告警详情" bordered={false} style={{ borderRadius: 8, height: '100%' }}>
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<ExclamationCircleOutlined style={{ color: '#ff4d4f', marginRight: 8 }} />
<span style={{ fontSize: 16, fontWeight: 500 }}>{selectedAlert.content}</span>
</div>
<Tag color={levelColor[selectedAlert.level]}>{selectedAlert.level}</Tag>
</div>
<div style={{ fontSize: 12, color: '#999', marginTop: 4 }}>{selectedAlert.id}</div>
</div>
<div style={{ background: '#fafafa', borderRadius: 8, padding: 16, marginBottom: 16 }}>
<Row gutter={[16, 16]}>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>来源设备</div><div>{selectedAlert.device}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>发生时间</div><div>{selectedAlert.time}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>持续时长</div><div>{selectedAlert.duration}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#888' }}>处理状态</div><div>{selectedAlert.status}</div></Col>
</Row>
</div>
<div style={{ marginBottom: 16 }}>
<div style={{ fontWeight: 500, marginBottom: 8 }}>根因分析建议</div>
<div style={{ fontSize: 12, color: '#666', lineHeight: 1.7 }}>
设备离线/网络异常<br />
电源或通讯模块故障<br />
现场信号弱或采集器异常
</div>
</div>
<Space direction="vertical" style={{ width: '100%' }}>
<Button type="primary" block>确认告警</Button>
<Button block>标记处理中</Button>
<Button block danger>关闭告警</Button>
</Space>
</Card>
</div>
)}
</div>
</div>
);
}

View File

@@ -1,19 +1,20 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
Card, Table, Button, Space, Popconfirm, Tag, Badge,
Modal, Form, Input, Select, Switch
Modal, Form, Input, Select, Switch, message
} from 'antd';
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
// 从你的设备接入页面 导入 物模型数据
//import { modelList, modelDetailList } from './DeviceAccessPage';
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 },
{ id: 1, name: '温度超温', deviceType: 'sensor', modelId:11, propCode:'temp', level: 'warn', condition: 'temp > 60', status: true },
{ id: 2, name: '电池低电量', deviceType: 'battery', modelId:12, propCode:'battery', level: 'info', condition: 'battery < 20', status: false },
];
const AlarmRules = () => {
@@ -23,12 +24,18 @@ const AlarmRules = () => {
const [editingId, setEditingId] = useState<number | null>(null);
const [form] = Form.useForm();
// 搜索筛选
// 下拉选项
const [deviceTypeOpts, setDeviceTypeOpts] = useState([
{ value: 'sensor', label: '传感器' },
{ value: 'camera', label: '摄像头' },
{ value: 'battery', label: '电池设备' },
]);
const [propList, setPropList] = useState<any[]>([]);
// 搜索
const handleSearch = (value: string) => {
const res = list.filter(item =>
item.name.includes(value) ||
item.deviceType.includes(value) ||
item.condition.includes(value)
item.name.includes(value) || item.condition.includes(value)
);
setFilteredList(res);
};
@@ -44,25 +51,27 @@ const AlarmRules = () => {
const openEdit = (record: any) => {
setEditingId(record.id);
form.setFieldsValue(record);
loadProps(record.modelId);
setModalVisible(true);
};
// 保存(新增 + 编辑)
// 保存
const handleSave = () => {
form.validateFields().then(values => {
const data = {
...values,
condition: `${values.propCode} ${values.symbol} ${values.threshold}`
};
if (editingId !== null) {
// 编辑
const updated = list.map(item =>
item.id === editingId ? { ...item, ...values } : item
);
const updated = list.map(item => item.id === editingId ? { ...item, ...data } : item);
setList(updated);
setFilteredList(updated);
message.success('修改成功');
} else {
// 新增
const newRule = { ...values, id: Date.now() };
const newList = [...list, newRule];
setList(newList);
setFilteredList(newList);
const newRule = { ...data, id: Date.now() };
setList([...list, newRule]);
setFilteredList([...list, newRule]);
message.success('新增成功');
}
setModalVisible(false);
});
@@ -73,8 +82,25 @@ const AlarmRules = () => {
const newList = list.filter(x => x.id !== id);
setList(newList);
setFilteredList(newList);
message.success('删除成功');
};
// 加载物模型属性
const loadProps = (modelId: number) => {
//const detail = modelDetailList[modelId];
//if (detail?.props) {
// setPropList(detail.props.map(p => ({ value: p.code, label: p.name })));
//} else {
// setPropList([]);
//}
};
// 选择物模型后加载属性
//useEffect(() => {
// const modelId = form.getFieldValue('modelId');
// if (modelId) loadProps(modelId);
//}, [form.getFieldValue('modelId')]);
const columns = [
{ title: '规则名称', dataIndex: 'name' },
{ title: '设备类型', dataIndex: 'deviceType' },
@@ -82,28 +108,21 @@ const AlarmRules = () => {
title: '告警级别',
render: (r: any) => {
const color = r.level === 'error' ? 'red' : r.level === 'warn' ? 'orange' : 'blue';
const text = r.level === 'error' ? '严重' : r.level === 'warn' ? '警告' : '提示';
const text = { error:'严重', warn:'警告', info:'提示' }[r.level];
return <Tag color={color}>{text}</Tag>;
}
},
{ title: '触发条件', dataIndex: 'condition' },
{
title: '状态',
render: (r: any) => (
<Badge status={r.status ? 'success' : 'error'} text={r.status ? '启用' : '禁用'} />
)
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>
<Popconfirm onConfirm={() => handleDelete(r.id)}><Button type="link" danger>删除</Button></Popconfirm>
</Space>
)
}
@@ -112,51 +131,68 @@ const AlarmRules = () => {
return (
<div style={{ padding: 24 }}>
<AntdCard
title="告警规则"
title="告警规则配置"
extra={
<Space>
{/* 修复:使用 Input.Search */}
<Search
placeholder="搜索规则名称/设备/条件"
style={{ width: 260 }}
onSearch={handleSearch}
/>
<Button icon={<PlusOutlined />} type="primary" onClick={openAdd}>
新增规则
</Button>
<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 }}
/>
<Table rowKey="id" columns={columns} dataSource={filteredList} />
</AntdCard>
{/* 新增/编辑 弹窗 */}
<Modal
title={editingId ? '编辑告警规则' : '新增告警规则'}
title={editingId ? '编辑规则' : '新增规则'}
open={modalVisible}
onCancel={() => setModalVisible(false)}
onOk={handleSave}
maskClosable={false}
width={600}
>
<Form form={form} layout="vertical">
<Form.Item label="规则名称" name="name" rules={[{ required: true, message: '请输入规则名称' }]}>
<Input placeholder="例如:温度超温告警" />
<Form.Item label="规则名称" name="name" rules={[{ required: true }]}>
<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>
{deviceTypeOpts.map(o => <Select.Option key={o.value} value={o.value}>{o.label}</Select.Option>)}
</Select>
</Form.Item>
<Form.Item label="关联物模型" name="modelId" rules={[{ required: true }]}>
<Select
onChange={(val) => {
form.setFieldValue('modelId', val);
loadProps(val);
}}
>
{/*{modelList.map(m => (
<Select.Option key={m.id} value={m.id}>{m.name}</Select.Option>
))}*/}
</Select>
</Form.Item>
<Form.Item label="监控属性" name="propCode" rules={[{ required: true }]}>
<Select>
{propList.map(p => (
<Select.Option key={p.value} value={p.value}>{p.label}</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item label="比较符号" name="symbol" rules={[{ required: true }]}>
<Select style={{ width: 100 }}>
<Select.Option value=">">大于 </Select.Option>
<Select.Option value="<">小于 </Select.Option>
<Select.Option value="==">等于 ==</Select.Option>
</Select>
</Form.Item>
<Form.Item label="阈值" name="threshold" rules={[{ required: true }]}>
<Input placeholder="填写数值" />
</Form.Item>
<Form.Item label="告警级别" name="level" rules={[{ required: true }]}>
<Select>
<Select.Option value="error">严重</Select.Option>
@@ -165,12 +201,8 @@ const AlarmRules = () => {
</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 label="启用" name="status" valuePropName="checked">
<Switch />
</Form.Item>
</Form>
</Modal>