2
0

Dashboard.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import React from 'react';
  2. import { useNavigate } from 'react-router';
  3. import { Users, Bell, Eye, TrendingUp, TrendingDown, Activity } from 'lucide-react';
  4. import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/client/components/ui/card';
  5. import { Badge } from '@/client/components/ui/badge';
  6. import { Progress } from '@/client/components/ui/progress';
  7. // 仪表盘页面
  8. export const DashboardPage = () => {
  9. const navigate = useNavigate();
  10. const stats = [
  11. {
  12. title: '活跃用户',
  13. value: '112,893',
  14. icon: Users,
  15. color: 'text-blue-500',
  16. bgColor: 'bg-blue-50',
  17. trend: 12.5,
  18. trendDirection: 'up',
  19. description: '较昨日增长 12.5%',
  20. },
  21. {
  22. title: '系统消息',
  23. value: '93',
  24. icon: Bell,
  25. color: 'text-yellow-500',
  26. bgColor: 'bg-yellow-50',
  27. trend: 0,
  28. trendDirection: 'neutral',
  29. description: '其中 5 条未读',
  30. },
  31. {
  32. title: '在线用户',
  33. value: '1,128',
  34. icon: Eye,
  35. color: 'text-purple-500',
  36. bgColor: 'bg-purple-50',
  37. trend: 32.1,
  38. trendDirection: 'up',
  39. description: '当前在线率 32.1%',
  40. },
  41. ];
  42. const recentActivities = [
  43. {
  44. id: 1,
  45. user: '张三',
  46. action: '登录系统',
  47. time: '2分钟前',
  48. status: 'success',
  49. },
  50. {
  51. id: 2,
  52. user: '李四',
  53. action: '创建了新用户',
  54. time: '5分钟前',
  55. status: 'info',
  56. },
  57. {
  58. id: 3,
  59. user: '王五',
  60. action: '删除了用户',
  61. time: '10分钟前',
  62. status: 'warning',
  63. },
  64. {
  65. id: 4,
  66. user: '赵六',
  67. action: '修改了配置',
  68. time: '15分钟前',
  69. status: 'info',
  70. },
  71. ];
  72. const systemMetrics = [
  73. {
  74. name: 'CPU使用率',
  75. value: 65,
  76. color: 'bg-green-500',
  77. },
  78. {
  79. name: '内存使用率',
  80. value: 78,
  81. color: 'bg-blue-500',
  82. },
  83. {
  84. name: '磁盘使用率',
  85. value: 45,
  86. color: 'bg-purple-500',
  87. },
  88. {
  89. name: '网络使用率',
  90. value: 32,
  91. color: 'bg-orange-500',
  92. },
  93. ];
  94. const handleQuickActionClick = (action: string) => {
  95. switch (action) {
  96. case 'users':
  97. navigate('/admin/users');
  98. break;
  99. case 'settings':
  100. navigate('/admin/settings');
  101. break;
  102. case 'backup':
  103. navigate('/admin/backup');
  104. break;
  105. case 'logs':
  106. navigate('/admin/logs');
  107. break;
  108. default:
  109. break;
  110. }
  111. };
  112. return (
  113. <div className="space-y-6">
  114. <div>
  115. <h1 className="text-3xl font-bold tracking-tight">仪表盘</h1>
  116. <p className="text-muted-foreground">
  117. 欢迎回来!这里是系统概览和关键指标。
  118. </p>
  119. </div>
  120. {/* 统计卡片 */}
  121. <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
  122. {stats.map((stat, index) => {
  123. const Icon = stat.icon;
  124. return (
  125. <Card key={index} className="transition-all duration-300 hover:shadow-lg">
  126. <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
  127. <CardTitle className="text-sm font-medium">
  128. {stat.title}
  129. </CardTitle>
  130. <div className={`p-2 rounded-full ${stat.bgColor}`}>
  131. <Icon className={`h-4 w-4 ${stat.color}`} />
  132. </div>
  133. </CardHeader>
  134. <CardContent>
  135. <div className="text-2xl font-bold">{stat.value}</div>
  136. <div className="flex items-center space-x-2">
  137. {stat.trendDirection === 'up' && (
  138. <TrendingUp className="h-4 w-4 text-green-500" />
  139. )}
  140. {stat.trendDirection === 'down' && (
  141. <TrendingDown className="h-4 w-4 text-red-500" />
  142. )}
  143. <p className="text-xs text-muted-foreground">{stat.description}</p>
  144. </div>
  145. </CardContent>
  146. </Card>
  147. );
  148. })}
  149. </div>
  150. <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
  151. {/* 系统性能 */}
  152. <Card className="lg:col-span-4">
  153. <CardHeader>
  154. <CardTitle>系统性能</CardTitle>
  155. <CardDescription>
  156. 当前系统各项资源的使用情况
  157. </CardDescription>
  158. </CardHeader>
  159. <CardContent>
  160. <div className="space-y-4">
  161. {systemMetrics.map((metric, index) => (
  162. <div key={index} className="space-y-2">
  163. <div className="flex justify-between text-sm">
  164. <span className="font-medium">{metric.name}</span>
  165. <span className="text-muted-foreground">{metric.value}%</span>
  166. </div>
  167. <Progress value={metric.value} className="h-2" />
  168. </div>
  169. ))}
  170. </div>
  171. </CardContent>
  172. </Card>
  173. {/* 最近活动 */}
  174. <Card className="lg:col-span-3">
  175. <CardHeader>
  176. <CardTitle>最近活动</CardTitle>
  177. <CardDescription>
  178. 系统最新操作记录
  179. </CardDescription>
  180. </CardHeader>
  181. <CardContent>
  182. <div className="space-y-4">
  183. {recentActivities.map((activity) => (
  184. <div key={activity.id} className="flex items-center space-x-4">
  185. <div className="flex-shrink-0">
  186. <div className={`p-2 rounded-full ${
  187. activity.status === 'success' ? 'bg-green-100' :
  188. activity.status === 'warning' ? 'bg-yellow-100' : 'bg-blue-100'
  189. }`}>
  190. <Activity className={`h-4 w-4 ${
  191. activity.status === 'success' ? 'text-green-600' :
  192. activity.status === 'warning' ? 'text-yellow-600' : 'text-blue-600'
  193. }`} />
  194. </div>
  195. </div>
  196. <div className="flex-1 space-y-1">
  197. <p className="text-sm font-medium">
  198. {activity.user} {activity.action}
  199. </p>
  200. <p className="text-sm text-muted-foreground">
  201. {activity.time}
  202. </p>
  203. </div>
  204. </div>
  205. ))}
  206. </div>
  207. </CardContent>
  208. </Card>
  209. </div>
  210. {/* 快捷操作 */}
  211. <Card>
  212. <CardHeader>
  213. <CardTitle>快捷操作</CardTitle>
  214. <CardDescription>
  215. 常用的管理功能
  216. </CardDescription>
  217. </CardHeader>
  218. <CardContent>
  219. <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
  220. <Card
  221. className="hover:shadow-md transition-all cursor-pointer"
  222. onClick={() => handleQuickActionClick('users')}
  223. >
  224. <CardHeader className="pb-3">
  225. <CardTitle className="text-base">用户管理</CardTitle>
  226. <CardDescription>查看和管理所有用户</CardDescription>
  227. </CardHeader>
  228. </Card>
  229. <Card
  230. className="hover:shadow-md transition-all cursor-pointer"
  231. onClick={() => handleQuickActionClick('settings')}
  232. >
  233. <CardHeader className="pb-3">
  234. <CardTitle className="text-base">系统设置</CardTitle>
  235. <CardDescription>配置系统参数</CardDescription>
  236. </CardHeader>
  237. </Card>
  238. <Card
  239. className="hover:shadow-md transition-all cursor-pointer"
  240. onClick={() => handleQuickActionClick('backup')}
  241. >
  242. <CardHeader className="pb-3">
  243. <CardTitle className="text-base">数据备份</CardTitle>
  244. <CardDescription>执行数据备份操作</CardDescription>
  245. </CardHeader>
  246. </Card>
  247. <Card
  248. className="hover:shadow-md transition-all cursor-pointer"
  249. onClick={() => handleQuickActionClick('logs')}
  250. >
  251. <CardHeader className="pb-3">
  252. <CardTitle className="text-base">日志查看</CardTitle>
  253. <CardDescription>查看系统日志</CardDescription>
  254. </CardHeader>
  255. </Card>
  256. </div>
  257. </CardContent>
  258. </Card>
  259. </div>
  260. );
  261. };