system.ts 1.3 KB

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