diff --git a/src/pages/DeviceAccessPage.tsx b/src/pages/DeviceAccessPage.tsx new file mode 100644 index 0000000..552b624 --- /dev/null +++ b/src/pages/DeviceAccessPage.tsx @@ -0,0 +1,511 @@ +import { useState } from 'react'; +import { + Card, Table, Button, Space, Form, Modal, Input, Select, InputNumber, + Tabs, Tag, Popconfirm, message, Descriptions, Divider, Empty +} from 'antd'; +import { + PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined, + AppstoreOutlined, SwapOutlined, VideoCameraOutlined, AlertOutlined +} from '@ant-design/icons'; + +const { Option } = Select; +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 }, +]; + +const modelList = [ + { id: 10, name: '通用视频监控设备', code: 'video_camera', desc: '摄像头、云台、告警' }, + { id: 11, name: '环境监测设备', code: 'env_sensor', desc: '温湿度、烟感' }, +]; + +// 物模型详情 +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' }, + ], + 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: '开启/关闭录像' }, + ] + } +}; + +// 字段映射数据 +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', + onlineStatus: 1, + createTime: '2026-05-07 10:23:45' + }, +]; + +const alarmList = [ + { id: 1, deviceId: 1, deviceName: '1#阵列区球机', level: 'warn', content: '周界入侵告警', time: '2026-05-07 10:23:41', status: 0 }, +]; + +export default function DeviceAccessPage() { + const [activeTab, setActiveTab] = useState('device'); + const [form] = Form.useForm(); + const [visible, setVisible] = useState(false); + const [modalType, setModalType] = useState(''); + const [editData, setEditData] = useState(null); + const [protocol, setProtocol] = useState('onvif'); + + // 物模型详情 + const [modelDetail, setModelDetail] = useState({ props: [], events: [], actions: [] }); + // 模型子项弹窗(属性/事件/动作) + const [itemModal, setItemModal] = useState(false); + const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props'); + const [itemForm] = Form.useForm(); + + // 字段映射 + const [mappingList, setMappingList] = useState(mappingInitList); + const [mappingModal, setMappingModal] = useState(false); + const [mappingForm] = Form.useForm(); + + // 打开主弹窗 + const openModal = (type: string, record?: any) => { + setModalType(type); + setEditData(record); + form.resetFields(); + + if (record) { + form.setFieldsValue(record); + if (type === 'model') { + setModelDetail(modelDetailList[record.id] || { props: [], events: [], actions: [] }); + } + } else { + setModelDetail({ props: [], events: [], actions: [] }); + } + + setVisible(true); + }; + + // 主表单保存 + const handleSubmit = () => { + form.validateFields().then(() => { + message.success('保存成功'); + setVisible(false); + }); + }; + + // ========== 物模型 增删改 ========== + const openItemModal = (type: 'props' | 'events' | 'actions', record?: any) => { + setItemType(type); + itemForm.resetFields(); + if (record) itemForm.setFieldsValue(record); + setItemModal(true); + }; + + const saveItem = () => { + itemForm.validateFields().then((val) => { + const list = [...modelDetail[itemType]]; + if (val.id) { + const idx = list.findIndex(x => x.id === val.id); + idx >= 0 && (list[idx] = val); + } else { + list.push({ ...val, id: Date.now() }); + } + setModelDetail({ ...modelDetail, [itemType]: list }); + setItemModal(false); + message.success('保存成功'); + }); + }; + + const deleteItem = (type: 'props' | 'events' | 'actions', id: number) => { + const list = modelDetail[type].filter(x => x.id !== id); + setModelDetail({ ...modelDetail, [type]: list }); + message.success('删除成功'); + }; + + // ========== 字段映射 增删改 核心 ========== + const openMappingModal = (record: any, row?: any) => { + setVisible(false); + mappingForm.resetFields(); + if (row) { + mappingForm.setFieldsValue(row); + } else { + mappingForm.setFieldsValue({ productId: record.id }); + } + setMappingModal(true); + }; + + const saveMapping = () => { + mappingForm.validateFields().then((val) => { + const list = [...mappingList]; + if (val.id) { + const idx = list.findIndex(item => item.id === val.id); + list[idx] = val; + } else { + list.push({ ...val, id: Date.now() }); + } + setMappingList(list); + setMappingModal(false); + message.success('字段映射保存成功'); + setTimeout(() => setVisible(true), 300); + }); + }; + + const delMapping = (id: number) => { + const list = mappingList.filter(item => item.id !== id); + setMappingList(list); + message.success('删除成功'); + }; + + // 获取当前模型标准属性下拉 + const getStandardPropOptions = () => { + if (!modelDetail?.props) return []; + return modelDetail.props.map((item: any) => ( + + )); + }; + + // 表格列 + const deviceColumns = [ + { title: '设备名称', dataIndex: 'name' }, + { title: 'SN', dataIndex: 'sn' }, + { title: '所属产品', dataIndex: 'productName' }, + { title: '物模型', dataIndex: 'modelName' }, + { title: '协议', dataIndex: 'protocolType', render: (t: string) => {t.toUpperCase()} }, + { title: 'IP', dataIndex: 'ip' }, + { title: '状态', dataIndex: 'onlineStatus', render: (s: number) => {s === 1 ? '在线' : '离线'} }, + { + title: '操作', render: (r: any) => ( + + + + ) + } + ]; + + const productColumns = [ + { title: '产品名称', dataIndex: 'name' }, + { title: '产品编码', dataIndex: 'code' }, + { title: '协议类型', dataIndex: 'protocolType', render: (t: string) => {t.toUpperCase()} }, + { title: '厂商', dataIndex: 'manufacturer' }, + { + title: '操作', render: (r: any) => ( + + + + + ) + } + ]; + + const modelColumns = [ + { title: '模型名称', dataIndex: 'name' }, + { title: '模型编码', dataIndex: 'code' }, + { title: '描述', dataIndex: 'desc' }, + { title: '操作', render: (r: any) => } + ]; + + // 字段映射列表列 + const mappingColumns = [ + { title: '标准模型字段', dataIndex: 'standardCode' }, + { title: '厂商原始字段', dataIndex: 'sourceField' }, + { title: '转换规则', dataIndex: 'convertRule' }, + { + title: '操作', render: (r: any) => ( + + + delMapping(r.id)}> + + + + ) + } + ]; + + const alarmColumns = [ + { title: '设备名称', dataIndex: 'deviceName' }, + { title: '告警级别', dataIndex: 'level' }, + { title: '告警内容', dataIndex: 'content' }, + { title: '告警时间', dataIndex: 'time' }, + ]; + + // 物模型子项列 + const propColumns = [ + { title: '字段编码', dataIndex: 'code' }, + { title: '字段名称', dataIndex: 'name' }, + { title: '数据类型', dataIndex: 'type' }, + { title: '读写类型', dataIndex: 'rw' }, + { + title: '操作', render: (r: any) => ( + + + deleteItem('props', r.id)}> + + + + ) + } + ]; + + const eventActionColumns = [ + { title: '编码', dataIndex: 'code' }, + { title: '名称', dataIndex: 'name' }, + { + title: '操作', render: (r: any) => ( + + + deleteItem(itemType, r.id)}> + + + + ) + } + ]; + + return ( +
+ + + 设备管理} key="device" /> + 产品管理} key="product" /> + 物模型管理} key="model" /> + 告警列表} key="alarm" /> + + + + {/* 设备管理 */} + {activeTab === 'device' && ( + + + + + + + )} + + {/* 产品管理 */} + {activeTab === 'product' && ( + + + + +
+ + )} + + {/* 物模型管理 */} + {activeTab === 'model' && ( + + + + +
+ + )} + + {/* 告警列表 */} + {activeTab === 'alarm' && ( + +
+ + )} + + {/* 主弹窗:设备/产品/物模型 */} + setVisible(false)} + onOk={handleSubmit} + width={750} + destroyOnClose + > +
+ {/* 设备接入 */} + {modalType === 'device' && ( + + + + + + + + + + + + + {protocol === 'onvif' && ( + <> + + + + + + )} + {protocol === 'rtsp' && ( + + )} + + + )} + + {/* 产品配置 */} + {modalType === 'product' && ( + <> + + + + + + + + )} + + {/* 物模型完整编辑 */} + {modalType === 'model' && ( + <> + + + + + 属性列表 + +
+ + 事件列表 + +
+ + 服务/指令 + +
+ + )} + + + {/* ========== 字段映射列表(独立显示,不嵌套) ========== */} + {modalType === 'mapping' && ( +
+ + {editData?.name} - 字段映射配置 + + + + +
item.productId === editData?.id)} + pagination={false} + /> + + )} + + + {/* 物模型子项编辑弹窗(属性/事件/动作) */} + setItemModal(false)} + onOk={saveItem} + width={520} + > +
+ + + + {itemType === 'props' && ( + <> + + + + + + + + )} + +
+ + {/* ========== 字段映射弹窗(完全独立,显示正常) ========== */} + setMappingModal(false)} + onOk={saveMapping} + width={600} + destroyOnClose + > +
+ + + + + + + + + + + + + + + +
+ 说明:将设备上报的私有字段,转换为平台统一标准字段 +
+
+ + ); +} diff --git a/src/pages/SystemSetting.tsx b/src/pages/SystemSetting.tsx index a7a265a..ad40589 100644 --- a/src/pages/SystemSetting.tsx +++ b/src/pages/SystemSetting.tsx @@ -16,6 +16,7 @@ import MenuList from './MenuList'; import Organization from './Organization'; import StationManage from './StationManage'; import { getMenuList } from '../api/mune'; +import DeviceAccessPage from './DeviceAccessPage'; const { Header, Content } = Layout; const { Text } = Typography; @@ -169,7 +170,7 @@ export default function SystemSettings() { }, []); const BasicSettingsPage = () =>

基础设置页面

; const NoticePage = () =>

通知策略页面

; - const DeviceAccessPage = () =>

设备接入页面

; + //const DeviceAccessPage = () =>

设备接入页面

; const DataSafetyPage = () =>

数据与安全页面

; const SystemMaintenancePage = () =>

系统维护页面

; const DefaultPage = () =>

请选择菜单

;