theme.ts 951 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import axios from 'axios';
  2. import type {
  3. ThemeSettings
  4. } from '../../share/types.ts';
  5. const API_BASE_URL = '/api';
  6. // Theme API 定义
  7. export const ThemeAPI = {
  8. // 获取主题设置
  9. getThemeSettings: async (): Promise<ThemeSettings> => {
  10. try {
  11. const response = await axios.get(`${API_BASE_URL}/theme`);
  12. return response.data.data;
  13. } catch (error) {
  14. throw error;
  15. }
  16. },
  17. // 更新主题设置
  18. updateThemeSettings: async (themeData: Partial<ThemeSettings>): Promise<ThemeSettings> => {
  19. try {
  20. const response = await axios.put(`${API_BASE_URL}/theme`, themeData);
  21. return response.data.data;
  22. } catch (error) {
  23. throw error;
  24. }
  25. },
  26. // 重置主题设置
  27. resetThemeSettings: async (): Promise<ThemeSettings> => {
  28. try {
  29. const response = await axios.post(`${API_BASE_URL}/theme/reset`);
  30. return response.data.data;
  31. } catch (error) {
  32. throw error;
  33. }
  34. }
  35. };