chore: add frontend/src/services/statistics.ts
This commit is contained in:
@@ -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<DashboardSummary> {
|
||||
const userId = useUserStore.getState().userId;
|
||||
const response = await apiClient.get<DashboardSummary>('/dashboard/summary', { userId });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: GET /api/statistics/monthly - 获取月度分类统计数据(按支出分类聚合)
|
||||
async getMonthlyStats(month: string): Promise<MonthlyStats> {
|
||||
const userId = useUserStore.getState().userId;
|
||||
const response = await apiClient.get<MonthlyStats>('/statistics/monthly', { userId, month });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: GET /api/statistics/trend - 获取日期趋势统计(按天聚合收入/支出)
|
||||
async getTrendStats(startDate?: string, endDate?: string): Promise<TrendStat[]> {
|
||||
const userId = useUserStore.getState().userId;
|
||||
const params: Record<string, string | number> = { userId };
|
||||
if (startDate) params.startDate = startDate;
|
||||
if (endDate) params.endDate = endDate;
|
||||
const response = await apiClient.get<TrendStat[]>('/statistics/trend', params);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: GET /api/statistics/compare - 获取本月与上月对比数据
|
||||
async getMonthlyCompare(month: string): Promise<MonthlyCompare> {
|
||||
const userId = useUserStore.getState().userId;
|
||||
const response = await apiClient.get<MonthlyCompare>('/statistics/compare', { userId, month });
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user