diff --git a/src/api/deviceAccess.ts b/src/api/deviceAccess.ts index b821e1d..fefb849 100644 --- a/src/api/deviceAccess.ts +++ b/src/api/deviceAccess.ts @@ -12,7 +12,7 @@ export function addDeviceModel(data) { //物模型列表export function addDeviceModel(data) { export function getDeviceModelList(params) { return request({ - url: ' /iot/deviceModel/list', + url: '/system/devicemodel/list', method: 'get', params }); diff --git a/src/components/SystemSetting/DeviceAccessPage.tsx b/src/components/SystemSetting/DeviceAccessPage.tsx index 186288e..a477ec4 100644 --- a/src/components/SystemSetting/DeviceAccessPage.tsx +++ b/src/components/SystemSetting/DeviceAccessPage.tsx @@ -1,13 +1,13 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Card, Table, Button, Space, Form, Modal, Input, Select, InputNumber, - Tabs, Tag, Popconfirm, message, Divider, Switch, Empty, Checkbox + Tabs, Tag, Popconfirm, message, Divider, Switch, Empty, Checkbox, } from 'antd'; import { PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined, AppstoreOutlined, SwapOutlined, VideoCameraOutlined } from '@ant-design/icons'; -import { addDeviceModel } from '../../api/deviceAccess.ts'; +import { addDeviceModel, getDeviceModelList } from '../../api/deviceAccess.ts'; const { Option } = Select; const { TabPane } = Tabs; @@ -20,18 +20,18 @@ const productList = [ }, { id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华', - publishTopic: '/dahua/device/upload', subscribeTopic: '/dahua/device/cmd' + publishTopic: '/dahua/upload', subscribeTopic: '/dahua/cmd' }, { id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用', - publishTopic: '/iot/device/upload', subscribeTopic: '/iot/device/cmd' + publishTopic: '/iot/upload', subscribeTopic: '/iot/cmd' }, ]; const modelList = [ - { id: 10, name: '通用视频监控设备', code: 'video_camera', desc: '摄像头、云台、告警' }, - { id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感' }, - { id: 12, name: '电池供电设备', code: 'battery_device', desc: '电量、电压监测' }, + { id: 10, name: '通用视频监控设备', code: 'video_camera', desc: '摄像头、云台、告警', connectType: 'MQTT' }, + { id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感', connectType: 'MQTT' }, + { id: 12, name: '电池供电设备', code: 'battery_device', desc: '电量、电压监测', connectType: 'HTTP' }, ]; const modelDetailList: Record { setModalType(type); @@ -134,7 +145,44 @@ export default function DeviceAccessPage() { setVisible(true); }; - // ===================== 物模型提交(完全匹配你的JSON) ===================== + // 获取物模型列表(带分页 + 筛选) + const getModel = () => { + const values = filterForm.getFieldsValue(); + const params = { + pageNum: pagination.current, + pageSize: pagination.pageSize, + name: values.name || '', + connectType: values.connectType || '', + }; + getDeviceModelList(params).then(res => { + // 接口返回格式自行替换:res.list / res.total + if (res.code === 200) { + // setFilteredModelList(res.data.list); + // setPagination(prev => ({ ...prev, total: res.data.total })); + } + }); + }; + + // 筛选 + const handleFilter = () => { + setPagination(prev => ({ ...prev, current: 1 })); + setTimeout(() => getModel(), 0); + }; + + // 重置 + const handleReset = () => { + filterForm.resetFields(); + setPagination(prev => ({ ...prev, current: 1 })); + setTimeout(() => getModel(), 0); + }; + + // 分页切换 + const handleTableChange = (pag) => { + setPagination(pag); + getModel(); + }; + + // ===================== 物模型提交 ===================== const handleSubmit = () => { form.validateFields().then(values => { if (modalType === 'model') { @@ -161,12 +209,10 @@ export default function DeviceAccessPage() { addDeviceModel(submitData).then(res => { if (res.code === 200) { message.success('物模型保存成功'); + getModel(); // 保存后刷新列表 } }); - console.log('✅ 最终提交物模型(完全匹配接口)', submitData); - message.success('物模型保存成功'); - } else { - message.success('保存成功'); + console.log('✅ 提交物模型', submitData); } setVisible(false); }); @@ -205,25 +251,29 @@ export default function DeviceAccessPage() { if (val.id) { const index = newList.findIndex(x => x.id === val.id); if (index >= 0) newList[index] = val; - message.success('字段映射修改成功'); + message.success('修改成功'); } else { newList.push({ ...val, id: Date.now() }); - message.success('字段映射新增成功'); + message.success('新增成功'); } setMappingList(newList); - mappingInitList = newList; setMappingModal(false); }); }; const deleteMapping = (id: number) => { const newList = mappingList.filter(x => x.id !== id); setMappingList(newList); - mappingInitList = newList; - message.success('字段映射删除成功'); + message.success('删除成功'); }; const getAlarmProps = () => modelDetail?.props?.filter(item => item.isAlarm) || []; + useEffect(() => { + if (activeTab === 'model') { + getModel(); + } + }, [ pagination.pageSize, activeTab]); + // 表格列 const deviceColumns = [ { title: '设备名称', dataIndex: 'name' }, @@ -253,6 +303,7 @@ export default function DeviceAccessPage() { const modelColumns = [ { title: '模型名称', dataIndex: 'name' }, + { title: '连接协议', dataIndex: 'connectType' }, { title: '操作', render: r => } ]; @@ -268,7 +319,40 @@ export default function DeviceAccessPage() { {activeTab === 'device' && } {activeTab === 'product' &&
} - {activeTab === 'model' &&
} + + {/* 物模型 + 筛选 + 分页 */} + {activeTab === 'model' && ( + +
+
+ + + + + + + + + + + + +
+ +
+ + )} setVisible(false)} onOk={handleSubmit} destroyOnClose title={modalType === 'device' ? '设备配置' : modalType === 'product' ? '产品配置' : '物模型配置'}> @@ -284,19 +368,43 @@ export default function DeviceAccessPage() { - {deviceProtocol === 'onvif' && <>} - {deviceProtocol === 'rtsp' && } - {deviceProtocol === 'mqtt' && <>} + {deviceProtocol === 'onvif' && ( + <> + + + + + + )} + {deviceProtocol === 'rtsp' && } + {deviceProtocol === 'mqtt' && ( + <> + + + + + + + )} - {getAlarmProps().map(item =>
)} - {getAlarmProps().length === 0 && } + {getAlarmProps().map(item => ( +
+ + + + + + +
+ ))} + {getAlarmProps().length === 0 && }
)} @@ -305,22 +413,28 @@ export default function DeviceAccessPage() { - - - {productProtocol === 'mqtt' && <>MQTT 厂商级 Topic 配置} + + + {productProtocol === 'mqtt' && ( + <> + MQTT Topic + + + + )} - +
x.productId === editData?.id)} pagination={false} columns={[ { title: '标准字段', dataIndex: 'standardCode' }, - { title: '厂商原始字段', dataIndex: 'sourceField' }, + { title: '厂商字段', dataIndex: 'sourceField' }, { title: '转换规则', dataIndex: 'convertRule' }, { title: '操作', render: r => ( - - deleteMapping(r.id)} title="确定删除?"> + + deleteMapping(r.id)}> ) } @@ -332,26 +446,20 @@ export default function DeviceAccessPage() { {modalType === 'model' && ( <> -
-
- - - +
+
+
-
- - - +
+
-
- - - +
+
- 属性列表 - + 属性 +
( - - deleteItem('props', r.id)}> - - + + deleteItem('props', r.id)}> ) } ]} /> - 指令列表 + 指令 + }} className="mb-2">新增
Object.keys(r.params || {}).join(',') || '无' }, + { title: '参数', render: r => Object.keys(r.params || []).join(',') || '无' }, { title: '操作', render: r => ( - { - setModelDetail({ - ...modelDetail, - actions: modelDetail.actions.filter(x => x.actionId !== r.actionId) - }) - }}> + setModelDetail({ ...modelDetail, actions: modelDetail.actions.filter(x => x.actionId !== r.actionId) })}> @@ -410,13 +509,13 @@ export default function DeviceAccessPage() { - {/* 属性弹窗:完整字段 */} + {/* 属性弹窗 */} setItemModal(false)} onOk={saveItem} title="配置属性">
- + - + - - {/**/} - - + + +
- {/* 指令 + 参数 + 枚举 */} - setActionModal(false)} + {/* 指令弹窗 */} + setActionModal(false)} onOk={() => { const params = paramList.reduce((obj, item) => { - obj[item.paramKey] = { - type: item.type, - description: item.desc || '', - default: item.defaultValue, - ...(item.enum?.length ? { enum: item.enum } : {}) - }; + obj[item.paramKey] = { type: item.type, description: item.desc, default: item.defaultValue, ...(item.enum?.length && { enum: item.enum }) }; return obj; }, {}); - - const action = { - actionId: currentAction.actionId, - actionName: currentAction.actionName, - params - }; - + const action = { actionId: currentAction.actionId, actionName: currentAction.actionName, params }; const exists = modelDetail.actions.some(x => x.actionId === currentAction.actionId); setModelDetail({ ...modelDetail, - actions: exists - ? modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x) - : [...modelDetail.actions, action] + actions: exists ? modelDetail.actions.map(x => x.actionId === currentAction.actionId ? action : x) : [...modelDetail.actions, action] }); setActionModal(false); - message.success('保存成功'); }} - width={750} - > -
- setCurrentAction({ ...currentAction, actionId: e.target.value })} - style={{ flex: 1 }} - /> - setCurrentAction({ ...currentAction, actionName: e.target.value })} - style={{ flex: 1 }} - /> + width={750}> +
+ setCurrentAction({ ...currentAction, actionId: e.target.value })} style={{ flex: 1 }} /> + setCurrentAction({ ...currentAction, actionName: e.target.value })} style={{ flex: 1 }} />
- - 指令参数(支持枚举) - - {/* 只保留 1 个参数,不支持新增多行 */} - {paramList.length > 0 && ( -
- { - const arr = [...paramList]; - arr[0].paramKey = e.target.value; - setParamList(arr); - }} /> - setParamList([{ ...paramList[0], paramKey: e.target.value }])} /> + - { - const arr = [...paramList]; - arr[0].desc = e.target.value; - setParamList(arr); - }} /> - { - const arr = [...paramList]; - arr[0].defaultValue = e.target.value; - setParamList(arr); - }} /> - { - const arr = [...paramList]; - arr[0].enum = e.target.value.split(',').map(s => s.trim()); - setParamList(arr); - }} /> + setParamList([{ ...paramList[0], desc: e.target.value }])} /> + setParamList([{ ...paramList[0], defaultValue: e.target.value }])} /> + setParamList([{ ...paramList[0], enum: e.target.value.split(',').map(s => s.trim()) }])} />
)} - - - setMappingModal(false)} onOk={saveMapping} title="字段映射配置"> + {/* 字段映射 */} + setMappingModal(false)} onOk={saveMapping} title="字段映射">