89 lines
2.1 KiB
TypeScript
89 lines
2.1 KiB
TypeScript
import axios from 'axios';
|
|
import { DeviceAlert } from "@/share/monitorTypes";
|
|
|
|
// 告警相关响应类型
|
|
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;
|
|
}
|
|
}
|
|
}; |