feat(api): 新增仪表盘监控API服务层
This commit is contained in:
parent
e7eb349272
commit
e1804a43e0
84
src/service/api/dashboard/index.ts
Normal file
84
src/service/api/dashboard/index.ts
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import { request } from '../../http'
|
||||||
|
import type {
|
||||||
|
DailyActivityStatsVo,
|
||||||
|
DashboardQueryBo,
|
||||||
|
DashboardStatisticsVo,
|
||||||
|
LoginStatsVo,
|
||||||
|
LoginTrendVo,
|
||||||
|
StorageStatsVo,
|
||||||
|
UserStatsVo,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
|
// 重新导出类型供外部使用
|
||||||
|
export type {
|
||||||
|
DailyActivityStatsVo,
|
||||||
|
DashboardQueryBo,
|
||||||
|
DashboardStatisticsVo,
|
||||||
|
LoginStatsVo,
|
||||||
|
LoginTrendItemVo,
|
||||||
|
LoginTrendVo,
|
||||||
|
StorageStatsVo,
|
||||||
|
UserStatsVo,
|
||||||
|
} from './types'
|
||||||
|
|
||||||
|
// 仪表盘相关API
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取仪表盘统计数据
|
||||||
|
*/
|
||||||
|
export function getDashboardStatistics() {
|
||||||
|
return request.Get<Service.ResponseResult<DashboardStatisticsVo>>('/coder/dashboard/getStatistics')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录趋势数据
|
||||||
|
* @param days 查询天数,默认7天
|
||||||
|
*/
|
||||||
|
export function getLoginTrend(days: number = 7) {
|
||||||
|
return request.Get<Service.ResponseResult<LoginTrendVo>>('/coder/dashboard/getLoginTrend', {
|
||||||
|
params: { days },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取完整仪表盘数据
|
||||||
|
* @param params 查询参数
|
||||||
|
*/
|
||||||
|
export function getAllDashboardData(params: DashboardQueryBo = {}) {
|
||||||
|
const { includeTrend = true, trendDays = 7 } = params
|
||||||
|
return request.Get<Service.ResponseResult<DashboardStatisticsVo>>('/coder/dashboard/getAllData', {
|
||||||
|
params: { includeTrend, trendDays },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户统计数据
|
||||||
|
*/
|
||||||
|
export function getUserStats() {
|
||||||
|
return request.Get<Service.ResponseResult<UserStatsVo>>('/coder/dashboard/getUserStats')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录统计数据
|
||||||
|
* @param params 查询参数
|
||||||
|
*/
|
||||||
|
export function getLoginStats(params: DashboardQueryBo = {}) {
|
||||||
|
const { includeTrend = false, trendDays = 7 } = params
|
||||||
|
return request.Get<Service.ResponseResult<LoginStatsVo>>('/coder/dashboard/getLoginStats', {
|
||||||
|
params: { includeTrend, trendDays },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取存储统计数据
|
||||||
|
*/
|
||||||
|
export function getStorageStats() {
|
||||||
|
return request.Get<Service.ResponseResult<StorageStatsVo>>('/coder/dashboard/getStorageStats')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取今日活跃统计数据
|
||||||
|
*/
|
||||||
|
export function getDailyActivityStats() {
|
||||||
|
return request.Get<Service.ResponseResult<DailyActivityStatsVo>>('/coder/dashboard/getDailyActivityStats')
|
||||||
|
}
|
||||||
91
src/service/api/dashboard/types.ts
Normal file
91
src/service/api/dashboard/types.ts
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// 仪表盘API类型定义
|
||||||
|
|
||||||
|
// 用户统计数据
|
||||||
|
export interface UserStatsVo {
|
||||||
|
/** 总用户数 */
|
||||||
|
totalUsers: number
|
||||||
|
/** 今日新增用户数 */
|
||||||
|
todayNewUsers: number
|
||||||
|
/** 活跃用户数 */
|
||||||
|
activeUsers: number
|
||||||
|
/** 当前在线用户数 */
|
||||||
|
onlineUsers: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录趋势项
|
||||||
|
export interface LoginTrendItemVo {
|
||||||
|
/** 日期(YYYY-MM-DD格式) */
|
||||||
|
date: string
|
||||||
|
/** 当日登录次数 */
|
||||||
|
count: number
|
||||||
|
/** 显示标签(用于图表展示) */
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录统计数据
|
||||||
|
export interface LoginStatsVo {
|
||||||
|
/** 今日登录次数 */
|
||||||
|
todayLogins: number
|
||||||
|
/** 累计登录次数 */
|
||||||
|
totalLogins: number
|
||||||
|
/** 登录趋势数据 */
|
||||||
|
loginTrend?: LoginTrendItemVo[]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存储统计数据
|
||||||
|
export interface StorageStatsVo {
|
||||||
|
/** 总文件数 */
|
||||||
|
totalFiles: number
|
||||||
|
/** 总图片数 */
|
||||||
|
totalImages: number
|
||||||
|
/** 总存储大小(格式化) */
|
||||||
|
totalSize: string
|
||||||
|
/** 今日上传文件数 */
|
||||||
|
todayUploads: number
|
||||||
|
/** 存储使用率(百分比) */
|
||||||
|
storageUsage: number
|
||||||
|
/** 可用空间(格式化) */
|
||||||
|
availableSpace: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 今日活跃统计数据
|
||||||
|
export interface DailyActivityStatsVo {
|
||||||
|
/** 今日访问量 */
|
||||||
|
todayVisits: number
|
||||||
|
/** 今日操作数 */
|
||||||
|
todayOperations: number
|
||||||
|
/** 活跃用户数 */
|
||||||
|
activeUsers: number
|
||||||
|
/** 新增内容数 */
|
||||||
|
newContent: number
|
||||||
|
/** API调用次数 */
|
||||||
|
apiCalls: number
|
||||||
|
/** 平均响应时间(毫秒) */
|
||||||
|
avgResponseTime: number
|
||||||
|
}
|
||||||
|
|
||||||
|
// 仪表盘统计数据响应对象
|
||||||
|
export interface DashboardStatisticsVo {
|
||||||
|
/** 用户统计数据 */
|
||||||
|
userStats?: UserStatsVo
|
||||||
|
/** 登录统计数据 */
|
||||||
|
loginStats?: LoginStatsVo
|
||||||
|
/** 存储统计数据 */
|
||||||
|
storageStats?: StorageStatsVo
|
||||||
|
/** 今日活跃统计数据 */
|
||||||
|
dailyActivityStats?: DailyActivityStatsVo
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录趋势数据响应对象
|
||||||
|
export interface LoginTrendVo {
|
||||||
|
/** 登录趋势数据列表 */
|
||||||
|
loginTrend: LoginTrendItemVo[]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询参数类型
|
||||||
|
export interface DashboardQueryBo {
|
||||||
|
/** 是否包含趋势数据 */
|
||||||
|
includeTrend?: boolean
|
||||||
|
/** 趋势数据天数 */
|
||||||
|
trendDays?: number
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user