2
0

chart.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import axios from 'axios';
  2. const API_BASE_URL = '/api';
  3. // 图表数据API接口类型
  4. interface ChartDataResponse<T> {
  5. message: string;
  6. data: T;
  7. }
  8. interface UserActivityData {
  9. date: string;
  10. count: number;
  11. }
  12. interface FileUploadsData {
  13. month: string;
  14. count: number;
  15. }
  16. interface FileTypesData {
  17. type: string;
  18. value: number;
  19. }
  20. interface DashboardOverviewData {
  21. userCount: number;
  22. fileCount: number;
  23. articleCount: number;
  24. todayLoginCount: number;
  25. }
  26. // 图表数据API
  27. export const ChartAPI = {
  28. // 获取用户活跃度数据
  29. getUserActivity: async (): Promise<ChartDataResponse<UserActivityData[]>> => {
  30. try {
  31. const response = await axios.get(`${API_BASE_URL}/charts/user-activity`);
  32. return response.data;
  33. } catch (error) {
  34. throw error;
  35. }
  36. },
  37. // 获取文件上传统计数据
  38. getFileUploads: async (): Promise<ChartDataResponse<FileUploadsData[]>> => {
  39. try {
  40. const response = await axios.get(`${API_BASE_URL}/charts/file-uploads`);
  41. return response.data;
  42. } catch (error) {
  43. throw error;
  44. }
  45. },
  46. // 获取文件类型分布数据
  47. getFileTypes: async (): Promise<ChartDataResponse<FileTypesData[]>> => {
  48. try {
  49. const response = await axios.get(`${API_BASE_URL}/charts/file-types`);
  50. return response.data;
  51. } catch (error) {
  52. throw error;
  53. }
  54. },
  55. // 获取仪表盘概览数据
  56. getDashboardOverview: async (): Promise<ChartDataResponse<DashboardOverviewData>> => {
  57. try {
  58. const response = await axios.get(`${API_BASE_URL}/charts/dashboard-overview`);
  59. return response.data;
  60. } catch (error) {
  61. throw error;
  62. }
  63. }
  64. };