86 lines
2.0 KiB
TypeScript
86 lines
2.0 KiB
TypeScript
/**
|
|
* 仪表板服务
|
|
* 负责仪表板数据的API调用
|
|
*/
|
|
|
|
import apiClient from '@/infrastructure/api/client';
|
|
import { API_ENDPOINTS } from '@/infrastructure/api/endpoints';
|
|
import type {
|
|
ApiResponse,
|
|
DashboardOverview,
|
|
DashboardTrendData,
|
|
DashboardPeriod,
|
|
RegionDistributionItem,
|
|
DashboardActivity,
|
|
DashboardStatItem,
|
|
} from '@/types';
|
|
|
|
/** 仪表板概览响应 */
|
|
interface DashboardOverviewResponse {
|
|
stats: DashboardStatItem[];
|
|
overview: DashboardOverview;
|
|
}
|
|
|
|
/** 仪表板趋势响应 */
|
|
interface DashboardTrendResponse {
|
|
trend: DashboardTrendData;
|
|
}
|
|
|
|
/** 仪表板区域分布响应 */
|
|
interface DashboardRegionResponse {
|
|
regions: RegionDistributionItem[];
|
|
}
|
|
|
|
/** 仪表板活动响应 */
|
|
interface DashboardActivitiesResponse {
|
|
activities: DashboardActivity[];
|
|
}
|
|
|
|
/**
|
|
* 仪表板服务
|
|
*/
|
|
export const dashboardService = {
|
|
/**
|
|
* 获取仪表板概览数据(统计卡片)
|
|
*/
|
|
async getOverview(): Promise<ApiResponse<DashboardOverviewResponse>> {
|
|
return apiClient.get(API_ENDPOINTS.DASHBOARD.OVERVIEW);
|
|
},
|
|
|
|
/**
|
|
* 获取仪表板统计卡片数据
|
|
*/
|
|
async getStats(): Promise<ApiResponse<{ stats: DashboardStatItem[] }>> {
|
|
return apiClient.get(API_ENDPOINTS.DASHBOARD.STATS);
|
|
},
|
|
|
|
/**
|
|
* 获取趋势图表数据
|
|
* @param period 时间周期 (7d | 30d | 90d)
|
|
*/
|
|
async getTrendData(period: DashboardPeriod = '7d'): Promise<ApiResponse<DashboardTrendResponse>> {
|
|
return apiClient.get(API_ENDPOINTS.DASHBOARD.CHARTS, {
|
|
params: { period },
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 获取区域分布数据
|
|
*/
|
|
async getRegionDistribution(): Promise<ApiResponse<DashboardRegionResponse>> {
|
|
return apiClient.get(API_ENDPOINTS.DASHBOARD.REGION);
|
|
},
|
|
|
|
/**
|
|
* 获取最近活动列表
|
|
* @param limit 返回数量限制
|
|
*/
|
|
async getRecentActivities(limit = 5): Promise<ApiResponse<DashboardActivitiesResponse>> {
|
|
return apiClient.get(API_ENDPOINTS.DASHBOARD.ACTIVITIES, {
|
|
params: { limit },
|
|
});
|
|
},
|
|
};
|
|
|
|
export default dashboardService;
|