diff --git a/src/api/alarmApi.js b/src/api/alarmApi.js new file mode 100644 index 0000000..8fa531b --- /dev/null +++ b/src/api/alarmApi.js @@ -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' + }); +} diff --git a/src/components/alerts/AlarmHistory.tsx b/src/components/alerts/AlarmHistory.tsx index dd33886..a4b121a 100644 --- a/src/components/alerts/AlarmHistory.tsx +++ b/src/components/alerts/AlarmHistory.tsx @@ -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(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 {text}; - } + width: 100, + render: (r) => ( + + {levelText[r.alarmLevel]} + + ) + }, + { + 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 ; - } + width: 100, + render: (r) => ( + + ) }, { title: '操作', - render: (_: any, record: any) => ( - ) @@ -95,59 +136,71 @@ const AlarmHistory = () => { return (
- - {/* 统一筛选栏:搜索 + 时间 + 设备 */} - - + 历史告警记录} + > + {/* 筛选栏 */} +
- - - - - - - -
-
+ + + + + + + + + + + + + + + {/* 表格 */} - + + {/* 分页 */} +
+ { + setPageNum(p); + setPageSize(s); + }} + showSizeChanger + showQuickJumper + showTotal={(total) => `共 ${total} 条`} + /> +
+ {/* 详情弹窗 */} { open={detailVisible} onCancel={() => setDetailVisible(false)} footer={null} - width={520} + width={580} + destroyOnClose > {currentAlarm && ( - - {currentAlarm.time} - {currentAlarm.deviceName} + + {currentAlarm.id} + {currentAlarm.createTime} + {currentAlarm.deviceId} + {currentAlarm.deviceName || '-'} {currentAlarm.content} - - {currentAlarm.level === 'warn' ? '警告' : currentAlarm.level === 'error' ? '严重' : '提示'} + + {levelText[currentAlarm.alarmLevel]} + {currentAlarm.handleRemark && ( + {currentAlarm.handleRemark} + )} )} diff --git a/src/components/alerts/AlarmOverview.tsx b/src/components/alerts/AlarmOverview.tsx index 046bc49..e67fa74 100644 --- a/src/components/alerts/AlarmOverview.tsx +++ b/src/components/alerts/AlarmOverview.tsx @@ -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(null); - const [detailVisible, setDetailVisible] = useState(false); - const [confirmModalVisible, setConfirmModalVisible] = useState(false); - const [notifyChannels, setNotifyChannels] = useState(['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} + render: (text) => AL{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) => ( - {l} + {levelText[l]} ) }, - { title: '发生时间', dataIndex: 'time', width: 160 }, - { title: '持续时长', dataIndex: 'duration', width: 100 }, + { title: '发生时间', dataIndex: 'createTime', width: 160 }, { title: '处理状态', - dataIndex: 'status', + dataIndex: 'handleStatus', width: 100, render: (s) => ( - {s} + {statusText[s]} ) }, - { title: '负责人', dataIndex: 'handler', width: 100 }, { title: '操作', width: 80, render: (_, record) => ( - + ) } ]; - // 告警趋势图配置 - 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 (
- {/* 🔥 核心布局:左侧内容 + 右侧详情 永远一行显示 */}
- {/* 左侧主内容区 */} + {/* 左侧 */}
+ {/* 查询栏 */}
告警级别
- - - -
设备类型
- setQueryParams({ ...queryParams, alarmLevel: v })} + options={[ + { value: '', label: '全部' }, + { value: 1, label: '严重' }, + { value: 2, label: '重要' }, + { value: 3, label: '一般' }, + { value: 4, label: '提示' }, + ]} + />
处理状态
- + setQueryParams({ ...queryParams, deviceId: e.target.value })} + style={{ width: 160 }} + /> + + +
时间范围
+ { + if (arr) { + setQueryParams({ + ...queryParams, + beginTime: arr[0].format('YYYY-MM-DD HH:mm:ss'), + endTime: arr[1].format('YYYY-MM-DD HH:mm:ss') + }); + } + }} + /> -
- - + + + @@ -289,260 +275,203 @@ export default function AlarmCenterPage() { - - - + {/* 统计卡片 —— 完全匹配后端接口 */} + + +
- -
今日告警总数
-
- 36 - 较昨日 +28.6% ↑ +
+
告警总数
+
+ {statData.total || 0}
-
昨日 28
- - + + +
- +
严重告警
-
- 8 - 较昨日 +33.3% ↑ +
+ {statData.levelStats?.[1] || 0}
-
昨日 6
-
- + + +
- -
处理中
-
- 12 - 较昨日 +20.0% ↑ +
+
待处理
+
+ {statData.pending || 0}
-
昨日 10
- - - - -
- -
- - -
已关闭
-
- 16 - 较昨日 +45.5% ↑ -
-
昨日 11
- - - - - - + + +
- -
平均响应时长
-
- 18分32秒 +
+
处理中
+
+ {statData.processing || 0} +
+ + + + + + + + + +
+ +
+ + +
已关闭
+
+ {statData.closed || 0}
-
昨日 21分12秒
+ {/* 表格 */} - -
- 告警列表(共 36 条) -
-
+ + +
+
- + setPageNum(p)} + showSizeChanger={false} showQuickJumper size="small" + />
+ {/* 三个图表 */} - 告警趋势} extra={} style={{ borderRadius: 8 }}> - + + - 告警分类占比} extra={} style={{ borderRadius: 8 }}> + - 告警来源设备分布} extra={} style={{ borderRadius: 8 }}> - + + - {/* 🔥 右侧详情:丝滑滑入动画 */} - {detailVisible && selectedAlert && ( -
- - 告警详情} - extra={ setDetailVisible(false)} />} - bodyStyle={{ padding: 16 }} - style={{ height: '100%', borderRadius: 8 }} - > -
-
- -
-
-
- {selectedAlert.content} - {selectedAlert.level} + {/* 右侧详情 */} + {detailVisible && currentAlarm && ( +
+ + setDetailVisible(false)} />} style={{ borderRadius: 8 }}> + +
+
+
-
告警编号:{selectedAlert.id}
-
-
- - -
来源设备
{selectedAlert.device}
-
设备类型
逆变器
-
发生时间
{selectedAlert.time}
-
持续时长
{selectedAlert.duration}
-
处理状态
{selectedAlert.status} - -
负责人
-
- {selectedAlert.handler} - +
+
+ {currentAlarm.content} + + {levelText[currentAlarm.alarmLevel]} + +
+
告警编号:AL{currentAlarm.id}
- -
当前处理人
张运维 (2025-05-25 09:22 接收)
-
告警描述
逆变器因内部故障自动停机,当前无功率输出。
- - - - -
-
- 根因分析建议 -
-
    -
  1. 逆变器内部保护触发 (IGBT/继电器故障)
  2. -
  3. 交流侧电压异常或并网不稳定
  4. -
  5. 散热风扇故障导致过温保护
  6. -
