参数报警配置
This commit is contained in:
@@ -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<number, {
|
||||
props: any[];
|
||||
events: any[];
|
||||
@@ -40,71 +41,86 @@ const modelDetailList: Record<number, {
|
||||
}> = {
|
||||
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<any>({ 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) => (
|
||||
<Option key={item.code} value={item.code}>{item.name}({item.code})</Option>
|
||||
));
|
||||
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) => <Tag color={t === 'onvif' ? 'blue' : t === 'rtsp' ? 'orange' : 'purple'}>{t.toUpperCase()}</Tag> },
|
||||
{ title: 'IP', dataIndex: 'ip' },
|
||||
{ title: '协议', dataIndex: 'protocolType', render: (t: string) => <Tag>{t.toUpperCase()}</Tag> },
|
||||
{ title: '状态', dataIndex: 'onlineStatus', render: (s: number) => <Tag color={s === 1 ? 'green' : 'red'}>{s === 1 ? '在线' : '离线'}</Tag> },
|
||||
{
|
||||
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) => (
|
||||
<Checkbox checked={r.isAlarm} disabled>启用</Checkbox>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: '操作', render: (r: any) => (
|
||||
<Space>
|
||||
@@ -400,7 +419,9 @@ export default function DeviceAccessPage() {
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="关联物模型" name="modelId" rules={[{ required: true }]}>
|
||||
<Select>{modelList.map(m => <Option key={m.id} value={m.id}>{m.name}</Option>)}</Select>
|
||||
<Select onChange={(val) => setModelDetail(modelDetailList[val] || { props: [] })}>
|
||||
{modelList.map(m => <Option key={m.id} value={m.id}>{m.name}</Option>)}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</TabPane>
|
||||
|
||||
@@ -427,7 +448,6 @@ export default function DeviceAccessPage() {
|
||||
<Form.Item label="用户名" name="mqttUsername"><Input /></Form.Item>
|
||||
<Form.Item label="密码" name="mqttPassword"><Input.Password /></Form.Item>
|
||||
</Card>
|
||||
|
||||
<Card size="small" title="MQTT Topic配置(继承自产品)">
|
||||
<div className="text-sm">上报主题:{editData?.publishTopic || '未配置'}</div>
|
||||
<div className="text-sm">订阅主题:{editData?.subscribeTopic || '未配置'}</div>
|
||||
@@ -436,27 +456,20 @@ export default function DeviceAccessPage() {
|
||||
)}
|
||||
</TabPane>
|
||||
|
||||
{/* 新增:报警阈值配置 */}
|
||||
{/* 报警阈值:动态渲染当前模型的告警属性 */}
|
||||
<TabPane tab="报警阈值" key="alarmThreshold">
|
||||
<div className="text-sm mb-2">可配置设备触发告警的上下限参数</div>
|
||||
<Form.Item label="温度上限" name={['alarmConfig', 'tempMax']}>
|
||||
<InputNumber className="w-full" placeholder="单位:℃" />
|
||||
</Form.Item>
|
||||
<Form.Item label="温度下限" name={['alarmConfig', 'tempMin']}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="湿度上限" name={['alarmConfig', 'humiMax']}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="湿度下限" name={['alarmConfig', 'humiMin']}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="电量上限" name={['alarmConfig', 'batteryMax']}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
<Form.Item label="电量下限" name={['alarmConfig', 'batteryMin']}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
<div className="text-sm mb-2">当前物模型:{editData?.modelName},仅显示告警参数</div>
|
||||
{getAlarmProps().map((item: any) => (
|
||||
<div key={item.code}>
|
||||
<Form.Item label={`${item.name} 上限`} name={['alarmConfig', `${item.code}Max`]}>
|
||||
<InputNumber className="w-full" placeholder={`单位:${item.type === 'float' ? '数值' : '整数'}`} />
|
||||
</Form.Item>
|
||||
<Form.Item label={`${item.name} 下限`} name={['alarmConfig', `${item.code}Min`]}>
|
||||
<InputNumber className="w-full" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
))}
|
||||
{getAlarmProps().length === 0 && <Empty description="该物模型未配置告警参数" />}
|
||||
</TabPane>
|
||||
</Tabs>
|
||||
)}
|
||||
@@ -474,26 +487,20 @@ export default function DeviceAccessPage() {
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="厂商名称" name="manufacturer"><Input /></Form.Item>
|
||||
|
||||
<Divider>厂商级 MQTT Topic 配置</Divider>
|
||||
<Form.Item label="设备上报主题(Publish)" name="publishTopic">
|
||||
<Input placeholder="/iot/device/upload" />
|
||||
</Form.Item>
|
||||
<Form.Item label="平台下发主题(Subscribe)" name="subscribeTopic">
|
||||
<Input placeholder="/iot/device/cmd" />
|
||||
</Form.Item>
|
||||
<div className="text-xs text-gray-500">同一厂商设备自动继承该 Topic</div>
|
||||
<Form.Item label="设备上报主题(Publish)" name="publishTopic"><Input placeholder="/iot/device/upload" /></Form.Item>
|
||||
<Form.Item label="平台下发主题(Subscribe)" name="subscribeTopic"><Input placeholder="/iot/device/cmd" /></Form.Item>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 物模型完整编辑(完全保留你原来的!) */}
|
||||
{/* 物模型完整编辑(含告警参数勾选) */}
|
||||
{modalType === 'model' && (
|
||||
<>
|
||||
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
|
||||
<Form.Item label="模型编码" name="code" rules={[{ required: true }]}><Input /></Form.Item>
|
||||
<Form.Item label="模型描述" name="desc"><Input.TextArea rows={2} /></Form.Item>
|
||||
|
||||
<Divider orientation="left">属性列表</Divider>
|
||||
<Divider orientation="left">属性列表(可勾选作为告警参数)</Divider>
|
||||
<Button size="small" type="primary" icon={<PlusOutlined />} onClick={() => openItemModal('props')} className="mb-2">新增属性</Button>
|
||||
<Table size="small" rowKey="id" columns={propColumns} dataSource={modelDetail.props} pagination={false} />
|
||||
|
||||
@@ -513,22 +520,14 @@ export default function DeviceAccessPage() {
|
||||
<div className="mt-4">
|
||||
<Divider orientation="left">{editData?.name} - 字段映射配置</Divider>
|
||||
<Space className="mb-3">
|
||||
<Button type="primary" size="small" icon={<PlusOutlined />} onClick={() => openMappingModal(editData)}>
|
||||
新增映射
|
||||
</Button>
|
||||
<Button type="primary" size="small" icon={<PlusOutlined />} onClick={() => openMappingModal(editData)}>新增映射</Button>
|
||||
</Space>
|
||||
<Table
|
||||
size="small"
|
||||
rowKey="id"
|
||||
columns={mappingColumns}
|
||||
dataSource={mappingList.filter(item => item.productId === editData?.id)}
|
||||
pagination={false}
|
||||
/>
|
||||
<Table size="small" rowKey="id" columns={mappingColumns} dataSource={mappingList.filter(item => item.productId === editData?.id)} pagination={false} />
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
{/* 物模型子项编辑弹窗 */}
|
||||
{/* 物模型子项编辑弹窗(属性增加isAlarm) */}
|
||||
<Modal
|
||||
open={itemModal}
|
||||
title={itemType === 'props' ? '属性配置' : itemType === 'events' ? '事件配置' : '指令配置'}
|
||||
@@ -538,8 +537,8 @@ export default function DeviceAccessPage() {
|
||||
>
|
||||
<Form form={itemForm} layout="vertical">
|
||||
<Form.Item name="id" hidden><Input /></Form.Item>
|
||||
<Form.Item label="字段编码" name="code" rules={[{ required: true }]}><Input placeholder="如:device_online" /></Form.Item>
|
||||
<Form.Item label="字段名称" name="name" rules={[{ required: true }]}><Input placeholder="如:设备在线状态" /></Form.Item>
|
||||
<Form.Item label="字段编码" name="code" rules={[{ required: true }]}><Input placeholder="如:temp" /></Form.Item>
|
||||
<Form.Item label="字段名称" name="name" rules={[{ required: true }]}><Input placeholder="如:温度" /></Form.Item>
|
||||
{itemType === 'props' && (
|
||||
<>
|
||||
<Form.Item label="数据类型" name="type" rules={[{ required: true }]}>
|
||||
@@ -556,6 +555,9 @@ export default function DeviceAccessPage() {
|
||||
<Option value="rw">读写</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="作为告警参数" name="isAlarm" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
@@ -573,19 +575,18 @@ export default function DeviceAccessPage() {
|
||||
<Form form={mappingForm} layout="vertical">
|
||||
<Form.Item name="id" hidden><Input /></Form.Item>
|
||||
<Form.Item name="productId" hidden><Input /></Form.Item>
|
||||
|
||||
<Form.Item label="平台标准字段" name="standardCode" rules={[{ required: true }]}>
|
||||
<Select placeholder="请选择标准字段">
|
||||
{getStandardPropOptions()}
|
||||
{modelDetail.props?.map((item: any) => (
|
||||
<Option key={item.code} value={item.code}>{item.name}({item.code})</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="厂商原始字段" name="sourceField" rules={[{ required: true }]}>
|
||||
<Input placeholder="例如:online_flag" />
|
||||
<Input placeholder="例如:temperature" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="转换规则" name="convertRule">
|
||||
<Input placeholder="例如:value==1?true:false" />
|
||||
<Input placeholder="例如:value>50" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user