import axios from "axios"; import { DeviceInstance, DeviceType, ZichanInfo } from "../../share/monitorTypes.ts"; // 设备实例API接口定义 interface DeviceInstancesResponse { data: DeviceInstance[]; pagination: { total: number; current: number; pageSize: number; totalPages: number; }; } interface DeviceInstanceResponse { data: DeviceInstance; asset_info?: ZichanInfo; type_info?: DeviceType; message?: string; } interface DeviceInstanceCreateResponse { message: string; data: DeviceInstance; } interface DeviceInstanceUpdateResponse { message: string; data: DeviceInstance; } interface DeviceInstanceDeleteResponse { message: string; id: number; } export const DeviceInstanceAPI = { // 获取设备实例列表 getDeviceInstances: async (params?: { page?: number, limit?: number, type_id?: number, protocol?: string, status?: number }): Promise => { try { const response = await axios.get('/device/instances', { params }); return response.data; } catch (error) { throw error; } }, // 获取单个设备实例信息 getDeviceInstance: async (id: number): Promise => { try { const response = await axios.get(`/device/instances/${id}`); return response.data; } catch (error) { throw error; } }, // 创建设备实例 createDeviceInstance: async (data: Partial): Promise => { try { const response = await axios.post('/device/instances', data); return response.data; } catch (error) { throw error; } }, // 更新设备实例 updateDeviceInstance: async (id: number, data: Partial): Promise => { try { const response = await axios.put(`/device/instances/${id}`, data); return response.data; } catch (error) { throw error; } }, // 删除设备实例 deleteDeviceInstance: async (id: number): Promise => { try { const response = await axios.delete(`/device/instances/${id}`); return response.data; } catch (error) { throw error; } } };