diff --git a/frontend/src/services/statistics.ts b/frontend/src/services/statistics.ts new file mode 100644 index 0000000..c900a57 --- /dev/null +++ b/frontend/src/services/statistics.ts @@ -0,0 +1,37 @@ +// Statistics API Service +import { apiClient } from './apiClient'; +import type { DashboardSummary, MonthlyStats, TrendStat, MonthlyCompare } from '../types'; +import { useUserStore } from '../stores/userStore'; + +export const statisticsApi = { + // API: GET /api/dashboard/summary - 获取仪表盘汇总数据(余额、本月收入/支出、预算进度) + async getDashboardSummary(): Promise { + const userId = useUserStore.getState().userId; + const response = await apiClient.get('/dashboard/summary', { userId }); + return response.data; + }, + + // API: GET /api/statistics/monthly - 获取月度分类统计数据(按支出分类聚合) + async getMonthlyStats(month: string): Promise { + const userId = useUserStore.getState().userId; + const response = await apiClient.get('/statistics/monthly', { userId, month }); + return response.data; + }, + + // API: GET /api/statistics/trend - 获取日期趋势统计(按天聚合收入/支出) + async getTrendStats(startDate?: string, endDate?: string): Promise { + const userId = useUserStore.getState().userId; + const params: Record = { userId }; + if (startDate) params.startDate = startDate; + if (endDate) params.endDate = endDate; + const response = await apiClient.get('/statistics/trend', params); + return response.data; + }, + + // API: GET /api/statistics/compare - 获取本月与上月对比数据 + async getMonthlyCompare(month: string): Promise { + const userId = useUserStore.getState().userId; + const response = await apiClient.get('/statistics/compare', { userId, month }); + return response.data; + }, +};