diff --git a/src/api/deviceAccess.ts b/src/api/deviceAccess.ts index 44e867f..a5f33ba 100644 --- a/src/api/deviceAccess.ts +++ b/src/api/deviceAccess.ts @@ -51,6 +51,25 @@ export function getConnectTypes(params) { +export function getProductPage(params) { + return request({ + url: '/system/product/list', + method: 'get', + params + }); +} + +//数据类型的枚举 +export function getDataTypesApi(params) { + return request({ + url: '/system/devicemodel/DataTypes', + method: 'get', + params + }); +} + + + diff --git a/src/components/SystemSetting/DeviceAccessPage.tsx b/src/components/SystemSetting/DeviceAccessPage.tsx index 6c34d5c..32a390d 100644 --- a/src/components/SystemSetting/DeviceAccessPage.tsx +++ b/src/components/SystemSetting/DeviceAccessPage.tsx @@ -7,32 +7,12 @@ import { PlusOutlined, EditOutlined, DeleteOutlined, ProductOutlined, AppstoreOutlined, SwapOutlined, VideoCameraOutlined } from '@ant-design/icons'; -import { addDeviceModel, addProduct, getConnectTypes, getDeviceModelList, updateDeviceModel } from '../../api/deviceAccess.ts'; +import { addDeviceModel, addProduct, getConnectTypes, getDataTypesApi, getDeviceModelList, getProductPage, updateDeviceModel } from '../../api/deviceAccess.ts'; const { Option } = Select; const { TabPane } = Tabs; -// ====================== 模拟基础数据 ====================== -const productList = [ - { - id: 1, name: '海康威视摄像头', code: 'hikvision', protocolType: 'onvif', manufacturer: '海康', - publishTopic: '/hik/device/upload', subscribeTopic: '/hik/device/cmd' - }, - { - id: 2, name: '大华摄像头', code: 'dahua', protocolType: 'rtsp', manufacturer: '大华', - publishTopic: '/dahua/upload', subscribeTopic: '/dahua/cmd' - }, - { - id: 3, name: '通用MQTT设备', code: 'mqtt_device', protocolType: 'mqtt', manufacturer: '通用', - publishTopic: '/iot/upload', subscribeTopic: '/iot/cmd' - }, -]; -const modelList = [ - { 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(null); + const [productList, setProductList] = useState([]); const [deviceProtocol, setDeviceProtocol] = useState('onvif'); const [productProtocol, setProductProtocol] = useState(''); @@ -118,7 +98,7 @@ export default function DeviceAccessPage() { // 筛选条件 const [filterForm] = Form.useForm(); - const [filteredModelList, setFilteredModelList] = useState(modelList); + const [filteredModelList, setFilteredModelList] = useState([]); // ========== 物模型分页 ========== const [pagination, setPagination] = useState({ @@ -238,20 +218,53 @@ export default function DeviceAccessPage() { // 筛选 const handleFilter = () => { setPagination(prev => ({ ...prev, current: 1 })); - getModel(); + if (activeTab === 'model') getModel(); + if (activeTab === 'product') getProductList(); // 产品列表 }; // 重置 const handleReset = () => { filterForm.resetFields(); setPagination(prev => ({ ...prev, current: 1 })); - getModel(); + if (activeTab === 'model') getModel(); + if (activeTab === 'product') getProductList(); }; + const getDataTypes = () => { + getDataTypesApi("").then(res => { + + }) + } // 分页切换 const handleTableChange = (pag) => { setPagination(pag); - getModel(); + if (activeTab === 'model') getModel(); + if (activeTab === 'product') getProductList(); + }; + // ====================== 获取产品列表 ====================== + const getProductList = () => { + const values = filterForm.getFieldsValue(); + const params = { + pageNum: pagination.current, + pageSize: pagination.pageSize, + code: values.code || '', + name: values.name || '', + manufacturer: values.manufacturer || '', + categoryId: values.categoryId || '', + protocolCode: values.protocolCode || '', + transport: values.transport || '', + uploadTopic: values.uploadTopic || '', + subscribeTopic: values.subscribeTopic || '', + status: values.status ?? '', + }; + + // 这里调用你的【产品列表接口】 + getProductPage(params).then(res => { + if (res.code === 200) { + setProductList(res.rows); + setPagination(prev => ({ ...prev, total: res.total })); + } + }); }; // ===================== 物模型提交 ===================== @@ -304,18 +317,34 @@ export default function DeviceAccessPage() { form.setFieldValue('modelId', selectedModelId); const newValues = form.getFieldsValue(); const { modelId, limitConfig, ...params } = newValues; - // 生成你需要的格式 + + // ====================== + // 👇 强制给默认值 0 ~ 100 + // ====================== + const finalLimitConfig = {}; + if (limitConfig) { + Object.keys(limitConfig).forEach(key => { + finalLimitConfig[key] = { + min: limitConfig[key].min ?? 0, + max: limitConfig[key].max ?? 100, + }; + }); + } + const thingsModels = {}; if (modelId) { - thingsModels[modelId] = limitConfig || {}; + thingsModels[modelId] = finalLimitConfig; // 👈 用处理后的 } + const submitData = { ...params, - thingsModels: thingsModels + thingsModels: thingsModels, }; + addProduct(submitData).then(res => { if (res.code == 200) { message.success('新增产品成功'); + getProductList() } }) } @@ -382,6 +411,8 @@ export default function DeviceAccessPage() { useEffect(() => { getConnectList(); getModelAll(); + getProductList(); + getDataTypes(); }, []); // 表格列 @@ -475,8 +506,95 @@ export default function DeviceAccessPage() { {activeTab === 'device' && } - {activeTab === 'product' &&
} + {activeTab === 'product' && ( + + {/* ====================== 产品筛选表单 ====================== */} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + {/* ====================== 产品表格 ====================== */} +
{s === 1 ? '启用' : '禁用'} + }, + { + title: '操作', + width: 120, + render: (r) => ( + + + + ) + } + ]} + dataSource={productList} + pagination={{ + current: pagination.current, + pageSize: pagination.pageSize, + total: pagination.total, + showSizeChanger: true, + showTotal: (total) => `共 ${total} 条` + }} + onChange={handleTableChange} + /> + + )} {/* 物模型 + 筛选 + 分页 */} {activeTab === 'model' && ( @@ -519,7 +637,7 @@ export default function DeviceAccessPage() { - + {/**/} @@ -659,14 +777,15 @@ export default function DeviceAccessPage() { style={{ flex: 1 }} > - + - +