zichan.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import axios from "axios";
  2. import { DeviceCategory, DeviceStatus, ZichanInfo } from "../../share/monitorTypes.ts";
  3. // 资产管理API
  4. export const ZichanAPI = {
  5. // 获取资产列表
  6. getZichanList: async (params?: {
  7. page?: number,
  8. limit?: number,
  9. asset_name?: string,
  10. device_category?: DeviceCategory,
  11. device_status?: DeviceStatus
  12. }) => {
  13. try {
  14. const response = await axios.get(`/zichan`, { params });
  15. return response.data;
  16. } catch (error) {
  17. throw error;
  18. }
  19. },
  20. // 获取单个资产
  21. getZichan: async (id: number) => {
  22. try {
  23. const response = await axios.get(`/zichan/${id}`);
  24. return response.data;
  25. } catch (error) {
  26. throw error;
  27. }
  28. },
  29. // 创建资产
  30. createZichan: async (data: Partial<ZichanInfo>) => {
  31. try {
  32. const response = await axios.post(`/zichan`, data);
  33. return response.data;
  34. } catch (error) {
  35. throw error;
  36. }
  37. },
  38. // 更新资产
  39. updateZichan: async (id: number, data: Partial<ZichanInfo>) => {
  40. try {
  41. const response = await axios.put(`/zichan/${id}`, data);
  42. return response.data;
  43. } catch (error) {
  44. throw error;
  45. }
  46. },
  47. // 删除资产
  48. deleteZichan: async (id: number) => {
  49. try {
  50. const response = await axios.delete(`/zichan/${id}`);
  51. return response.data;
  52. } catch (error) {
  53. throw error;
  54. }
  55. }
  56. };