chart.ts 1.5 KB

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