diff --git a/src/api/deviceAccess.ts b/src/api/deviceAccess.ts index 235a558..60d3e5c 100644 --- a/src/api/deviceAccess.ts +++ b/src/api/deviceAccess.ts @@ -96,6 +96,27 @@ export function deleteModel(id) { }); } +//新增设备 + +export function addIotDevice(data) { + return request({ + url: `/system/iotDevice/add`, + method: 'post', + data + + }); +} +//编辑设备 + +export function updateIotDevice(data) { + return request({ + url: `/system/iotDevice/update`, + method: 'post', + data + + }); +} + diff --git a/src/components/SystemSetting/DeviceAccessPage.tsx b/src/components/SystemSetting/DeviceAccessPage.tsx index 8905dc1..7cbb256 100644 --- a/src/components/SystemSetting/DeviceAccessPage.tsx +++ b/src/components/SystemSetting/DeviceAccessPage.tsx @@ -8,6 +8,7 @@ import { AppstoreOutlined, SwapOutlined, VideoCameraOutlined } from '@ant-design/icons'; import { addDeviceModel, addProduct, deleteModel, deleteProduct, getConnectTypes, getDataTypesApi, getDeviceModelList, getProductPage, updateDeviceModel, updateProduct } from '../../api/deviceAccess.ts'; +import { Z_FIXED } from 'zlib'; const { Option } = Select; const { TabPane } = Tabs; @@ -197,6 +198,7 @@ export default function DeviceAccessPage() { await fetchProtocolList(); await fetchDataTypeList(); await fetchAllModelList(); + await fetchProductPageList(); if (record) { form.setFieldsValue(record); @@ -238,7 +240,7 @@ export default function DeviceAccessPage() { } } } else { - if (type === 'device') { setDeviceProtocol('onvif'); setModelDetail({ props: [] }); } + if (type === 'device') { setDeviceProtocol(''); setModelDetail({ props: [] }); } else if (type === 'product') { setProductProtocol(''); setPropertyList([]); form.setFieldsValue({ status: 1 }); } else setModelDetail({ props: [], events: [], actions: [] }); } @@ -404,7 +406,7 @@ export default function DeviceAccessPage() { { title: '物模型', dataIndex: 'modelName' }, { title: '协议', render: t => {t.protocolType.toUpperCase()} }, { title: '状态', render: r => {r.onlineStatus ? '在线' : '离线'} }, - { title: '操作', render: r => } + { title: '操作', fixed: "right", render: r => } ]; const modelColumns = [ @@ -425,7 +427,7 @@ export default function DeviceAccessPage() { } }, { - title: '操作', render: r => ( + title: '操作', fixed: "right", render: r => ( handleDeleteModel(r.id)} okText="确定" cancelText="取消"> @@ -446,7 +448,14 @@ export default function DeviceAccessPage() { - {activeTab === 'device' && } + {activeTab === 'device' && +
+
+ + + + + } {activeTab === 'product' && (
@@ -513,7 +522,7 @@ export default function DeviceAccessPage() { render: (s) => {s === 1 ? '启用' : '禁用'} }, { - title: '操作', width: 180, render: (r) => ( + title: '操作', fixed: "right", width: 180, render: (r) => ( @@ -565,8 +574,10 @@ export default function DeviceAccessPage() {
+
+
-
+ )} @@ -596,7 +607,29 @@ export default function DeviceAccessPage() { name="productId" rules={[{ required: true, message: '请选择关联产品' }]} > - { + // 核心逻辑:选择产品后自动加载协议并回填 + const targetProduct = productList.find(p => p.id === val); + if (targetProduct) { + const protocol = targetProduct.protocolCode || ''; + // 自动设置协议并回填表单 + setDeviceProtocol(protocol.toUpperCase()); + form.setFieldsValue({ protocolType: protocol }); + + // 自动回填产品里的协议配置 + const configFields = ['ip', 'port', 'username', 'password', 'rtspUrl', 'mqttServer', 'mqttPort', 'clientId', 'mqttUsername', 'mqttPassword']; + const configValues = {}; + configFields.forEach(field => { + if (targetProduct[field] !== undefined) { + configValues[field] = targetProduct[field]; + } + }); + form.setFieldsValue(configValues); + } + }} + > {productList.map(p => (