| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import axios from 'axios';
- import { DeviceAlert } from "../../share/monitorTypes.ts";
- // 告警相关响应类型
- interface DeviceAlertDataResponse {
- data: DeviceAlert[];
- total: number;
- page: number;
- pageSize: number;
- }
-
- interface DeviceAlertResponse {
- data: DeviceAlert;
- message?: string;
- }
-
- interface AlertCreateResponse {
- data: DeviceAlert;
- message: string;
- }
-
- interface AlertUpdateResponse {
- data: DeviceAlert;
- message: string;
- }
-
- interface AlertDeleteResponse {
- message: string;
- }
- // 告警API接口定义
- export const AlertAPI = {
- // 获取告警数据
- getAlertData: async (params?: {
- page?: number,
- limit?: number,
- alert_type?: string,
- alert_level?: string,
- start_time?: string,
- end_time?: string
- }): Promise<DeviceAlertDataResponse> => {
- try {
- const response = await axios.get(`/alerts`, { params });
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 获取单个告警数据
- getAlert: async (id: number): Promise<DeviceAlert> => {
- try {
- const response = await axios.get(`/alerts/${id}`);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 创建告警数据
- createAlert: async (data: Partial<DeviceAlert>): Promise<AlertCreateResponse> => {
- try {
- const response = await axios.post(`/alerts`, data);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 更新告警数据
- updateAlert: async (id: number, data: Partial<DeviceAlert>): Promise<AlertUpdateResponse> => {
- try {
- const response = await axios.put(`/alerts/${id}`, data);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
-
- // 删除告警数据
- deleteAlert: async (id: number): Promise<AlertDeleteResponse> => {
- try {
- const response = await axios.delete(`/alerts/${id}`);
- return response.data;
- } catch (error) {
- throw error;
- }
- }
- };
|