feat(dashboard): 新增仪表盘监控类型定义和模拟数据
This commit is contained in:
parent
e1804a43e0
commit
269c0b60a8
116
src/views/dashboard/monitor/mockData.ts
Normal file
116
src/views/dashboard/monitor/mockData.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import type { DashboardData } from './types'
|
||||
|
||||
// 生成模拟仪表盘数据
|
||||
export function generateMockDashboardData(): DashboardData {
|
||||
return {
|
||||
// 用户统计数据
|
||||
userStats: {
|
||||
totalUsers: 1286,
|
||||
todayNewUsers: 23,
|
||||
activeUsers: 856,
|
||||
onlineUsers: 142,
|
||||
},
|
||||
|
||||
// 登录统计数据
|
||||
loginStats: {
|
||||
todayLogins: 468,
|
||||
totalLogins: 45672,
|
||||
loginTrend: generateLoginTrendData(),
|
||||
},
|
||||
|
||||
// 存储统计数据
|
||||
storageStats: {
|
||||
totalFiles: 8924,
|
||||
totalImages: 3420,
|
||||
totalSize: '2.3 GB',
|
||||
todayUploads: 67,
|
||||
storageUsage: 67.5,
|
||||
availableSpace: '1.2 GB',
|
||||
},
|
||||
|
||||
// 今日活跃数据
|
||||
dailyActivityStats: {
|
||||
todayVisits: 1247,
|
||||
todayOperations: 856,
|
||||
activeUsers: 142,
|
||||
newContent: 23,
|
||||
apiCalls: 3420,
|
||||
avgResponseTime: 235,
|
||||
},
|
||||
|
||||
// 系统状态
|
||||
systemStatus: {
|
||||
diskUsage: 67.5,
|
||||
memoryUsage: 43.2,
|
||||
cpuUsage: 28.7,
|
||||
systemHealth: 'good',
|
||||
uptime: '15天 8小时 23分钟',
|
||||
lastBackup: '2024-01-15 02:30:00',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// 生成登录趋势数据(最近7天)
|
||||
function generateLoginTrendData() {
|
||||
const trendData = []
|
||||
const today = new Date()
|
||||
|
||||
for (let i = 6; i >= 0; i--) {
|
||||
const date = new Date(today)
|
||||
date.setDate(date.getDate() - i)
|
||||
|
||||
const dateStr = date.toISOString().split('T')[0]
|
||||
const label = date.toLocaleDateString('zh-CN', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
|
||||
// 生成随机但合理的登录数量
|
||||
const baseCount = 300
|
||||
const randomVariation = Math.floor(Math.random() * 200) - 100
|
||||
const weekendMultiplier
|
||||
= date.getDay() === 0 || date.getDay() === 6 ? 0.6 : 1
|
||||
const count = Math.max(
|
||||
50,
|
||||
Math.floor((baseCount + randomVariation) * weekendMultiplier),
|
||||
)
|
||||
|
||||
trendData.push({
|
||||
date: dateStr,
|
||||
count,
|
||||
label,
|
||||
})
|
||||
}
|
||||
|
||||
return trendData
|
||||
}
|
||||
|
||||
// 生成随机颜色
|
||||
export function generateRandomColor(): string {
|
||||
const colors = [
|
||||
'#18A058',
|
||||
'#2080F0',
|
||||
'#F0A020',
|
||||
'#D03050',
|
||||
'#722ED1',
|
||||
'#13C2C2',
|
||||
'#52C41A',
|
||||
'#1890FF',
|
||||
'#FAAD14',
|
||||
'#F5222D',
|
||||
]
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 获取状态颜色
|
||||
export function getStatusColor(status: string): string {
|
||||
const colorMap: Record<string, string> = {
|
||||
success: 'var(--success-color)',
|
||||
failed: 'var(--error-color)',
|
||||
warning: 'var(--warning-color)',
|
||||
info: 'var(--info-color)',
|
||||
good: 'var(--success-color)',
|
||||
critical: 'var(--error-color)',
|
||||
}
|
||||
return colorMap[status] || 'var(--text-color-3)'
|
||||
}
|
||||
44
src/views/dashboard/monitor/types.ts
Normal file
44
src/views/dashboard/monitor/types.ts
Normal file
@ -0,0 +1,44 @@
|
||||
// 仪表盘数据类型定义
|
||||
|
||||
// 从API模块重新导出类型,保持一致性
|
||||
export type {
|
||||
DailyActivityStatsVo as DailyActivityStats,
|
||||
LoginStatsVo as LoginStats,
|
||||
LoginTrendItemVo,
|
||||
StorageStatsVo as StorageStats,
|
||||
UserStatsVo as UserStats,
|
||||
} from '@/service/api/dashboard'
|
||||
|
||||
// 完整的仪表盘数据结构(与后端API保持一致)
|
||||
export interface DashboardData {
|
||||
userStats: UserStats
|
||||
loginStats: LoginStats
|
||||
storageStats: StorageStats
|
||||
dailyActivityStats: DailyActivityStats
|
||||
}
|
||||
|
||||
// 图表数据点类型
|
||||
export interface ChartDataPoint {
|
||||
name: string
|
||||
value: number
|
||||
color?: string
|
||||
}
|
||||
|
||||
// 趋势数据类型
|
||||
export interface TrendData {
|
||||
label: string
|
||||
value: number
|
||||
date: string
|
||||
}
|
||||
|
||||
// 统计卡片属性类型
|
||||
export interface StatCardProps {
|
||||
title: string
|
||||
value: number | string
|
||||
subtitle: string
|
||||
extraInfo?: string
|
||||
trend?: string
|
||||
trendUp?: boolean
|
||||
icon: string
|
||||
color: string
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user