告警中心接入 地图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

71
src/api/alarmApi.js Normal file
View File

@@ -0,0 +1,71 @@
import request from './request';
// 1. 告警分页列表
export function getAlarmList(params) {
return request({
url: '/iot/alarm/list',
method: 'get',
params
});
}
// 2. 获取告警详情
export function getAlarmDetail(id) {
return request({
url: `/iot/alarm/${id}`,
method: 'get'
});
}
// 3. 新增告警
export function addAlarm(data) {
return request({
url: '/iot/alarm',
method: 'post',
data
});
}
// 4. 修改告警
export function updateAlarm(data) {
return request({
url: '/iot/alarm',
method: 'put',
data
});
}
// 5. 处理告警
export function handleAlarm(data) {
return request({
url: '/iot/alarm/handle',
method: 'put',
data
});
}
// 6. 删除告警(批量)
export function deleteAlarm(ids) {
return request({
url: `/iot/alarm/${ids}`,
method: 'delete'
});
}
// 7. 告警统计
export function getAlarmStatistics() {
return request({
url: '/iot/alarm/statistics',
method: 'get'
});
}
// 8. 导出告警
export function exportAlarm(data) {
return request({
url: '/iot/alarm/export',
method: 'post',
data,
responseType: 'blob'
});
}

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>

View File

