From 760eb8eec4ff2d8d37e334c6ddb8a3c8b51f52c5 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Sat, 9 May 2026 12:37:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemSetting/DeviceAccessPage.tsx | 199 ++++++++++++++---- 1 file changed, 163 insertions(+), 36 deletions(-) diff --git a/src/components/SystemSetting/DeviceAccessPage.tsx b/src/components/SystemSetting/DeviceAccessPage.tsx index 5b0163c..6c34d5c 100644 --- a/src/components/SystemSetting/DeviceAccessPage.tsx +++ b/src/components/SystemSetting/DeviceAccessPage.tsx @@ -7,7 +7,7 @@ import { PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined, AppstoreOutlined, SwapOutlined, VideoCameraOutlined } from '@ant-design/icons'; -import { addDeviceModel, getConnectTypes, getDeviceModelList, updateDeviceModel } from '../../api/deviceAccess.ts'; +import { addDeviceModel, addProduct, getConnectTypes, getDeviceModelList, updateDeviceModel } from '../../api/deviceAccess.ts'; const { Option } = Select; const { TabPane } = Tabs; @@ -101,6 +101,7 @@ export default function DeviceAccessPage() { const [itemModal, setItemModal] = useState(false); const [itemType, setItemType] = useState<'props' | 'events' | 'actions'>('props'); const [itemForm] = Form.useForm(); + const [thinsModelList, setThingsModelList] = useState([]); // 指令 + 参数 + 枚举 const [actionModal, setActionModal] = useState(false); @@ -112,6 +113,8 @@ export default function DeviceAccessPage() { const [mappingModal, setMappingModal] = useState(false); const [mappingForm] = Form.useForm(); const [protocolList, setProtocolList] = useState([]); + const [propertyList, setPropertyList] = useState([]); // 物模型属性列表 + const [selectedModelId, setSelectedModelId] = useState(''); // 选中的模型ID // 筛选条件 const [filterForm] = Form.useForm(); @@ -179,10 +182,23 @@ export default function DeviceAccessPage() { setDeviceProtocol(record.protocolType); setModelDetail(modelDetailList[record.modelId] || { props: [] }); } - if (type === 'product') setProductProtocol(record.protocolType || ''); + if (type === 'product') { + setProductProtocol(record?.protocolCode || ''); + // 编辑回显 + const modelId = Object.keys(record?.thingsModels || {})[0] || ''; + const limitConfig = record?.thingsModels?.[modelId] || {}; + const targetModel = filteredModelList.find(m => m.id == modelId); + form.setFieldsValue({ + ...record, + modelId: modelId, + limitConfig: limitConfig, + propertyList: targetModel?.supportProperties || [] + }); + setVisible(true); + } } else { if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); } - else if (type === 'product') setProductProtocol(''); + else if (type === 'product') { setProductProtocol(''); setPropertyList([]) } else setModelDetail({ props: [], events: [], actions: [] }); } setVisible(true); @@ -205,6 +221,20 @@ export default function DeviceAccessPage() { }); }; + const getModelAll = () => { + const params = { + pageNum: 1, + pageSize: 999999, + + }; + getDeviceModelList(params).then(res => { + if (res.code === 200) { + setThingsModelList(res.rows); + + } + }); + }; + // 筛选 const handleFilter = () => { setPagination(prev => ({ ...prev, current: 1 })); @@ -269,6 +299,26 @@ export default function DeviceAccessPage() { }); } } + + if (modalType === 'product') { + form.setFieldValue('modelId', selectedModelId); + const newValues = form.getFieldsValue(); + const { modelId, limitConfig, ...params } = newValues; + // 生成你需要的格式 + const thingsModels = {}; + if (modelId) { + thingsModels[modelId] = limitConfig || {}; + } + const submitData = { + ...params, + thingsModels: thingsModels + }; + addProduct(submitData).then(res => { + if (res.code == 200) { + message.success('新增产品成功'); + } + }) + } setVisible(false); }); }; @@ -331,6 +381,7 @@ export default function DeviceAccessPage() { useEffect(() => { getConnectList(); + getModelAll(); }, []); // 表格列 @@ -515,44 +566,120 @@ export default function DeviceAccessPage() { )} {modalType === 'product' && ( - - - - - - + + + + + + + + + + + + - {productProtocol === 'mqtt' && ( - <> - MQTT Topic - - - - )} - - - - x.productId === editData?.id)} pagination={false} - columns={[ - { title: '标准字段', dataIndex: 'standardCode' }, - { title: '厂商字段', dataIndex: 'sourceField' }, - { title: '转换规则', dataIndex: 'convertRule' }, - { - title: '操作', render: r => ( - - - deleteMapping(r.id)}> - - ) + + + + + + + + + + + + + + + {/* ============ 物模型选择(直接放在基础信息里) ============ */} + 物模型属性配置 + + + + + {/* 隐藏字段存储数据 */} + + + + {/* ============ 自动渲染属性 + min/max输入框 ============ */} + {/* ============ 自动渲染属性 + min/max输入框 ============ */} +
+ {/* 👇 这里从 state 取,同步秒刷新 */} + {propertyList?.map((item) => ( +
+
+ {item.propertyName}({item.propertyKey}) +
+
+ + + + + + +
+
+ ))} + + {(!propertyList || propertyList.length === 0) && ( +
+ 请选择物模型以显示属性 +
+ )} +
+ + )} {modalType === 'model' && (