-
-
-
相关趋势
- -
- -
-
推荐处理措施
-
    -
  • 现场检查逆变器告警记录及指示灯状态;
  • -
  • 检查散热风扇运行及通风条件;
  • -
  • 检查交流侧电压及并网条件;
  • -
  • 如无法恢复,建议联系厂家或更换模块。
  • -
-
- -
-
- -
-
通知与订阅
- -
短信 - Telegram - 邮件 + +
设备ID
{currentAlarm.deviceId}
+
状态
{statusText[currentAlarm.handleStatus]} +
发生时间
{currentAlarm.createTime}
- - + + )} - - setConfirmModalVisible(false)} - onOk={handleConfirmAlarm} - destroyOnClose - > -
- - - -
- 确认后将向选中渠道发送通知 -
- -
); } diff --git a/src/components/devices/DeviceStatusPage.tsx b/src/components/devices/DeviceStatusPage.tsx index d074f25..e1f45a5 100644 --- a/src/components/devices/DeviceStatusPage.tsx +++ b/src/components/devices/DeviceStatusPage.tsx @@ -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 )} {wsStatus === 'connected' && ( - - )} + + )} + {/* 左侧:视频和地图 */} @@ -362,41 +336,72 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha style={{ borderRadius: 12, marginBottom: 16 }} bodyStyle={{ padding: 12 }} > + {/* ====================== 机器人:视角切换按钮(只在机器人显示)====================== */} + {!isUAV && ( + + + + + + + + + )} + + {/* ====================== 视频区域 ====================== */}
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) => ( -
- -
0 ? ( + planeVideo.map((stream, index) => ( +
- {stream?.camera_position === 'indoor' ? '库内监控' : `画面 ${index + 1}`} + +
+ {stream?.camera_position === 'indoor' ? '库内监控' : `画面 ${index + 1}`} +
+ )) + ) : ( +
+ 暂无实时画面
- )) + ) ) : ( -
- 暂无实时画面 -
+ /* ---------------------- 机器人视频(带视角切换)---------------------- */ + robotVideo ? ( + + ) : ( +
+ 机器人视频加载中... +
+ ) )}
@@ -420,40 +425,25 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha extra={{device.onlineStatus === 1 ? '在线' : '离线'}} > {isUAV ? ( - /* 无人机特有面板 */ 电池电量}> - + 飞行高度}> {fix2(device.height)} m - - - {fix2(device.wind_speed)} m/s - - - {fix2(device.environment_temperature)} ℃ - - + {fix2(device.wind_speed)} m/s + {fix2(device.environment_temperature)} ℃ {getVal(device.rainfall)} - - {fix2(device.home_distance)} m - - + {fix2(device.home_distance)} m - {device.position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'} @@ -461,58 +451,29 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha ) : ( - /* 机器人特有面板 */ 电池电量}> - + 系统电压}> {fix2(runningStatus.voltage)} V - - - {fix2(runningStatus?.leftCurrent)} A - - - {fix2(runningStatus?.rightCurrent)} A - - - {fix2(runningStatus?.leftMeasureSpeed)} m/s - - - {fix2(runningStatus?.rightMeasureSpeed)} m/s - - - - {fix2(runningStatus?.leftMotorTemp)} ℃ - - - {fix2(runningStatus?.rightMotorTemp)} ℃ - - - - {fix2(runningStatus?.chipTemp)} ℃ - + {fix2(runningStatus?.leftCurrent)} A + {fix2(runningStatus?.rightCurrent)} A + {fix2(runningStatus?.leftMeasureSpeed)} m/s + {fix2(runningStatus?.rightMeasureSpeed)} m/s + {fix2(runningStatus?.leftMotorTemp)} ℃ + {fix2(runningStatus?.rightMotorTemp)} ℃ + {fix2(runningStatus?.chipTemp)} ℃ - - - - - {fix2(runningStatus?.yaw)}° - - - {fix2(runningStatus?.pitch)}° + + {fix2(runningStatus?.yaw)}° + {fix2(runningStatus?.pitch)}° )} - - + {!isUAV && ( 远程控制} @@ -525,11 +486,8 @@ export default function DeviceStatusPage({ devicesAll, serialNumber, onDeviceCha handleControlModal={handleControlModal} isControlled={isControlled} /> - )} - - diff --git a/src/index.css b/src/index.css index 8fff911..dd70106 100644 --- a/src/index.css +++ b/src/index.css @@ -56,7 +56,7 @@ padding-bottom:12px !important; } -.ant-select-selector{ +.ant-select-selector,.ant-input,.ant-picker{ border-radius:8px !important; } .ant-btn{ diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 4350464..181851b 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -530,8 +530,21 @@ export default function StationDashboard() {
-
- +
+