import axios from 'axios' const baseURL = import.meta.env.VITE_API_BASE_URL ?? '/api' const dashboardApi = axios.create({ baseURL, headers: { 'Content-Type': 'application/json' } }) // 请求拦截器 - 添加认证头 dashboardApi.interceptors.request.use( (config) => { const apiKey = localStorage.getItem('apiKey') if (apiKey) { config.headers['X-API-Key'] = apiKey } const token = localStorage.getItem('token') if (token) { config.headers['Authorization'] = `Bearer ${token}` } return config }, (error) => Promise.reject(error) ) export interface KpiData { label: string value: number status: string hint: string } export interface ActivitySummary { id: number name: string startTime?: string endTime?: string participants: number shares: number conversions: number } export interface Alert { title: string detail: string type: string level: string } export interface Todo { id: string title: string description: string type: string link: string priority: string } export interface DashboardData { updatedAt: string kpis: KpiData[] activities: ActivitySummary[] alerts: Alert[] todos: Todo[] } interface ApiResponse { code: number data: T } /** * 获取仪表盘数据 */ export async function getDashboard(): Promise { const response = await dashboardApi.get>('/dashboard') return response.data.data } /** * 获取KPI数据 */ export async function getKpis(): Promise { const response = await dashboardApi.get>('/dashboard/kpis') return response.data.data } /** * 获取活动统计 */ export async function getActivitySummary() { const response = await dashboardApi.get('/dashboard/activities') return response.data } /** * 获取待办事项 */ export async function getTodos(): Promise { const response = await dashboardApi.get>('/dashboard/todos') return response.data.data } export default { getDashboard, getKpis, getActivitySummary, getTodos }