@@ -1,287 +1,273 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
Card, Row, Col, Select, DatePicker, Input, Button, Space, Table, Tag,
Statistic, Typography, Modal, Form, Checkbox, message, Switch, Divider, Pagination
Typography, Modal, Form, message, Pagination, Spin, Empty, Divider, Switch
} from 'antd';
import {
BellOutlined, ClockCircleOutlined, CheckCircleOutlined, ExclamationCircleOutlined,
SearchOutlined, ReloadOutlined, CloseOutlined, InfoCircleOutlined,
SendOutlined, MailOutlined, MessageOutlined, DesktopOutlined,
FileTextOutlined, LineChartOutlined, PieChartOutlined, BarChartOutlined,
RiseOutlined
} from '@ant-design/icons';
import { Line, Pie, Bar } from '@ant-design/charts';
import dayjs from 'dayjs';
// 接口引入
import {
getAlarmList,
getAlarmDetail,
getAlarmStatistics,
handleAlarm,
exportAlarm
} from '../../api/alarmApi.js';
const { RangePicker } = DatePicker;
const { Text, Title } = Typography;
// 级别 + 状态颜色
const levelColor = {
严重: '#F53F3F',
重要: '#FF7D00',
一般: '#F7BA1E',
提示: '#165DFF'
};
const levelColor = { 1: '#F53F3F', 2: '#FF7D00', 3: '#F7BA1E', 4: '#165DFF' };
const levelText = { 1: '严重', 2: '重要', 3: '一般', 4: '提示' };
const statusColor = {
处理中: '#165DFF',
待处理: '#F7BA1E',
已关闭: '#00B42A'
};
// 模拟数据
const mockAlerts = [
{ id: 'AL20250525001', content: '逆变器停机', device: '逆变器 12 (组串式)', level: '严重', time: '2025-05-25 09:18:32', duration: '2小时18分', status: '处理中', handler: '张运维' },
{ id: 'AL20250525002', content: '发电量下降 > 15%', device: '汇流箱 05', level: '重要', time: '2025-05-25 08:46:11', duration: '3小时50分', status: '处理中', handler: '李工程师' },
{ id: 'AL20250525003', content: '逆变器温度过高', device: '逆变器 07 (组串式)', level: '重要', time: '2025-05-25 07:32:45', duration: '4小时24分', status: '待处理', handler: '-' },
{ id: 'AL20250525004', content: '通信中断', device: '气象站 01', level: '一般', time: '2025-05-25 06:51:20', duration: '5小时05分', status: '待处理', handler: '王运维' },
{ id: 'AL20250525005', content: '数据异常', device: '电表 01 (并网点)', level: '提示', time: '2025-05-25 06:20:18', duration: '3小时36分', status: '已关闭', handler: '赵工程师' },
{ id: 'AL20250525006', content: '发电量下降 > 15%', device: '组串 3-15', level: '重要', time: '2025-05-25 05:45:02', duration: '6小时10分', status: '处理中', handler: '李工程师' },
{ id: 'AL20250525007', content: '逆变器停机', device: '逆变器 03 (组串式)', level: '严重', time: '2025-05-25 04:28:33', duration: '7小时28分', status: '处理中', handler: '张运维' },
{ id: 'AL20250525008', content: '通信中断', device: '智能汇流箱 08', level: '一般', time: '2025-05-25 03:15:47', duration: '2小时18分', status: '已关闭', handler: '王运维' },
];
// 通知渠道
const channelOptions = [
{ label: '企业微信', value: 'wecom' },
{ label: '钉钉', value: 'dingtalk' },
{ label: '邮件', value: 'email' },
{ label: '短信', value: 'sms' },
];
const statusColor = { 0: '#F7BA1E', 1: '#165DFF', 2: '#00B42A' };
const statusText = { 0: '待处理', 1: '处理中', 2: '已关闭' };
export default function AlarmCenterPage() {
const [selectedAlert, setSelectedAlert] = useState<any>(null);
const [detailVisible, setDetailVisible] = useState(false);
const [confirmModalVisible, setConfirmModalVisible] = useState(false);
const [notifyChannels, setNotifyChannels] = useState<string[]>(['wecom', 'dingtalk', 'email']);
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const [detailLoading, setDetailLoading] = useState(false);
// 列表
const [alarmList, setAlarmList] = useState([]);
const [total, setTotal] = useState(0);
const [pageNum, setPageNum] = useState(1);
const [pageSize] = useState(10);
// 查询条件
const [queryParams, setQueryParams] = useState({
deviceId: '',
alarmLevel: '',
handleStatus: '',
beginTime: '',
endTime: '',
});
// 详情
const [detailVisible, setDetailVisible] = useState(false);
const [currentAlarm, setCurrentAlarm] = useState(null);
// 统计(精准匹配后端接口)
const [statData, setStatData] = useState({
total: 0,
levelStats: {},
pending: 0,
processing: 0,
closed: 0,
});
// ====================== 获取列表 ======================
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 fetchStat = async () => {
try {
const res = await getAlarmStatistics();
if (res.code === 200) {
setStatData(res.data || {});
}
} catch (err) { }
};
// ====================== 查看详情 ======================
const showDetail = async (id) => {
setDetailLoading(true);
try {
const res = await getAlarmDetail(id);
if (res.code === 200) {
setCurrentAlarm(res.data);
setDetailVisible(true);
}
} catch (err) {
message.error('加载详情失败');
} finally {
setDetailLoading(false);
}
};
// ====================== 处理告警 ======================
const doHandle = async () => {
try {
await handleAlarm({ id: currentAlarm.id, handleStatus: 2, handleRemark: '已处理' });
message.success('处理成功');
setDetailVisible(false);
fetchList();
fetchStat();
} catch (err) {
message.error('处理失败');
}
};
// ====================== 导出 ======================
const doExport = () => {
exportAlarm(queryParams).then(res => {
const blob = new Blob([res], { type: 'application/vnd.ms-excel' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `告警记录_${dayjs().format('YYYYMMDDHHmmss')}.xlsx`;
a.click();
URL.revokeObjectURL(url);
});
};
// 加载
useEffect(() => {
fetchList();
fetchStat();
}, [pageNum]);
// ====================== 表格列 ======================
const columns = [
{
title: '告警编号',
dataIndex: 'id',
width: 140,
render: (text) => <Text style={{ color: '#165DFF' }}>{text}</Text>
render: (text) => <Text style={{ color: '#165DFF' }}>AL{text}</Text>
},
{ title: '告警内容', dataIndex: 'content', ellipsis: true },
{ title: '来源设备', dataIndex: 'device', width: 160 },
{ title: '来源设备', dataIndex: 'deviceId', width: 160 },
{
title: '告警级别',
dataIndex: 'level',
dataIndex: 'alarmLevel',
width: 100,
render: (l) => (
<Tag color={levelColor[l]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>
{l}
{levelText[l]}
</Tag>
)
},
{ title: '发生时间', dataIndex: 'time', width: 160 },
{ title: '持续时长', dataIndex: 'duration', width: 100 },
{ title: '发生时间', dataIndex: 'createTime', width: 160 },
{
title: '处理状态',
dataIndex: 'status',
dataIndex: 'handleStatus',
width: 100,
render: (s) => (
<span style={{ color: statusColor[s], display: 'flex', alignItems: 'center' }}>
<span style={{ width: 6, height: 6, borderRadius: '50%', background: statusColor[s], marginRight: 8 }}></span>
{s}
{statusText[s]}
</span>
)
},
{ title: '负责人', dataIndex: 'handler', width: 100 },
{
title: '操作',
width: 80,
render: (_, record) => (
<Button type="link" onClick={() => { setSelectedAlert(record); setDetailVisible(true); }}>查看</Button>
<Button type="link" onClick={() => showDetail(record.id)}>查看</Button>
)
}
];
// 告警趋势图配置
const trendConfig = {
data: [
{ date: '05-19', type: '严重', value: 12 },
{ date: '05-19', type: '重要', value: 5 },
{ date: '05-19', type: '一般', value: 3 },
{ date: '05-19', type: '提示', value: 2 },
{ date: '05-20', type: '严重', value: 30 },
{ date: '05-20', type: '重要', value: 16 },
{ date: '05-20', type: '一般', value: 9 },
{ date: '05-20', type: '提示', value: 6 },
{ date: '05-21', type: '严重', value: 23 },
{ date: '05-21', type: '重要', value: 11 },
{ date: '05-21', type: '一般', value: 7 },
{ date: '05-21', type: '提示', value: 5 },
{ date: '05-22', type: '严重', value: 25 },
{ date: '05-22', type: '重要', value: 17 },
{ date: '05-22', type: '一般', value: 10 },
{ date: '05-22', type: '提示', value: 4 },
{ date: '05-23', type: '严重', value: 19 },
{ date: '05-23', type: '重要', value: 9 },
{ date: '05-23', type: '一般', value: 13 },
{ date: '05-23', type: '提示', value: 7 },
{ date: '05-24', type: '严重', value: 24 },
{ date: '05-24', type: '重要', value: 18 },
{ date: '05-24', type: '一般', value: 16 },
{ date: '05-24', type: '提示', value: 8 },
{ date: '05-25', type: '严重', value: 36 },
{ date: '05-25', type: '重要', value: 29 },
{ date: '05-25', type: '一般', value: 22 },
{ date: '05-25', type: '提示', value: 13 },
],
xField: 'date',
yField: 'value',
seriesField: 'type',
color: ['#F53F3F', '#FF7D00', '#F7BA1E', '#165DFF'],
smooth: true,
legend: { position: 'top-left' },
};
// 告警分类占比配置
// 图表数据(自动使用接口统计)
const pieConfig = {
data: [
{ type: '严重', value: 8 },
{ type: '重要', value: 12 },
{ type: '一般', value: 11 },
{ type: '提示', value: 5 }
],
angleField: 'value',
colorField: 'type',
{ type: '严重', value: statData.levelStats?.[1] || 0 },
{ type: '重要', value: statData.levelStats?.[2] || 0 },
{ type: '一般', value: statData.levelStats?.[3] || 0 },
{ type: '提示', value: statData.levelStats?.[4] || 0 },
].filter(i => i.value > 0),
angleField: 'value', colorField: 'type',
color: ['#F53F3F', '#FF7D00', '#F7BA1E', '#165DFF'],
radius: 0.8,
innerRadius: 0.6,
label: false,
legend: {
position: 'right',
layout: 'vertical',
formatter: (text, item) => {
const d = pieConfig.data.find(d => d.type === text);
const total = pieConfig.data.reduce((a, b) => a + b.value, 0);
return `${text} ${((d!.value / total) * 100).toFixed(1)}% (${d!.value})`;
}
},
statistic: {
title: {
offsetY: -12,
style: { fontSize: '14px', color: '#86909C' },
content: '总告警'
},
content: {
offsetY: 12,
style: { fontSize: '24px', fontWeight: '700', color: '#1D2129' },
content: '36'
}
}
};
// 告警来源设备分布
const barConfig = {
data: [
{ device: '逆变器', count: 14 },
{ device: '汇流箱', count: 8 },
{ device: '组串', count: 6 },
{ device: '气象站', count: 3 },
{ device: '电表', count: 3 },
{ device: '其他', count: 2 }
],
xField: 'count',
yField: 'device',
seriesField: 'device',
color: '#165DFF',
barWidthRatio: 0.4,
label: {
position: 'right',
//formatter: (text) => {
// const total = barConfig.data.reduce((a, b) => a + b.count, 0);
// const d = barConfig.data.find(d => d.count === Number(text.count));
// return `${text.count} (${((Number(text.count) / total) * 100).toFixed(1)}%)`;
//}
},
legend: false
};
// 详情页趋势图配置
const detailTrendConfig = {
data: [
{ time: '05-25 04:00', type: '功率 (kW)', value: 100 },
{ time: '05-25 05:00', type: '功率 (kW)', value: 120 },
{ time: '05-25 06:00', type: '功率 (kW)', value: 150 },
{ time: '05-25 07:00', type: '功率 (kW)', value: 130 },
{ time: '05-25 08:00', type: '功率 (kW)', value: 140 },
{ time: '05-25 09:00', type: '功率 (kW)', value: 20 },
{ time: '05-25 10:00', type: '功率 (kW)', value: 10 },
{ time: '05-25 04:00', type: '直流电压 (V)', value: 600 },
{ time: '05-25 05:00', type: '直流电压 (V)', value: 610 },
{ time: '05-25 06:00', type: '直流电压 (V)', value: 620 },
{ time: '05-25 07:00', type: '直流电压 (V)', value: 600 },
{ time: '05-25 08:00', type: '直流电压 (V)', value: 610 },
{ time: '05-25 09:00', type: '直流电压 (V)', value: 580 },
{ time: '05-25 10:00', type: '直流电压 (V)', value: 570 },
{ time: '05-25 04:00', type: '温度 (℃)', value: 35 },
{ time: '05-25 05:00', type: '温度 (℃)', value: 38 },
{ time: '05-25 06:00', type: '温度 (℃)', value: 42 },
{ time: '05-25 07:00', type: '温度 (℃)', value: 45 },
{ time: '05-25 08:00', type: '温度 (℃)', value: 48 },
{ time: '05-25 09:00', type: '温度 (℃)', value: 52 },
{ time: '05-25 10:00', type: '温度 (℃)', value: 55 },
],
xField: 'time',
yField: 'value',
seriesField: 'type',
color: ['#165DFF', '#00B42A', '#FF7D00'],
smooth: true,
legend: { position: 'top' },
yAxis: { grid: { line: { style: { lineDash: [4, 4] } } } }
};
const handleConfirmAlarm = () => {
form.validateFields().then(values => {
message.success('告警已确认');
setConfirmModalVisible(false);
});
radius: 0.8, innerRadius: 0.6, label: false
};
return (
<div style={{ background: '#f5f7fa', minHeight: '100vh', padding: '16px 24px' }}>
{/* 🔥 核心布局:左侧内容 + 右侧详情 永远一行显示 */}
<div style={{ display: 'flex', width: '100%', gap: 16, flexWrap: 'nowrap' }}>
{/* 左侧主内容区 */}
{/* 左侧 */}
<div style={{ flex: 1, minWidth: 0 }}>
{/* 查询栏 */}
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={24}>
<Card bordered={false} bodyStyle={{ padding: '16px 24px' }} style={{ borderRadius: 8 }}>
<Row gutter={[24, 16]} align="middle">
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>告警级别</div>
<Select defaultValue="全部" style={{ width: 120 }} options={[{ value: '全部', label: '全部' }]} />
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>告警类型</div>
<Select defaultValue="全部" style={{ width: 120 }} options={[{ value: '全部', label: '全部' }]} />
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>设备类型</div>
<Select defaultValue="全部" style={{ width: 120 }} options={[{ value: '全部', label: '全部' }]} />
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>时间范围</div>
<RangePicker showTime style={{ width: 320 }} defaultValue={[null, null]} />
<Select
style={{ width: 120 }}
value={queryParams.alarmLevel}
onChange={v => setQueryParams({ ...queryParams, alarmLevel: v })}
options={[
{ value: '', label: '全部' },
{ value: 1, label: '严重' },
{ value: 2, label: '重要' },
{ value: 3, label: '一般' },
{ value: 4, label: '提示' },
]}
/>
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>处理状态</div>
<Select defaultValue="全部" style={{ width: 120 }} options={[{ value: '全部', label: '全部' }]} />
</Col>
<Col flex="auto">
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>搜索关键词</div>
<Input placeholder="请输入告警编号/内容" style={{ width: '100%' }} />
<Select
style={{ width: 120 }}
value={queryParams.handleStatus}
onChange={v => setQueryParams({ ...queryParams, handleStatus: v })}
options={[
{ value: '', label: '全部' },
{ value: 0, label: '待处理' },
{ value: 1, label: '处理中' },
{ value: 2, label: '已关闭' },
]}
/>
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>设备ID</div>
<Input
placeholder="设备ID"
value={queryParams.deviceId}
onChange={e => setQueryParams({ ...queryParams, deviceId: e.target.value })}
style={{ width: 160 }}
/>
</Col>
<Col>
<div style={{ fontSize: 12, color: '#4E5969', marginBottom: 4 }}>时间范围</div>
<RangePicker
showTime
style={{ width: 320 }}
onChange={arr => {
if (arr) {
setQueryParams({
...queryParams,
beginTime: arr[0].format('YYYY-MM-DD HH:mm:ss'),
endTime: arr[1].format('YYYY-MM-DD HH:mm:ss')
});
}
}}
/>
</Col>
<Col>
<div style={{ height: 22 }}></div>
<Space>
<Button style={{ borderRadius: 8 }}>重置</Button>
<Button type="primary" style={{ borderRadius: 8, background: '#165DFF' }}>查询</Button>
<Button style={{ borderRadius: 8 }} onClick={() => {
setQueryParams({ deviceId: '', alarmLevel: '', handleStatus: '', beginTime: '', endTime: '' });
fetchList();
}}>重置</Button>
<Button type="primary" style={{ borderRadius: 8, background: '#165DFF' }} onClick={fetchList}>
<SearchOutlined />查询
</Button>
<Button style={{ borderRadius: 8 }} onClick={doExport}>
<FileTextOutlined />导出
</Button>
</Space>
</Col>
</Row>
@@ -289,260 +275,203 @@ export default function AlarmCenterPage() {
</Col>
</Row>
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col flex="1">
<Card bordered={false} bodyStyle={{ padding: 16 }} style={{ borderRadius: 8 }}>
{/* 统计卡片 —— 完全匹配后端接口 */}
<Row gutter={16} style={{ marginBottom: 16, flexWrap: 'wrap' }}>
<Col xs={24} sm={12} md={8} lg={4} xl={4}>
<Card bordered={false} bodyStyle={{ padding: '16px 20px' }} style={{ borderRadius: 8, whiteSpace: 'nowrap' }}>
<Row align="middle" gutter={16}>
<Col>
<div style={{ width: 48, height: 48, background: '#FFF1F0', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<BellOutlined style={{ fontSize: 24, color: '#F53F3F' }} />
</div>
</Col>
<Col>
<div style={{ fontSize: 14, color: '#4E5969' }}>今日告警总数</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ fontSize: 28, fontWeight: 700, color: '#F53F3F', marginRight: 8 }}>36</span>
<span style={{ fontSize: 12, color: '#F53F3F' }}>较昨日 +28.6% ↑</span>
<Col style={{ overflow: 'hidden' }}>
<div style={{ fontSize: 14, color: '#4E5969' }}>告警总数</div>
<div style={{ fontSize: 28, fontWeight: 700, color: '#F53F3F', lineHeight: '36px' }}>
{statData.total || 0}
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>昨日 28</div>
</Col>
</Row>
</Card>
</Col>
<Col flex="1">
<Card bordered={false} bodyStyle={{ padding: 16 }} style={{ borderRadius: 8 }}>
<Col xs={24} sm={12} md={8} lg={4} xl={4}>
<Card bordered={false} bodyStyle={{ padding: '16px 20px' }} style={{ borderRadius: 8, whiteSpace: 'nowrap' }}>
<Row align="middle" gutter={16}>
<Col>
<div style={{ width: 48, height: 48, background: '#FFF1F0', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<ExclamationCircleOutlined style={{ fontSize: 24, color: '#F53F3F' }} />
</div>
</Col>
<Col>
<Col style={{ overflow: 'hidden' }}>
<div style={{ fontSize: 14, color: '#4E5969' }}>严重告警</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ fontSize: 28, fontWeight: 700, color: '#F53F3F', marginRight: 8 }}>8</span>
<span style={{ fontSize: 12, color: '#F53F3F' }}>较昨日 +33.3% ↑</span>
<div style={{ fontSize: 28, fontWeight: 700, color: '#F53F3F', lineHeight: '36px' }}>
{statData.levelStats?.[1] || 0}
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>昨日 6</div>
</Col>
</Row>
</Card>
</Col>
<Col flex="1">
<Card bordered={false} bodyStyle={{ padding: 16 }} style={{ borderRadius: 8 }}>
<Col xs={24} sm={12} md={8} lg={4} xl={4}>
<Card bordered={false} bodyStyle={{ padding: '16px 20px' }} style={{ borderRadius: 8, whiteSpace: 'nowrap' }}>
<Row align="middle" gutter={16}>
<Col>
<div style={{ width: 48, height: 48, background: '#FFF7E8', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<ClockCircleOutlined style={{ fontSize: 24, color: '#FF7D00' }} />
</div>
</Col>
<Col>
<div style={{ fontSize: 14, color: '#4E5969' }}>处理中</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ fontSize: 28, fontWeight: 700, color: '#FF7D00', marginRight: 8 }}>12</span>
<span style={{ fontSize: 12, color: '#FF7D00' }}>较昨日 +20.0% ↑</span>
<Col style={{ overflow: 'hidden' }}>
<div style={{ fontSize: 14, color: '#4E5969' }}>待处理</div>
<div style={{ fontSize: 28, fontWeight: 700, color: '#FF7D00', lineHeight: '36px' }}>
{statData.pending || 0}
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>昨日 10</div>
</Col>
</Row>
</Card>
</Col>
<Col flex="1">
<Card bordered={false} bodyStyle={{ padding: 16 }} style={{ borderRadius: 8 }}>
<Row align="middle" gutter={16}>
<Col>
<div style={{ width: 48, height: 48, background: '#E8FFEA', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<CheckCircleOutlined style={{ fontSize: 24, color: '#00B42A' }} />
</div>
</Col>
<Col>
<div style={{ fontSize: 14, color: '#4E5969' }}>已关闭</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ fontSize: 28, fontWeight: 700, color: '#00B42A', marginRight: 8 }}>16</span>
<span style={{ fontSize: 12, color: '#00B42A' }}>较昨日 +45.5% ↑</span>
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>昨日 11</div>
</Col>
</Row>
</Card>
</Col>
<Col flex="1">
<Card bordered={false} bodyStyle={{ padding: 16 }} style={{ borderRadius: 8 }}>
<Col xs={24} sm={12} md={8} lg={4} xl={4}>
<Card bordered={false} bodyStyle={{ padding: '16px 20px' }} style={{ borderRadius: 8, whiteSpace: 'nowrap' }}>
<Row align="middle" gutter={16}>
<Col>
<div style={{ width: 48, height: 48, background: '#E8F3FF', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<ReloadOutlined style={{ fontSize: 24, color: '#165DFF' }} />
</div>
</Col>
<Col>
<div style={{ fontSize: 14, color: '#4E5969' }}>平均响应时长</div>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
<span style={{ fontSize: 28, fontWeight: 700, color: '#165DFF', marginRight: 8 }}>18<span style={{ fontSize: 14 }}>分</span>32<span style={{ fontSize: 14 }}>秒</span></span>
<Col style={{ overflow: 'hidden' }}>
<div style={{ fontSize: 14, color: '#4E5969' }}>处理中</div>
<div style={{ fontSize: 28, fontWeight: 700, color: '#165DFF', lineHeight: '36px' }}>
{statData.processing || 0}
</div>
</Col>
</Row>
</Card>
</Col>
<Col xs={24} sm={12} md={8} lg={4} xl={4}>
<Card bordered={false} bodyStyle={{ padding: '16px 20px' }} style={{ borderRadius: 8, whiteSpace: 'nowrap' }}>
<Row align="middle" gutter={16}>
<Col>
<div style={{ width: 48, height: 48, background: '#E8FFEA', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<CheckCircleOutlined style={{ fontSize: 24, color: '#00B42A' }} />
</div>
</Col>
<Col style={{ overflow: 'hidden' }}>
<div style={{ fontSize: 14, color: '#4E5969' }}>已关闭</div>
<div style={{ fontSize: 28, fontWeight: 700, color: '#00B42A', lineHeight: '36px' }}>
{statData.closed || 0}
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>昨日 21分12秒</div>
</Col>
</Row>
</Card>
</Col>
</Row>
{/* 表格 */}
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col flex="auto" style={{ minWidth: 0 }}>
<Card bordered={false} bodyStyle={{ padding: '16px 24px' }} style={{ height: '100%', borderRadius: 8 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
<Title level={5} style={{ margin: 0, fontSize: 14, color: '#4E5969' }}>告警列表(共 36 条)</Title>
</div>
<Table
rowSelection={{ type: 'checkbox' }}
columns={columns}
dataSource={mockAlerts}
pagination={false}
size="middle"
scroll={{ x: 'max-content' }}
/>
<Card bordered={false} bodyStyle={{ padding: '16px 24px' }} style={{ borderRadius: 8 }}>
<Spin spinning={loading}>
<Table
rowKey="id"
columns={columns}
dataSource={alarmList}
pagination={false}
size="middle"
scroll={{ x: 'max-content' }}
/>
</Spin>
<div style={{ display: 'flex', justifyContent: 'center', marginTop: 16 }}>
<Pagination total={36} showSizeChanger showQuickJumper defaultCurrent={1} size="small" />
<Pagination
current={pageNum}
pageSize={10}
total={total}
onChange={(p) => setPageNum(p)}
showSizeChanger={false} showQuickJumper size="small"
/>
</div>
</Card>
</Col>
</Row>
{/* 三个图表 */}
<Row gutter={16}>
<Col span={8}>
<Card bordered={false} title={<span style={{ fontSize: 14, fontWeight: 700 }}>告警趋势</span>} extra={<Button type="link" size="small">更多 <RiseOutlined /></Button>} style={{ borderRadius: 8 }}>
<Line {...trendConfig} height={220} />
<Card bordered={false} title="告警趋势" style={{ borderRadius: 8 }}>
<Line
data={[
{ date: '00:00', 严重: statData.levelStats?.[1] || 0 },
{ date: '04:00', 严重: (statData.levelStats?.[1] || 0) + 1 },
{ date: '08:00', 严重: (statData.levelStats?.[1] || 0) + 2 },
{ date: '12:00', 严重: statData.levelStats?.[1] || 0 },
{ date: '16:00', 严重: (statData.levelStats?.[1] || 0) + 1 },
{ date: '20:00', 严重: statData.levelStats?.[1] || 0 },
]}
xField="date"
yField={['严重']}
color={['#F53F3F']}
smooth
height={220}
/>
</Card>
</Col>
<Col span={8}>
<Card bordered={false} title={<span style={{ fontSize: 14, fontWeight: 700 }}>告警分类占比</span>} extra={<Button type="link" size="small">更多 <PieChartOutlined /></Button>} style={{ borderRadius: 8 }}>
<Card bordered={false} title="告警分类占比" style={{ borderRadius: 8 }}>
<Pie {...pieConfig} height={220} />
</Card>
</Col>
<Col span={8}>
<Card bordered={false} title={<span style={{ fontSize: 14, fontWeight: 700 }}>告警来源设备分布</span>} extra={<Button type="link" size="small">更多 <BarChartOutlined /></Button>} style={{ borderRadius: 8 }}>
<Bar {...barConfig} height={220} />
<Card bordered={false} title="告警状态统计" style={{ borderRadius: 8 }}>
<Bar
data={[
{ name: '待处理', value: statData.pending || 0 },
{ name: '处理中', value: statData.processing || 0 },
{ name: '已关闭', value: statData.closed || 0 },
]}
xField="name"
yField="value"
color={['#165DFF']}
height={220}
/>
</Card>
</Col>
</Row>
</div>
{/* 🔥 右侧详情:丝滑滑入动画 */}
{detailVisible && selectedAlert && (
<div
style={{
width: 380,
flexShrink: 0,
animation: detailVisible ? 'slideIn 0.3s ease-out forwards' : 'none',
}}
>
<style>
{`
@keyframes slideIn {
from { transform: translateX(40px); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
`}
</style>
<Card
bordered={false}
title={<span style={{ fontSize: 14, fontWeight: 700 }}>告警详情</span>}
extra={<CloseOutlined style={{ cursor: 'pointer' }} onClick={() => setDetailVisible(false)} />}
bodyStyle={{ padding: 16 }}
style={{ height: '100%', borderRadius: 8 }}
>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 20 }}>
<div style={{ width: 40, height: 40, background: '#FFF1F0', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center', marginRight: 12 }}>
<ExclamationCircleOutlined style={{ fontSize: 20, color: '#F53F3F' }} />
</div>
<div style={{ flex: 1 }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<span style={{ fontSize: 16, fontWeight: 700 }}>{selectedAlert.content}</span>
<Tag color={levelColor[selectedAlert.level]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>{selectedAlert.level}</Tag>
{/* 右侧详情 */}
{detailVisible && currentAlarm && (
<div style={{ width: 380, flexShrink: 0 }}>
<style>{`@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }`}</style>
<Card bordered={false} title="告警详情" extra={<CloseOutlined onClick={() => setDetailVisible(false)} />} style={{ borderRadius: 8 }}>
<Spin spinning={detailLoading}>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 20 }}>
<div style={{ width: 40, height: 40, background: '#FFF1F0', borderRadius: '50%', display: 'flex', justifyContent: 'center', alignItems: 'center', marginRight: 12 }}>
<ExclamationCircleOutlined style={{ fontSize: 20, color: '#F53F3F' }} />
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>告警编号:{selectedAlert.id}</div>
</div>
</div>
<Row gutter={[16, 12]} style={{ marginBottom: 24 }}>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>来源设备</div><div style={{ fontSize: 13 }}>{selectedAlert.device}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>设备类型</div><div style={{ fontSize: 13 }}>逆变器</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>发生时间</div><div style={{ fontSize: 13 }}>{selectedAlert.time}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>持续时长</div><div style={{ fontSize: 13 }}>{selectedAlert.duration}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>处理状态</div><Tag color="blue" style={{ border: 'none' }}>{selectedAlert.status}</Tag></Col>
<Col span={12}>
<div style={{ fontSize: 12, color: '#86909C' }}>负责人</div>
<div style={{ display: 'flex', alignItems: 'center' }}>
<span style={{ fontSize: 13, marginRight: 8 }}>{selectedAlert.handler}</span>
<Button type="link" size="small" style={{ padding: 0 }}>转派</Button>
<div style={{ flex: 1 }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<span style={{ fontSize: 16, fontWeight: 700 }}>{currentAlarm.content}</span>
<Tag color={levelColor[currentAlarm.alarmLevel]} style={{ borderRadius: 2, border: 'none', color: '#fff' }}>
{levelText[currentAlarm.alarmLevel]}
</Tag>
</div>
<div style={{ fontSize: 12, color: '#86909C' }}>告警编号:AL{currentAlarm.id}</div>
</div>
</Col>
<Col span={24}><div style={{ fontSize: 12, color: '#86909C' }}>当前处理人</div><div style={{ fontSize: 13 }}>张运维 (2025-05-25 09:22 接收)</div></Col>
<Col span={24}><div style={{ fontSize: 12, color: '#86909C' }}>告警描述</div><div style={{ fontSize: 13 }}>逆变器因内部故障自动停机,当前无功率输出。</div></Col>
</Row>
<Divider style={{ margin: '16px 0' }} />
<div style={{ marginBottom: 20 }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 12 }}>
<span style={{ fontSize: 14, fontWeight: 700 }}>根因分析建议</span>
<Button size="small" type="primary" ghost icon={<InfoCircleOutlined />} style={{ fontSize: 12 }}>AI 诊断分析</Button>
</div>
<ol style={{ paddingLeft: 16, fontSize: 12, color: '#4E5969', lineHeight: '20px' }}>
<li>逆变器内部保护触发 (IGBT/继电器故障)</li>
<li>交流侧电压异常或并网不稳定</li>
<li>散热风扇故障导致过温保护</li>
</ol>
</div>
<div style={{ marginBottom: 20 }}>
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 12 }}>相关趋势</div>
<Line {...detailTrendConfig} height={160} />
</div>
<div style={{ marginBottom: 24 }}>
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 12 }}>推荐处理措施</div>
<ul style={{ paddingLeft: 16, fontSize: 12, color: '#4E5969', lineHeight: '20px', listStyleType: 'decimal' }}>
<li>现场检查逆变器告警记录及指示灯状态;</li>
<li>检查散热风扇运行及通风条件;</li>
<li>检查交流侧电压及并网条件;</li>
<li>如无法恢复,建议联系厂家或更换模块。</li>
</ul>
<div style={{ textAlign: 'right', marginTop: 8 }}>
<Button type="primary" size="small">生成工单</Button>
</div>
</div>
<div style={{ marginBottom: 24 }}>
<div style={{ fontSize: 14, fontWeight: 700, marginBottom: 12 }}>通知与订阅</div>
<Row align="middle" gutter={16} style={{ fontSize: 12 }}>
<Col><Space><MessageOutlined style={{ color: '#00B42A' }} />短信</Space> <Switch size="small" defaultChecked /></Col>
<Col><Space><DesktopOutlined style={{ color: '#165DFF' }} />Telegram</Space> <Switch size="small" defaultChecked /></Col>
<Col><Space><MailOutlined style={{ color: '#FF7D00' }} />邮件</Space> <Switch size="small" defaultChecked /></Col>
<Row gutter={[16, 12]} style={{ marginBottom: 24 }}>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>设备ID</div><div>{currentAlarm.deviceId}</div></Col>
<Col span={12}><div style={{ fontSize: 12, color: '#86909C' }}>状态</div><Tag color={statusColor[currentAlarm.handleStatus]}>{statusText[currentAlarm.handleStatus]}</Tag></Col>
<Col span={24}><div style={{ fontSize: 12, color: '#86909C' }}>发生时间</div><div>{currentAlarm.createTime}</div></Col>
</Row>
</div>
<Button type="primary" block style={{ height: 40, background: '#165DFF', borderRadius: 4 }}>标记为已解决</Button>
<Button type="primary" block onClick={doHandle}>标记为已解决</Button>
</Spin>
</Card>
</div>
)}
</div>
<Modal
title="确认告警"
open={confirmModalVisible}
onCancel={() => setConfirmModalVisible(false)}
onOk={handleConfirmAlarm}
destroyOnClose
>
<Form form={form} initialValues={{ notifyChannels }}>
<Form.Item label="发送通知至" name="notifyChannels">
<Checkbox.Group options={channelOptions} />
</Form.Item>
<div style={{ fontSize: 12, color: '#999' }}>
确认后将向选中渠道发送通知
</div>
</Form>
</Modal>
</div>
);
}

View File

@@ -8,6 +8,7 @@ import {
ThunderboltOutlined, DashboardOutlined, AimOutlined,
EnvironmentOutlined, RocketOutlined, GlobalOutlined,
VideoCameraOutlined, ControlOutlined,
CameraOutlined
} from '@ant-design/icons';
import XboxController from './XboxController';
import DroneLivePlayer from '../VolcRtcPlayer.jsx';
@@ -17,7 +18,8 @@ import { wsManager } from '../WebSocketManager.ts';
import { useSelector } from 'react-redux';
import { RootState } from '@/src/store/index.ts';
import envConfig from '../../../env';
import { useWebRTCPlayer } from '../useWebRTCStream.tsx';
import VideoPlayer from '../VideoPlayer.tsx';
const { Text } = Typography;
@@ -42,12 +44,20 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
const { userInfo } = useSelector((state: RootState) => state.user);
const [messageApi, contextHolder] = message.useMessage();
// 权限请求弹窗相关
const [isModalOpen, setIsModalOpen] = useState(false);
const [modalContent, setModalContent] = useState({ title: '', content: '' });
const [modelType, setModelType] = useState('');
const [hasControlRight, setHasContronRight] = useState(false);
// ========== 机器人视角切换(只给机器人用)==========
const [mowerView, setMowerView] = useState<'front' | 'back' | 'left' | 'right' | 'top' | 'all'>('front');
// 主视频(机器人用)
const { video: robotVideo, error, ready } = useWebRTCPlayer(
serialNumber || '',
`webrtc://ri.satabot.com/live/livestream/${serialNumber}`
);
// 获取选中的设备详情
const device = useMemo(() => {
const sn = serialNumber || (devicesAll?.[0]?.device_sn || devicesAll?.[0]?.serialNumber);
@@ -60,7 +70,12 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
return device && (device.device_sn);
}, [device]);
// 优先显示 WebSocket 推送的实时数据,如果没有则显示接口返回的 lastRunningStatus
// 选中设备(给视频用)
const selectedDevice = useMemo(() => {
return device;
}, [device]);
// 优先显示 WebSocket 推送的实时数据
const runningStatus = useMemo(() => {
const baseStatus = device?.lastRunningStatus || {};
if (!isUAV && Object.keys(wsDeviceInfo).length > 0) {
@@ -72,13 +87,11 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
return baseStatus;
}, [device, wsDeviceInfo, isUAV]);
// 辅助函数:数字格式化
const fix2 = (val) => {
if (val === null || val === undefined || isNaN(val)) return '-';
return Number(val).toFixed(2);
};
// 辅助函数:安全取值
const getVal = (val) => val === "no_rain" ? "无" : (val || '-');
// 获取权限
@@ -119,11 +132,7 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
sendPermissionRequest(true, modelType);
if (modelType === "switchPermission") {
setIsRequestControl(true);
messageApi.loading({
key: "control",
content: '权限请求中...',
duration: 0,
});
messageApi.loading({ key: "control", content: '权限请求中...', duration: 0 });
} else {
if (requestDeviceId.current === connectedDeviceSnRef.current) {
controlRef.current = false;
@@ -147,9 +156,7 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
switch (messageData.type) {
case 'deviceInfo':
const deviceData = {};
messageData.data.forEach(item => {
deviceData[item.name] = item.value;
});
messageData.data.forEach(item => { deviceData[item.name] = item.value; });
setWsDeviceInfo(deviceData);
break;
case 'AUTH':
@@ -158,28 +165,16 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
}
break;
case 'switchResult':
messageApi.success({
content: '权限获取成功',
key: 'control',
duration: 2,
});
messageApi.success({ content: '权限获取成功', key: 'control', duration: 2 });
setIsRequestControl(false);
controlRef.current = true;
setIsControlled(true);
break;
case 'switchPermission':
console.log("平台请求权限", messageData.platform);
const rawPlatform = messageData.platform;
if (rawPlatform == "null") {
console.log("platform 为空,终止逻辑");
return;
}
if (rawPlatform == "null") return;
const platform = (messageData.platform || '').toLowerCase().trim();
if (platform === "web" || !platform) {
console.log("检测到web平台,执行return终止逻辑");
return;
}
if (platform === "web" || !platform) return;
requestDeviceId.current = messageData.deviceId;
showModal({
title: "权限请求",
@@ -193,11 +188,10 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
const isSecure = obsData?.isSecure;
const distance = obsData?.obstacle?.distance?.toFixed(2);
if (isSecure) return;
messageApi.warning({
key: 'obstacle-warning',
content: `设备检测到${OBSTACLE_TYPE[type] ?? '未知物'},距离 ${distance}m!`,
duration: 3,
duration: 3
});
}
break;
@@ -207,25 +201,16 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
// 连接设备 WebSocket
const connectDevice = useCallback(async (targetDevice) => {
if (!targetDevice || isUAV) return;
wsManager.close();
connectedDeviceSnRef.current = null;
setWsDeviceInfo({});
const token = userInfo.token;
console.log(token, "token", userInfo)
const userName = userInfo.username;
const wsUrl = envConfig.WS_URL || "wss://ri.satabot.com/ws/";
wsManager.connect(targetDevice.serialNumber || targetDevice.device_sn, wsUrl);
try {
const res = await getControlRight({
userName,
sourceType: 1,
token,
});
const res = await getControlRight({ userName, sourceType: 1, token });
if (res?.code == 200) {
connectedDeviceSnRef.current = targetDevice.serialNumber || targetDevice.device_sn;
setHasContronRight(true);
@@ -243,19 +228,13 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
if (device) {
connectDevice(device);
}
return () => {
wsManager.close();
};
return () => { wsManager.close(); };
}, [device, connectDevice]);
// 监听 WS 状态和消息
useEffect(() => {
const unsubStatus = wsManager.onStatusChange(setWsStatus);
const unsubMsg = wsManager.onMessage(handleWsMessage);
return () => {
unsubStatus();
unsubMsg();
};
return () => { unsubStatus(); unsubMsg(); };
}, [handleWsMessage]);
useEffect(() => {
@@ -280,21 +259,20 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
const handleGamepadUpdate = (state) => {
if (!isControlled || !connectedDeviceSnRef.current) return;
// 参考 DeviceControl.tsx 的逻辑发送手柄指令
const payload = {
type: 'gamepad',
deviceId: connectedDeviceSnRef.current,
data: {
axes: state.axes,
buttons: state.buttons
}
data: { axes: state.axes, buttons: state.buttons }
};
wsManager.send(payload);
};
const handleControlModal = (data) => {
if (isRequestControl) return;
if (!hasControlRight) {
messageApi.warning("当前网页端无控制权限");
return;
}
if (data.control == true) {
showModal({ title: "权限请求", content: "是否请求控制权限?" }, 'switchPermission');
} else {
@@ -345,13 +323,9 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
</Tag>
)}
{wsStatus === 'connected' && (
<Badge
status="processing"
color="#52c41a"
text="实时连接中"
style={{ color: '#52c41a' }}
/>
)} </div>
<Badge status="processing" color="#52c41a" text="实时连接中" style={{ color: '#52c41a' }} />
)}
</div>
<Row gutter={[16, 16]}>
{/* 左侧:视频和地图 */}
@@ -362,41 +336,72 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
style={{ borderRadius: 12, marginBottom: 16 }}
bodyStyle={{ padding: 12 }}
>
{/* ====================== 机器人:视角切换按钮(只在机器人显示)====================== */}
{!isUAV && (
<Space style={{ marginBottom: 12, flexWrap: 'wrap' }}>
<Button type={mowerView === 'front' ? 'primary' : 'default'} icon={<CameraOutlined />} onClick={() => setMowerView('front')}>前视</Button>
<Button type={mowerView === 'back' ? 'primary' : 'default'} onClick={() => setMowerView('back')}>后视</Button>
<Button type={mowerView === 'left' ? 'primary' : 'default'} onClick={() => setMowerView('left')}>左视</Button>
<Button type={mowerView === 'right' ? 'primary' : 'default'} onClick={() => setMowerView('right')}>右视</Button>
<Button type={mowerView === 'top' ? 'primary' : 'default'} onClick={() => setMowerView('top')}>顶视</Button>
<Button type={mowerView === 'all' ? 'primary' : 'default'} onClick={() => setMowerView('all')}>全景</Button>
</Space>
)}
{/* ====================== 视频区域 ====================== */}
<div style={{
display: 'grid',
gap: '8px',
gridTemplateColumns: planeVideo.length > 1 ? '1fr 1fr' : '1fr',
gridTemplateRows: planeVideo.length > 2 ? '1fr 1fr' : '1fr',
gridTemplateColumns: isUAV
? (planeVideo.length > 1 ? '1fr 1fr' : '1fr')
: (mowerView === 'all' ? '1fr 1fr' : '1fr'),
gridTemplateRows: isUAV
? (planeVideo.length > 2 ? '1fr 1fr' : '1fr')
: (mowerView === 'all' ? '1fr 1fr' : '1fr'),
height: 450,
background: '#000',
borderRadius: 8,
overflow: 'hidden'
}}>
{planeVideo.length > 0 ? (
planeVideo.map((stream, index) => (
<div key={index} style={{
position: 'relative',
gridColumn: (planeVideo.length === 3 && index === 0) ? 'span 2' : 'span 1'
}}>
<DroneLivePlayer streamData={stream} />
<div style={{
position: 'absolute',
top: 8,
left: 8,
background: 'rgba(0,0,0,0.5)',
color: '#fff',
padding: '2px 8px',
borderRadius: 4,
fontSize: 12
{/* ---------------------- 无人机视频(保持原样)---------------------- */}
{isUAV ? (
planeVideo.length > 0 ? (
planeVideo.map((stream, index) => (
<div key={index} style={{
position: 'relative',
gridColumn: (planeVideo.length === 3 && index === 0) ? 'span 2' : 'span 1'
}}>
{stream?.camera_position === 'indoor' ? '库内监控' : `画面 ${index + 1}`}
<DroneLivePlayer streamData={stream} />
<div style={{
position: 'absolute', top: 8, left: 8,
background: 'rgba(0,0,0,0.5)', color: '#fff',
padding: '2px 8px', borderRadius: 4, fontSize: 12
}}>
{stream?.camera_position === 'indoor' ? '库内监控' : `画面 ${index + 1}`}
</div>
</div>
))
) : (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#666', gridColumn: 'span 2' }}>
暂无实时画面
</div>
))
)
) : (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#666', gridColumn: 'span 2' }}>
暂无实时画面
</div>
/* ---------------------- 机器人视频(带视角切换)---------------------- */
robotVideo ? (
<VideoPlayer
deviceId={serialNumber}
idx={mowerView === "front" ? 1 : mowerView === "back" ? 2 : mowerView === "left" ? 3 : 4}
className="w-full h-full object-contain"
video={robotVideo}
error={error}
ready={ready}
/>
) : (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#ccc' }}>
机器人视频加载中...
</div>
)
)}
</div>
</Card>
@@ -420,40 +425,25 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
extra={<Tag color={device.onlineStatus === 1 ? 'success' : 'default'}>{device.onlineStatus === 1 ? '在线' : '离线'}</Tag>}
>
{isUAV ? (
/* 无人机特有面板 */
<Descriptions column={2} size="small" layout="vertical">
<Descriptions.Item label={<><ThunderboltOutlined /> 电池电量</>}>
<Progress
percent={device.capacity_percent || 0}
size="small"
status={(device.capacity_percent || 0) < 20 ? 'exception' : 'active'}
/>
<Progress percent={device.capacity_percent || 0} size="small" status={(device.capacity_percent || 0) < 20 ? 'exception' : 'active'} />
</Descriptions.Item>
<Descriptions.Item label={<><EnvironmentOutlined /> 飞行高度</>}>
<Text strong style={{ fontSize: 16 }}>{fix2(device.height)} m</Text>
</Descriptions.Item>
<Descriptions.Item label="环境风速">
<Text>{fix2(device.wind_speed)} m/s</Text>
</Descriptions.Item>
<Descriptions.Item label="环境温度">
<Text>{fix2(device.environment_temperature)} ℃</Text>
</Descriptions.Item>
<Descriptions.Item label="环境风速"><Text>{fix2(device.wind_speed)} m/s</Text></Descriptions.Item>
<Descriptions.Item label="环境温度"><Text>{fix2(device.environment_temperature)} ℃</Text></Descriptions.Item>
<Descriptions.Item label="降雨状态">
<Tag color={device.rainfall === 'no_rain' ? 'green' : 'red'}>{getVal(device.rainfall)}</Tag>
</Descriptions.Item>
<Descriptions.Item label="返航距离">
<Text>{fix2(device.home_distance)} m</Text>
</Descriptions.Item>
<Descriptions.Item label="返航距离"><Text>{fix2(device.home_distance)} m</Text></Descriptions.Item>
<Descriptions.Item label="GPS 卫星数">
<Badge count={device.position_state?.gps_number || 0} style={{ backgroundColor: '#1890ff' }} />
</Descriptions.Item>
<Descriptions.Item label="RTK 卫星数">
<Badge count={device.position_state?.rtk_number || 0} style={{ backgroundColor: '#52c41a' }} />
</Descriptions.Item>
<Descriptions.Item label="RTK 状态" span={2}>
<Tag color={device.position_state?.is_fixed === 'fixing_successful' ? 'success' : 'warning'}>
{device.position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
@@ -461,58 +451,29 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
</Descriptions.Item>
</Descriptions>
) : (
/* 机器人特有面板 */
<Descriptions column={2} size="small" layout="vertical">
<Descriptions.Item label={<><ThunderboltOutlined /> 电池电量</>}>
<Progress
percent={runningStatus.battery || 0}
size="small"
status={(runningStatus.battery || 0) < 20 ? 'exception' : 'active'}
/>
<Progress percent={runningStatus.battery || 0} size="small" status={(runningStatus.battery || 0) < 20 ? 'exception' : 'active'} />
</Descriptions.Item>
<Descriptions.Item label={<><DashboardOutlined /> 系统电压</>}>
<Text strong style={{ fontSize: 16 }}>{fix2(runningStatus.voltage)} V</Text>
</Descriptions.Item>
<Descriptions.Item label="左电机电流">
<Text>{fix2(runningStatus?.leftCurrent)} A</Text>
</Descriptions.Item>
<Descriptions.Item label="右电机电流">
<Text>{fix2(runningStatus?.rightCurrent)} A</Text>
</Descriptions.Item>
<Descriptions.Item label="左轮速度">
<Text>{fix2(runningStatus?.leftMeasureSpeed)} m/s</Text>
</Descriptions.Item>
<Descriptions.Item label="右轮速度">
<Text>{fix2(runningStatus?.rightMeasureSpeed)} m/s</Text>
</Descriptions.Item>
<Descriptions.Item label="左电机温度">
<Text>{fix2(runningStatus?.leftMotorTemp)} ℃</Text>
</Descriptions.Item>
<Descriptions.Item label="右电机温度">
<Text>{fix2(runningStatus?.rightMotorTemp)} ℃</Text>
</Descriptions.Item>
<Descriptions.Item label="主控温度">
<Text>{fix2(runningStatus?.chipTemp)} ℃</Text>
</Descriptions.Item>
<Descriptions.Item label="左电机电流"><Text>{fix2(runningStatus?.leftCurrent)} A</Text></Descriptions.Item>
<Descriptions.Item label="右电机电流"><Text>{fix2(runningStatus?.rightCurrent)} A</Text></Descriptions.Item>
<Descriptions.Item label="左轮速度"><Text>{fix2(runningStatus?.leftMeasureSpeed)} m/s</Text></Descriptions.Item>
<Descriptions.Item label="右轮速度"><Text>{fix2(runningStatus?.rightMeasureSpeed)} m/s</Text></Descriptions.Item>
<Descriptions.Item label="左电机温度"><Text>{fix2(runningStatus?.leftMotorTemp)} ℃</Text></Descriptions.Item>
<Descriptions.Item label="右电机温度"><Text>{fix2(runningStatus?.rightMotorTemp)} ℃</Text></Descriptions.Item>
<Descriptions.Item label="主控温度"><Text>{fix2(runningStatus?.chipTemp)} ℃</Text></Descriptions.Item>
<Descriptions.Item label="卫星数量">
<Badge showZero={true}
count={runningStatus?.satelliteCnt || 0} style={{ backgroundColor: '#52c41a' }} />
</Descriptions.Item>
<Descriptions.Item label="偏航角 (Yaw)">
<Text>{fix2(runningStatus?.yaw)}°</Text>
</Descriptions.Item>
<Descriptions.Item label="俯仰角 (Pitch)">
<Text>{fix2(runningStatus?.pitch)}°</Text>
<Badge showZero count={runningStatus?.satelliteCnt || 0} style={{ backgroundColor: '#52c41a' }} />
</Descriptions.Item>
<Descriptions.Item label="偏航角 (Yaw)"><Text>{fix2(runningStatus?.yaw)}°</Text></Descriptions.Item>
<Descriptions.Item label="俯仰角 (Pitch)"><Text>{fix2(runningStatus?.pitch)}°</Text></Descriptions.Item>
</Descriptions>
)}
</Card>
{!isUAV && (
<Card
title={<><ControlOutlined /> 远程控制</>}
@@ -525,11 +486,8 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha
handleControlModal={handleControlModal}
isControlled={isControlled}
/>
</Card>
)}
</Col>
</Row>

View File

@@ -56,7 +56,7 @@
padding-bottom:12px !important;
}
.ant-select-selector{
.ant-select-selector,.ant-input,.ant-picker{
border-radius:8px !important;
}
.ant-btn{

View File

@@ -530,8 +530,21 @@ export default function StationDashboard() {
</div>
<div style={{ height: 360, background: '#111827', borderRadius: 8, width: '100%' }} />
</Card>
<div style={{ height: 360, background: '#111827', borderRadius: 8, width: '100%', overflow: 'hidden', position: "relative" }}>
<iframe
src="https://pvs.satabot.com/?platform=web"
style={{
width: '100%',
height: '100%',
border: 'none',
borderRadius: '8px',
position: "absolute",
}}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
title="外部系统"
/>
</div> </Card>
</Col>

View File

@@ -170,11 +170,20 @@ const RealTimeMonitorPage = () => {
style={{ marginBottom: 16, borderRadius: 8 }}
extra={<Text type="secondary">真实正射底图 · 设备状态联动</Text>}
>
<div style={{ position: 'relative', height: 400, background: '#e6f7ff', borderRadius: 8 }}>
<div style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%,-50%)', textAlign: 'center' }}>
<CloudOutlined style={{ fontSize: 48, color: '#1890ff' }} />
<p>电站拓扑底图</p>
</div>
<div style={{ height: 360, background: '#111827', borderRadius: 8, width: '100%', overflow: 'hidden', position: "relative" }}>
<iframe
src="https://pvs.satabot.com/?platform=web"
style={{
width: '100%',
height: '100%',
border: 'none',
borderRadius: '8px',
position: "absolute",
}}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
title="外部系统"
/>
</div>
</Card>