From e401eef62f79acbd140b0f1fa92988c5a4c15102 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Thu, 7 May 2026 09:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=8A=A5=E8=AD=A6=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/DeviceAccessPage.tsx | 191 +++++++++++++++++---------------- 1 file changed, 96 insertions(+), 95 deletions(-) diff --git a/src/pages/DeviceAccessPage.tsx b/src/pages/DeviceAccessPage.tsx index 27359db..a96b890 100644 --- a/src/pages/DeviceAccessPage.tsx +++ b/src/pages/DeviceAccessPage.tsx @@ -1,7 +1,7 @@ import { useState } from 'react'; import { Card, Table, Button, Space, Form, Modal, Input, Select, InputNumber, - Tabs, Tag, Popconfirm, message, Descriptions, Divider, Empty + Tabs, Tag, Popconfirm, message, Divider, Switch, Checkbox } from 'antd'; import { PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined, @@ -14,15 +14,15 @@ const { TabPane } = Tabs; // ====================== 模拟基础数据 ====================== const productList = [ { - id: 1, name: '海康威视摄像头', code: 'hikvision', protocolType: 'onvif', manufacturer: '海康', status: 1, + id: 1, name: '海康威视摄像头', code: 'hikvision', protocolType: 'onvif', manufacturer: '海康', publishTopic: '/hik/device/upload', subscribeTopic: '/hik/device/cmd' }, { - id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华', status: 1, + id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华', publishTopic: '/dahua/device/upload', subscribeTopic: '/dahua/device/cmd' }, { - id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用', status: 1, + id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用', publishTopic: '/iot/device/upload', subscribeTopic: '/iot/device/cmd' }, ]; @@ -30,9 +30,10 @@ const productList = [ const modelList = [ { id: 10, name: '通用视频监控设备', code: 'video_camera', desc: '摄像头、云台、告警' }, { id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感' }, + { id: 12, name: '电池供电设备', code: 'battery_device', desc: '电量、电压监测' }, ]; -// 物模型详情(完全保留你原来的) +// 物模型详情:属性增加 isAlarm(是否作为告警参数) const modelDetailList: Record = { 10: { props: [ - { id: 1, code: 'device_online', name: '在线状态', type: 'bool', rw: 'r' }, - { id: 2, code: 'record_status', name: '录像状态', type: 'string', rw: 'r' }, - { id: 3, code: 'battery', name: '电量', type: 'int', rw: 'r' }, + { id: 1, code: 'device_online', name: '在线状态', type: 'bool', rw: 'r', isAlarm: false }, + { id: 2, code: 'record_status', name: '录像状态', type: 'string', rw: 'r', isAlarm: false }, ], events: [ { id: 1, code: 'alarm_perimeter', name: '周界入侵告警' }, - { id: 2, code: 'alarm_people', name: '人员闯入告警' }, ], actions: [ { id: 1, code: 'take_snapshot', name: '截图' }, - { id: 2, code: 'set_record', name: '开启/关闭录像' }, ] }, 11: { props: [ - { id: 1, code: 'temp', name: '温度', type: 'float', rw: 'r' }, - { id: 2, code: 'humi', name: '湿度', type: 'float', rw: 'r' }, + { id: 1, code: 'temp', name: '温度', type: 'float', rw: 'r', isAlarm: true }, + { id: 2, code: 'humi', name: '湿度', type: 'float', rw: 'r', isAlarm: true }, ], events: [ { id: 1, code: 'temp_over', name: '超温告警' }, ], actions: [] + }, + 12: { + props: [ + { id: 1, code: 'battery', name: '电量', type: 'int', rw: 'r', isAlarm: true }, + { id: 2, code: 'voltage', name: '电压', type: 'float', rw: 'r', isAlarm: true }, + ], + events: [ + { id: 1, code: 'low_power', name: '低电量告警' }, + ], + actions: [] } }; // 字段映射数据 const mappingInitList = [ { id: 1, productId: 1, standardCode: 'device_online', sourceField: 'online_flag', convertRule: 'value==1?true:false' }, - { id: 2, productId: 1, standardCode: 'record_status', sourceField: 'record_state', convertRule: 'value' }, ]; const deviceList = [ { id: 1, - name: '1#阵列区球机', - sn: 'HK20260507001', - productId: 1, - productName: '海康威视摄像头', - modelId: 10, - modelName: '通用视频监控设备', - protocolType: 'onvif', - ip: '192.168.1.65', - port: 80, - username: 'admin', - password: '123456', - mqttServer: '', + name: '1#环境传感器', + sn: 'SEN001', + productId: 3, + productName: '通用MQTT设备', + modelId: 11, + modelName: '环境监测设备', + protocolType: 'mqtt', + mqttServer: 'tcp://192.168.1.200', mqttPort: 1883, - clientId: '', - mqttUsername: '', - mqttPassword: '', + clientId: 'sen_001', alarmConfig: { - tempMax: 60, - tempMin: 0, - humiMax: 90, - humiMin: 20, - batteryMax: 100, - batteryMin: 10 + tempMax: 60, tempMin: 0, + humiMax: 90, humiMin: 20 }, onlineStatus: 1, createTime: '2026-05-07 10:23:45' }, + { + id: 2, + name: '1#电池设备', + sn: 'BAT001', + productId: 3, + productName: '通用MQTT设备', + modelId: 12, + modelName: '电池供电设备', + protocolType: 'mqtt', + mqttServer: 'tcp://192.168.1.200', + mqttPort: 1883, + clientId: 'bat_001', + alarmConfig: { + batteryMax: 100, batteryMin: 10, + voltageMax: 24, voltageMin: 12 + }, + onlineStatus: 1, + createTime: '2026-05-07 10:25:10' + } ]; const alarmList = [ - { id: 1, deviceId: 1, deviceName: '1#阵列区球机', level: 'warn', content: '周界入侵告警', time: '2026-05-07 10:23:41', status: 0 }, + { id: 1, deviceId: 1, deviceName: '1#环境传感器', level: 'warn', content: '温度超过阈值 62℃', time: '2026-05-07 10:24:00' }, ]; export default function DeviceAccessPage() { @@ -117,7 +133,6 @@ export default function DeviceAccessPage() { // 物模型详情 const [modelDetail, setModelDetail] = useState({ props: [], events: [], actions: [] }); - // 模型子项弹窗(属性/事件/动作) const [itemModal, setItemModal] = useState(false); const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props'); const [itemForm] = Form.useForm(); @@ -140,6 +155,8 @@ export default function DeviceAccessPage() { } if (type === 'device') { setProtocol(record.protocolType); + // 加载对应模型详情,用于动态生成告警项 + setModelDetail(modelDetailList[record.modelId] || { props: [] }); } } else { setModelDetail({ props: [], events: [], actions: [] }); @@ -185,7 +202,7 @@ export default function DeviceAccessPage() { message.success('删除成功'); }; - // ========== 字段映射 增删改 核心 ========== + // ========== 字段映射 增删改 ========== const openMappingModal = (record: any, row?: any) => { setVisible(false); mappingForm.resetFields(); @@ -219,12 +236,10 @@ export default function DeviceAccessPage() { message.success('删除成功'); }; - // 获取当前模型标准属性下拉 - const getStandardPropOptions = () => { + // 获取当前模型的告警属性(isAlarm=true) + const getAlarmProps = () => { if (!modelDetail?.props) return []; - return modelDetail.props.map((item: any) => ( - - )); + return modelDetail.props.filter(item => item.isAlarm); }; // 表格列 @@ -233,8 +248,7 @@ export default function DeviceAccessPage() { { title: 'SN', dataIndex: 'sn' }, { title: '所属产品', dataIndex: 'productName' }, { title: '物模型', dataIndex: 'modelName' }, - { title: '协议', dataIndex: 'protocolType', render: (t: string) => {t.toUpperCase()} }, - { title: 'IP', dataIndex: 'ip' }, + { title: '协议', dataIndex: 'protocolType', render: (t: string) => {t.toUpperCase()} }, { title: '状态', dataIndex: 'onlineStatus', render: (s: number) => {s === 1 ? '在线' : '离线'} }, { title: '操作', render: (r: any) => ( @@ -297,6 +311,11 @@ export default function DeviceAccessPage() { { title: '字段名称', dataIndex: 'name' }, { title: '数据类型', dataIndex: 'type' }, { title: '读写类型', dataIndex: 'rw' }, + { + title: '告警参数', render: (r: any) => ( + 启用 + ) + }, { title: '操作', render: (r: any) => ( @@ -400,7 +419,9 @@ export default function DeviceAccessPage() { - + @@ -427,7 +448,6 @@ export default function DeviceAccessPage() { -
上报主题:{editData?.publishTopic || '未配置'}
订阅主题:{editData?.subscribeTopic || '未配置'}
@@ -436,27 +456,20 @@ export default function DeviceAccessPage() { )} - {/* 新增:报警阈值配置 */} + {/* 报警阈值:动态渲染当前模型的告警属性 */} -
可配置设备触发告警的上下限参数
- - - - - - - - - - - - - - - - - - +
当前物模型:{editData?.modelName},仅显示告警参数
+ {getAlarmProps().map((item: any) => ( +
+ + + + + + +
+ ))} + {getAlarmProps().length === 0 && }
)} @@ -474,26 +487,20 @@ export default function DeviceAccessPage() { - 厂商级 MQTT Topic 配置 - - - - - - -
同一厂商设备自动继承该 Topic
+ + )} - {/* 物模型完整编辑(完全保留你原来的!) */} + {/* 物模型完整编辑(含告警参数勾选) */} {modalType === 'model' && ( <> - 属性列表 + 属性列表(可勾选作为告警参数) @@ -513,22 +520,14 @@ export default function DeviceAccessPage() {
{editData?.name} - 字段映射配置 - + -
item.productId === editData?.id)} - pagination={false} - /> +
item.productId === editData?.id)} pagination={false} /> )} - {/* 物模型子项编辑弹窗 */} + {/* 物模型子项编辑弹窗(属性增加isAlarm) */}
- - + + {itemType === 'props' && ( <> @@ -556,6 +555,9 @@ export default function DeviceAccessPage() { + + + )} @@ -573,19 +575,18 @@ export default function DeviceAccessPage() {
- - - + - - +