| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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<DeviceInstancesResponse> => {
- try {
- const response = await axios.get('/device/instances', { params });
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 获取单个设备实例信息
- getDeviceInstance: async (id: number): Promise<DeviceInstanceResponse> => {
- try {
- const response = await axios.get(`/device/instances/${id}`);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 创建设备实例
- createDeviceInstance: async (data: Partial<DeviceInstance>): Promise<DeviceInstanceCreateResponse> => {
- try {
- const response = await axios.post('/device/instances', data);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 更新设备实例
- updateDeviceInstance: async (id: number, data: Partial<DeviceInstance>): Promise<DeviceInstanceUpdateResponse> => {
- try {
- const response = await axios.put(`/device/instances/${id}`, data);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 删除设备实例
- deleteDeviceInstance: async (id: number): Promise<DeviceInstanceDeleteResponse> => {
- try {
- const response = await axios.delete(`/device/instances/${id}`);
- return response.data;
- } catch (error) {
- throw error;
- }
- }
- };
|