设备接入 细节搭建

This commit is contained in:
mmc
2026-05-07 09:40:07 +08:00
parent ed32020a0e
commit ac5b531a6f
2 changed files with 103 additions and 21 deletions

View File

@@ -13,9 +13,18 @@ const { TabPane } = Tabs;
// ====================== 模拟基础数据 ======================
const productList = [
{ id: 1, name: '海康威视摄像头', code: 'hikvision', protocolType: 'onvif', manufacturer: '海康', status: 1 },
{ id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华', status: 1 },
{ id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用', status: 1 },
{
id: 1, name: '海康威视摄像头', code: 'hikvision', protocolType: 'onvif', manufacturer: '海康', status: 1,
publishTopic: '/hik/device/upload', subscribeTopic: '/hik/device/cmd'
},
{
id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华', status: 1,
publishTopic: '/dahua/device/upload', subscribeTopic: '/dahua/device/cmd'
},
{
id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用', status: 1,
publishTopic: '/iot/device/upload', subscribeTopic: '/iot/device/cmd'
},
];
const modelList = [
@@ -23,7 +32,7 @@ const modelList = [
{ id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感' },
];
// 物模型详情
// 物模型详情(完全保留你原来的)
const modelDetailList: Record<number, {
props: any[];
events: any[];
@@ -43,6 +52,16 @@ const modelDetailList: Record<number, {
{ 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' },
],
events: [
{ id: 1, code: 'temp_over', name: '超温告警' },
],
actions: []
}
};
@@ -66,6 +85,19 @@ const deviceList = [
port: 80,
username: 'admin',
password: '123456',
mqttServer: '',
mqttPort: 1883,
clientId: '',
mqttUsername: '',
mqttPassword: '',
alarmConfig: {
tempMax: 60,
tempMin: 0,
humiMax: 90,
humiMin: 20,
batteryMax: 100,
batteryMin: 10
},
onlineStatus: 1,
createTime: '2026-05-07 10:23:45'
},
@@ -106,6 +138,9 @@ export default function DeviceAccessPage() {
if (type === 'model') {
setModelDetail(modelDetailList[record.id] || { props: [], events: [], actions: [] });
}
if (type === 'device') {
setProtocol(record.protocolType);
}
} else {
setModelDetail({ props: [], events: [], actions: [] });
}
@@ -173,8 +208,8 @@ export default function DeviceAccessPage() {
}
setMappingList(list);
setMappingModal(false);
message.success('字段映射保存成功');
setTimeout(() => setVisible(true), 300);
message.success('字段映射保存成功');
});
};
@@ -213,8 +248,10 @@ export default function DeviceAccessPage() {
const productColumns = [
{ title: '产品名称', dataIndex: 'name' },
{ title: '产品编码', dataIndex: 'code' },
{ title: '协议类型', dataIndex: 'protocolType', render: (t: string) => <Tag>{t.toUpperCase()}</Tag> },
{ title: '厂商', dataIndex: 'manufacturer' },
{ title: '协议类型', dataIndex: 'protocolType', render: (t: string) => <Tag>{t.toUpperCase()}</Tag> },
{ title: '上报Topic', dataIndex: 'publishTopic' },
{ title: '订阅Topic', dataIndex: 'subscribeTopic' },
{
title: '操作', render: (r: any) => (
<Space>
@@ -232,7 +269,6 @@ export default function DeviceAccessPage() {
{ title: '操作', render: (r: any) => <Button type="text" icon={<EditOutlined />} onClick={() => openModal('model', r)}>编辑</Button> }
];
// 字段映射列表列
const mappingColumns = [
{ title: '标准模型字段', dataIndex: 'standardCode' },
{ title: '厂商原始字段', dataIndex: 'sourceField' },
@@ -256,7 +292,6 @@ export default function DeviceAccessPage() {
{ title: '告警时间', dataIndex: 'time' },
];
// 物模型子项列
const propColumns = [
{ title: '字段编码', dataIndex: 'code' },
{ title: '字段名称', dataIndex: 'name' },
@@ -348,10 +383,11 @@ export default function DeviceAccessPage() {
}
onCancel={() => setVisible(false)}
onOk={handleSubmit}
width={750}
width={800}
destroyOnClose
>
<Form form={form} layout="vertical">
{/* 设备接入 */}
{modalType === 'device' && (
<Tabs defaultActiveKey="base">
@@ -367,6 +403,7 @@ export default function DeviceAccessPage() {
<Select>{modelList.map(m => <Option key={m.id} value={m.id}>{m.name}</Option>)}</Select>
</Form.Item>
</TabPane>
<TabPane tab="协议配置" key="protocol">
{protocol === 'onvif' && (
<>
@@ -376,14 +413,55 @@ export default function DeviceAccessPage() {
<Form.Item label="登录密码" name="password"><Input.Password /></Form.Item>
</>
)}
{protocol === 'rtsp' && (
<Form.Item label="RTSP流地址" name="rtspUrl"><Input placeholder="rtsp://xxx" /></Form.Item>
)}
{protocol === 'mqtt' && (
<>
<Card size="small" title="MQTT连接配置" className="mb-2">
<Form.Item label="MQTT服务器" name="mqttServer"><Input placeholder="tcp://192.168.1.200" /></Form.Item>
<Form.Item label="端口" name="mqttPort"><InputNumber className="w-full" defaultValue={1883} /></Form.Item>
<Form.Item label="ClientID" name="clientId"><Input placeholder="设备唯一标识" /></Form.Item>
<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>
</Card>
</>
)}
</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>
</TabPane>
</Tabs>
)}
{/* 产品配置 */}
{/* 产品配置 + MQTT Topic */}
{modalType === 'product' && (
<>
<Form.Item label="产品名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
@@ -396,10 +474,19 @@ 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>
</>
)}
{/* 物模型完整编辑 */}
{/* 物模型完整编辑(完全保留你原来的!) */}
{modalType === 'model' && (
<>
<Form.Item label="模型名称" name="name" rules={[{ required: true }]}><Input /></Form.Item>
@@ -421,12 +508,10 @@ export default function DeviceAccessPage() {
)}
</Form>
{/* ========== 字段映射列表(独立显示,不嵌套) ========== */}
{/* 字段映射列表 */}
{modalType === 'mapping' && (
<div className="mt-4">
<Divider orientation="left">
{editData?.name} - 字段映射配置
</Divider>
<Divider orientation="left">{editData?.name} - 字段映射配置</Divider>
<Space className="mb-3">
<Button type="primary" size="small" icon={<PlusOutlined />} onClick={() => openMappingModal(editData)}>
新增映射
@@ -443,7 +528,7 @@ export default function DeviceAccessPage() {
)}
</Modal>
{/* 物模型子项编辑弹窗(属性/事件/动作) */}
{/* 物模型子项编辑弹窗 */}
<Modal
open={itemModal}
title={itemType === 'props' ? '属性配置' : itemType === 'events' ? '事件配置' : '指令配置'}
@@ -461,6 +546,7 @@ export default function DeviceAccessPage() {
<Select>
<Option value="bool">布尔 bool</Option>
<Option value="int">数字 int</Option>
<Option value="float">浮点 float</Option>
<Option value="string">字符串 string</Option>
</Select>
</Form.Item>
@@ -475,7 +561,7 @@ export default function DeviceAccessPage() {
</Form>
</Modal>
{/* ========== 字段映射弹窗(完全独立,显示正常) ========== */}
{/* 字段映射弹窗 */}
<Modal
open={mappingModal}
title="字段映射配置"
@@ -502,9 +588,6 @@ export default function DeviceAccessPage() {
<Input placeholder="例如:value==1?true:false" />
</Form.Item>
</Form>
<div className="text-xs text-gray-500 mt-4">
说明:将设备上报的私有字段,转换为平台统一标准字段
</div>
</Modal>
</div>
);

View File

@@ -170,7 +170,6 @@ export default function SystemSettings() {
}, []);
const BasicSettingsPage = () => <div style={{ padding: 20 }}><h2>基础设置页面</h2></div>;
const NoticePage = () => <div style={{ padding: 20 }}><h2>通知策略页面</h2></div>;
//const DeviceAccessPage = () => <div style={{ padding: 20 }}><h2>设备接入页面</h2></div>;
const DataSafetyPage = () => <div style={{ padding: 20 }}><h2>数据与安全页面</h2></div>;
const SystemMaintenancePage = () => <div style={{ padding: 20 }}><h2>系统维护页面</h2></div>;
const DefaultPage = () => <div style={{ padding: 20 }}><h2>请选择菜单</h2></div>;