alert.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import axios from 'axios';
  2. import { DeviceAlert } from "../../share/monitorTypes.ts";
  3. // 告警相关响应类型
  4. interface DeviceAlertDataResponse {
  5. data: DeviceAlert[];
  6. total: number;
  7. page: number;
  8. pageSize: number;
  9. }
  10. interface DeviceAlertResponse {
  11. data: DeviceAlert;
  12. message?: string;
  13. }
  14. interface AlertCreateResponse {
  15. data: DeviceAlert;
  16. message: string;
  17. }
  18. interface AlertUpdateResponse {
  19. data: DeviceAlert;
  20. message: string;
  21. }
  22. interface AlertDeleteResponse {
  23. message: string;
  24. }
  25. // 告警API接口定义
  26. export const AlertAPI = {
  27. // 获取告警数据
  28. getAlertData: async (params?: {
  29. page?: number,
  30. limit?: number,
  31. alert_type?: string,
  32. alert_level?: string,
  33. start_time?: string,
  34. end_time?: string
  35. }): Promise<DeviceAlertDataResponse> => {
  36. try {
  37. const response = await axios.get(`/alerts`, { params });
  38. return response.data;
  39. } catch (error) {
  40. throw error;
  41. }
  42. },
  43. // 获取单个告警数据
  44. getAlert: async (id: number): Promise<DeviceAlert> => {
  45. try {
  46. const response = await axios.get(`/alerts/${id}`);
  47. return response.data;
  48. } catch (error) {
  49. throw error;
  50. }
  51. },
  52. // 创建告警数据
  53. createAlert: async (data: Partial<DeviceAlert>): Promise<AlertCreateResponse> => {
  54. try {
  55. const response = await axios.post(`/alerts`, data);
  56. return response.data;
  57. } catch (error) {
  58. throw error;
  59. }
  60. },
  61. // 更新告警数据
  62. updateAlert: async (id: number, data: Partial<DeviceAlert>): Promise<AlertUpdateResponse> => {
  63. try {
  64. const response = await axios.put(`/alerts/${id}`, data);
  65. return response.data;
  66. } catch (error) {
  67. throw error;
  68. }
  69. },
  70. // 删除告警数据
  71. deleteAlert: async (id: number): Promise<AlertDeleteResponse> => {
  72. try {
  73. const response = await axios.delete(`/alerts/${id}`);
  74. return response.data;
  75. } catch (error) {
  76. throw error;
  77. }
  78. }
  79. };