device_instance.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import axios from "axios";
  2. import { DeviceInstance, DeviceType, ZichanInfo } from "../../share/monitorTypes.ts";
  3. // 设备实例API接口定义
  4. interface DeviceInstancesResponse {
  5. data: DeviceInstance[];
  6. pagination: {
  7. total: number;
  8. current: number;
  9. pageSize: number;
  10. totalPages: number;
  11. };
  12. }
  13. interface DeviceInstanceResponse {
  14. data: DeviceInstance;
  15. asset_info?: ZichanInfo;
  16. type_info?: DeviceType;
  17. message?: string;
  18. }
  19. interface DeviceInstanceCreateResponse {
  20. message: string;
  21. data: DeviceInstance;
  22. }
  23. interface DeviceInstanceUpdateResponse {
  24. message: string;
  25. data: DeviceInstance;
  26. }
  27. interface DeviceInstanceDeleteResponse {
  28. message: string;
  29. id: number;
  30. }
  31. export const DeviceInstanceAPI = {
  32. // 获取设备实例列表
  33. getDeviceInstances: async (params?: {
  34. page?: number,
  35. limit?: number,
  36. type_id?: number,
  37. protocol?: string,
  38. status?: number
  39. }): Promise<DeviceInstancesResponse> => {
  40. try {
  41. const response = await axios.get('/device/instances', { params });
  42. return response.data;
  43. } catch (error) {
  44. throw error;
  45. }
  46. },
  47. // 获取单个设备实例信息
  48. getDeviceInstance: async (id: number): Promise<DeviceInstanceResponse> => {
  49. try {
  50. const response = await axios.get(`/device/instances/${id}`);
  51. return response.data;
  52. } catch (error) {
  53. throw error;
  54. }
  55. },
  56. // 创建设备实例
  57. createDeviceInstance: async (data: Partial<DeviceInstance>): Promise<DeviceInstanceCreateResponse> => {
  58. try {
  59. const response = await axios.post('/device/instances', data);
  60. return response.data;
  61. } catch (error) {
  62. throw error;
  63. }
  64. },
  65. // 更新设备实例
  66. updateDeviceInstance: async (id: number, data: Partial<DeviceInstance>): Promise<DeviceInstanceUpdateResponse> => {
  67. try {
  68. const response = await axios.put(`/device/instances/${id}`, data);
  69. return response.data;
  70. } catch (error) {
  71. throw error;
  72. }
  73. },
  74. // 删除设备实例
  75. deleteDeviceInstance: async (id: number): Promise<DeviceInstanceDeleteResponse> => {
  76. try {
  77. const response = await axios.delete(`/device/instances/${id}`);
  78. return response.data;
  79. } catch (error) {
  80. throw error;
  81. }
  82. }
  83. };