diff --git a/src/components/SystemSetting/DeviceAccessPage.tsx b/src/components/SystemSetting/DeviceAccessPage.tsx index dda2b28..2456d1e 100644 --- a/src/components/SystemSetting/DeviceAccessPage.tsx +++ b/src/components/SystemSetting/DeviceAccessPage.tsx @@ -5,7 +5,7 @@ import { } from 'antd'; import { PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined, - AppstoreOutlined, SwapOutlined, VideoCameraOutlined, AlertOutlined + AppstoreOutlined, SwapOutlined, VideoCameraOutlined } from '@ant-design/icons'; const { Option } = Select; @@ -44,7 +44,7 @@ const modelDetailList: Record('props'); const [itemForm] = Form.useForm(); + // 指令 + 参数 新增状态 + const [actionModal, setActionModal] = useState(false); + const [currentAction, setCurrentAction] = useState(null); + const [paramList, setParamList] = useState([]); + // 字段映射(实时增删改查,实时保存) const [mappingList, setMappingList] = useState(mappingInitList); const [mappingModal, setMappingModal] = useState(false); @@ -128,15 +133,35 @@ export default function DeviceAccessPage() { setVisible(true); }; - // 产品提交 + // 提交 const handleSubmit = () => { form.validateFields().then(values => { - message.success('产品信息保存成功'); + if (modalType === 'model') { + const submitData = { + name: values.name, + connectType: values.connectType, + version: "1.0", + deviceType: values.deviceType, + supportProperties: modelDetail.props.map(p => ({ + propertyKey: p.code, + propertyName: p.name, + dataType: p.type, + unit: p.unit || "", + required: true, + defaultValue: null + })), + supportActions: modelDetail.actions + }; + console.log("最终提交物模型:", submitData); + message.success("物模型保存成功"); + } else { + message.success("保存成功"); + } setVisible(false); }); }; - // 物模型 + // 属性/事件 编辑 const openItemModal = (type: 'props' | 'events' | 'actions', record?: any) => { setItemType(type); itemForm.resetFields(); @@ -163,18 +188,14 @@ export default function DeviceAccessPage() { else mappingForm.setFieldsValue({ productId: editData?.id }); setMappingModal(true); }; - - // 新增/编辑 → 立即保存 const saveMapping = () => { mappingForm.validateFields().then(val => { let newList = [...mappingList]; if (val.id) { - // 编辑 const index = newList.findIndex(x => x.id === val.id); if (index >= 0) newList[index] = val; message.success('字段映射修改成功'); } else { - // 新增 newList.push({ ...val, id: Date.now() }); message.success('字段映射新增成功'); } @@ -183,8 +204,6 @@ export default function DeviceAccessPage() { setMappingModal(false); }); }; - - // 删除 → 立即保存 const deleteMapping = (id: number) => { const newList = mappingList.filter(x => x.id !== id); setMappingList(newList); @@ -201,9 +220,9 @@ export default function DeviceAccessPage() { { title: 'SN', dataIndex: 'sn' }, { title: '所属产品', dataIndex: 'productName' }, { title: '物模型', dataIndex: 'modelName' }, - { title: '协议', dataIndex: 'protocolType', render: t => {t.toUpperCase()} }, + { title: '协议', render: t => {t.protocolType.toUpperCase()} }, { title: '状态', render: r => {r.onlineStatus ? '在线' : '离线'} }, - { title: '操作', render: r => } + { title: '操作', render: r => } ]; const productColumns = [ @@ -239,8 +258,8 @@ export default function DeviceAccessPage() { {activeTab === 'device' && } - {activeTab === 'product' &&
} - {activeTab === 'model' &&
} + {activeTab === 'product' &&
} + {activeTab === 'model' &&
} setVisible(false)} onOk={handleSubmit} destroyOnClose title={modalType === 'device' ? '设备配置' : modalType === 'product' ? '产品配置' : '物模型配置'}> @@ -281,7 +300,6 @@ export default function DeviceAccessPage() { {productProtocol === 'mqtt' && <>MQTT 厂商级 Topic 配置} -
x.productId === editData?.id)} pagination={false} @@ -305,9 +323,24 @@ export default function DeviceAccessPage() { {modalType === 'model' && ( <> - - - +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ 属性列表
}, { title: '操作', render: r => deleteItem('props', r.id)}> } ]} /> - 事件列表 - -
}]} /> + 指令列表 + +
Object.keys(r.params || {}).join(',') || '无' }, + { + title: '操作', render: r => ( + + + { + setModelDetail({ + ...modelDetail, + actions: modelDetail.actions.filter(x => x.actionId !== r.actionId) + }) + }}> + + + + ) + } + ]} /> )} @@ -333,7 +397,92 @@ export default function DeviceAccessPage() { - {/* 字段映射弹窗:操作即保存 */} + {/* 指令 + 参数 弹窗 */} + setActionModal(false)} + onOk={() => { + const params = paramList.reduce((obj, item) => { + obj[item.paramKey] = { + type: item.type, + description: item.desc || '', + default: item.defaultValue + }; + return obj; + }, {}); + + const action = { + actionId: currentAction.actionId, + actionName: currentAction.actionName, + params + }; + + const exists = modelDetail.actions.some(x => x.actionId === currentAction.actionId); + let newActions = []; + if (exists) { + newActions = modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x); + } else { + newActions = [...modelDetail.actions, action]; + } + + setModelDetail({ ...modelDetail, actions: newActions }); + setActionModal(false); + message.success('保存成功'); + }} + width={700} + > +
+ setCurrentAction({ ...currentAction, actionId: e.target.value })} + style={{ width: '48%', marginRight: '4%' }} + /> + setCurrentAction({ ...currentAction, actionName: e.target.value })} + style={{ width: '48%' }} + /> +
+ + 指令参数 + + {paramList.map((item, index) => ( +
+ { + const arr = [...paramList]; + arr[index].paramKey = e.target.value; + setParamList(arr); + }} /> + + { + const arr = [...paramList]; + arr[index].desc = e.target.value; + setParamList(arr); + }} /> + { + const arr = [...paramList]; + arr[index].defaultValue = e.target.value; + setParamList(arr); + }} /> + +
+ ))} + + +
+ setMappingModal(false)} onOk={saveMapping} title="字段映射配置">
告警总数
45
-
严重告警
12
-
警告告警
20
-
已处理
13
- - - - ); +// 级别 + 状态颜色 +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(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 => {l} }, + { title: '发生时间', dataIndex: 'time', width: 160 }, + { title: '持续时长', dataIndex: 'duration', width: 100 }, + { title: '处理状态', dataIndex: 'status', width: 100, render: s => {s} }, + { title: '负责人', dataIndex: 'handler', width: 100 }, + { + title: '操作', width: 120, + render: (_, record) => ( + + + + + ) + } + ]; + + return ( +
+ + {/* ===================== 统一宽度容器 ===================== */} +
+ + {/* ===================== 左侧:所有模块宽度完全一致 ===================== */} +
+ + {/* 筛选卡片 */} + + +
+ + + + + + + {/* 统计卡片 */} + + } valueStyle={{ fontSize: 22 }} />
昨日 28
+ } valueStyle={{ fontSize: 22 }} />
重要 2
+ } valueStyle={{ fontSize: 22 }} />
待处理 4
+ } valueStyle={{ fontSize: 22 }} />
闭环完成
+ } valueStyle={{ fontSize: 22 }} />
时间估算
+ + + {/* 告警列表(宽度 = 筛选卡片 完全一致) */} + +
+
+ 告警列表(共8条)
+ 点击告警查看详情 +
+
+ +
+ + + + + {/* ===================== 右侧详情面板 ===================== */} + {detailVisible && selectedAlert && ( +
+ +
+
+
+ + {selectedAlert.content} +
+ {selectedAlert.level} +
+
{selectedAlert.id}
+
+ +
+ +
来源设备
{selectedAlert.device}
+
发生时间
{selectedAlert.time}
+
持续时长
{selectedAlert.duration}
+
处理状态
{selectedAlert.status}
+ + + +
+
根因分析建议
+
+ 设备离线/网络异常
+ 电源或通讯模块故障
+ 现场信号弱或采集器异常 +
+
+ + + + + + + + + )} + + + + ); +} diff --git a/src/components/alerts/AlarmRules.tsx b/src/components/alerts/AlarmRules.tsx index c386728..8049aba 100644 --- a/src/components/alerts/AlarmRules.tsx +++ b/src/components/alerts/AlarmRules.tsx @@ -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(null); const [form] = Form.useForm(); - // 搜索筛选 + // 下拉选项 + const [deviceTypeOpts, setDeviceTypeOpts] = useState([ + { value: 'sensor', label: '传感器' }, + { value: 'camera', label: '摄像头' }, + { value: 'battery', label: '电池设备' }, + ]); + const [propList, setPropList] = useState([]); + + // 搜索 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 {text}; } }, { title: '触发条件', dataIndex: 'condition' }, { title: '状态', - render: (r: any) => ( - - ) + render: (r: any) => }, { title: '操作', render: (r: any) => ( - handleDelete(r.id)} - > - - + handleDelete(r.id)}> ) } @@ -112,51 +131,68 @@ const AlarmRules = () => { return (
- {/* 修复:使用 Input.Search */} - - + + } > -
+
- {/* 新增/编辑 弹窗 */} setModalVisible(false)} onOk={handleSave} - maskClosable={false} + width={600} > - - + + + + + + + + + + + + + + + + + + - - - - - - + + diff --git a/src/pages/Alerts.tsx b/src/pages/Alerts.tsx index 304a2db..0d259b0 100644 --- a/src/pages/Alerts.tsx +++ b/src/pages/Alerts.tsx @@ -69,6 +69,11 @@ export default function AlarmCenterPage() { return ( +
+ 告警中心 + 告警处置闭环、规则管理与事件中心 +
+