sys.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import axios from 'axios';
  2. import type {
  3. SystemSetting, SystemSettingGroupData,
  4. } from '../../share/types.ts';
  5. const API_BASE_URL = '/api';
  6. export const SystemAPI = {
  7. // 获取所有系统设置
  8. getSettings: async (): Promise<SystemSettingGroupData[]> => {
  9. try {
  10. const response = await axios.get(`${API_BASE_URL}/settings`);
  11. return response.data.data;
  12. } catch (error) {
  13. throw error;
  14. }
  15. },
  16. // 获取指定分组的系统设置
  17. getSettingsByGroup: async (group: string): Promise<SystemSetting[]> => {
  18. try {
  19. const response = await axios.get(`${API_BASE_URL}/settings/group/${group}`);
  20. return response.data.data;
  21. } catch (error) {
  22. throw error;
  23. }
  24. },
  25. // 更新系统设置
  26. updateSettings: async (settings: Partial<SystemSetting>[]): Promise<SystemSetting[]> => {
  27. try {
  28. const response = await axios.put(`${API_BASE_URL}/settings`, settings);
  29. return response.data.data;
  30. } catch (error) {
  31. throw error;
  32. }
  33. },
  34. // 重置系统设置
  35. resetSettings: async (): Promise<SystemSetting[]> => {
  36. try {
  37. const response = await axios.post(`${API_BASE_URL}/settings/reset`);
  38. return response.data.data;
  39. } catch (error) {
  40. throw error;
  41. }
  42. }
  43. };