feat(dashboard): 实现仪表盘数据服务
- 新增 DashboardController 提供后端API - 新增 dashboard.ts 前端服务 - 更新 ApiDataService 集成仪表盘数据 - 完成任务 TASK-401-404 (96%完成) Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { getDashboard } from '../dashboard'
|
||||
|
||||
const baseUrl = import.meta.env.VITE_MOSQUITO_API_BASE_URL ?? ''
|
||||
const apiKey = import.meta.env.VITE_MOSQUITO_API_KEY ?? ''
|
||||
const userToken = import.meta.env.VITE_MOSQUITO_USER_TOKEN ?? ''
|
||||
@@ -19,11 +21,22 @@ const requestJson = async (url: string) => {
|
||||
|
||||
export const apiDataService = {
|
||||
async getDashboard() {
|
||||
return {
|
||||
updatedAt: '刚刚',
|
||||
kpis: [],
|
||||
activities: [],
|
||||
alerts: []
|
||||
try {
|
||||
const data = await getDashboard()
|
||||
return {
|
||||
updatedAt: data.updatedAt,
|
||||
kpis: data.kpis,
|
||||
activities: data.activities,
|
||||
alerts: data.alerts
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch dashboard:', error)
|
||||
return {
|
||||
updatedAt: '刚刚',
|
||||
kpis: [],
|
||||
activities: [],
|
||||
alerts: []
|
||||
}
|
||||
}
|
||||
},
|
||||
async getActivities() {
|
||||
|
||||
111
frontend/admin/src/services/dashboard.ts
Normal file
111
frontend/admin/src/services/dashboard.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
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<T> {
|
||||
code: number
|
||||
data: T
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取仪表盘数据
|
||||
*/
|
||||
export async function getDashboard(): Promise<DashboardData> {
|
||||
const response = await dashboardApi.get<ApiResponse<DashboardData>>('/dashboard')
|
||||
return response.data.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取KPI数据
|
||||
*/
|
||||
export async function getKpis(): Promise<KpiData[]> {
|
||||
const response = await dashboardApi.get<ApiResponse<KpiData[]>>('/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<Todo[]> {
|
||||
const response = await dashboardApi.get<ApiResponse<Todo[]>>('/dashboard/todos')
|
||||
return response.data.data
|
||||
}
|
||||
|
||||
export default {
|
||||
getDashboard,
|
||||
getKpis,
|
||||
getActivitySummary,
|
||||
getTodos
|
||||
}
|
||||
Reference in New Issue
Block a user