chore: update frontend/src/services/statistics.ts
This commit is contained in:
@@ -1,25 +1,27 @@
|
|||||||
// Statistics API Service
|
// Statistics API Service
|
||||||
import { apiClient } from './apiClient';
|
import { apiClient } from './apiClient';
|
||||||
import type { DashboardSummary, MonthlyStats, TrendStat, MonthlyCompare } from '../types';
|
import type { DashboardSummary, MonthlyStats, TrendStat, MonthlyCompare } from '../types';
|
||||||
|
import { useUserStore } from '../stores/userStore';
|
||||||
const USER_ID = 6; // Mock user ID
|
|
||||||
|
|
||||||
export const statisticsApi = {
|
export const statisticsApi = {
|
||||||
// API: GET /api/dashboard/summary - 获取仪表盘汇总数据(余额、本月收入/支出、预算进度)
|
// API: GET /api/dashboard/summary - 获取仪表盘汇总数据(余额、本月收入/支出、预算进度)
|
||||||
async getDashboardSummary(): Promise<DashboardSummary> {
|
async getDashboardSummary(): Promise<DashboardSummary> {
|
||||||
const response = await apiClient.get<DashboardSummary>('/dashboard/summary', { userId: USER_ID });
|
const userId = useUserStore.getState().userId;
|
||||||
|
const response = await apiClient.get<DashboardSummary>('/dashboard/summary', { userId });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// API: GET /api/statistics/monthly - 获取月度分类统计数据(按支出分类聚合)
|
// API: GET /api/statistics/monthly - 获取月度分类统计数据(按支出分类聚合)
|
||||||
async getMonthlyStats(month: string): Promise<MonthlyStats> {
|
async getMonthlyStats(month: string): Promise<MonthlyStats> {
|
||||||
const response = await apiClient.get<MonthlyStats>('/statistics/monthly', { userId: USER_ID, month });
|
const userId = useUserStore.getState().userId;
|
||||||
|
const response = await apiClient.get<MonthlyStats>('/statistics/monthly', { userId, month });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
// API: GET /api/statistics/trend - 获取日期趋势统计(按天聚合收入/支出)
|
// API: GET /api/statistics/trend - 获取日期趋势统计(按天聚合收入/支出)
|
||||||
async getTrendStats(startDate?: string, endDate?: string): Promise<TrendStat[]> {
|
async getTrendStats(startDate?: string, endDate?: string): Promise<TrendStat[]> {
|
||||||
const params: Record<string, string | number> = { userId: USER_ID };
|
const userId = useUserStore.getState().userId;
|
||||||
|
const params: Record<string, string | number> = { userId };
|
||||||
if (startDate) params.startDate = startDate;
|
if (startDate) params.startDate = startDate;
|
||||||
if (endDate) params.endDate = endDate;
|
if (endDate) params.endDate = endDate;
|
||||||
const response = await apiClient.get<TrendStat[]>('/statistics/trend', params);
|
const response = await apiClient.get<TrendStat[]>('/statistics/trend', params);
|
||||||
@@ -28,7 +30,8 @@ export const statisticsApi = {
|
|||||||
|
|
||||||
// API: GET /api/statistics/compare - 获取本月与上月对比数据
|
// API: GET /api/statistics/compare - 获取本月与上月对比数据
|
||||||
async getMonthlyCompare(month: string): Promise<MonthlyCompare> {
|
async getMonthlyCompare(month: string): Promise<MonthlyCompare> {
|
||||||
const response = await apiClient.get<MonthlyCompare>('/statistics/compare', { userId: USER_ID, month });
|
const userId = useUserStore.getState().userId;
|
||||||
|
const response = await apiClient.get<MonthlyCompare>('/statistics/compare', { userId, month });
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user