Skip to content

Commit 5f0afb5

Browse files
CopilotSilianZ
andcommitted
Improve dashboard with refresh button, better polling, error handling and updated README
Co-authored-by: SilianZ <113701655+SilianZ@users.noreply.github.com>
1 parent 5fbdaaa commit 5f0afb5

3 files changed

Lines changed: 110 additions & 6 deletions

File tree

dashboard/README.md

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,73 @@
1-
# Vue 3 + TypeScript + Vite
1+
# Python-OpenBMCLAPI Dashboard
22

3-
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
3+
基于 Vue 3 + TypeScript + Vite 构建的 Python-OpenBMCLAPI 仪表盘。
44

5-
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
5+
## 特性
6+
7+
- 🎨 使用 PrimeVue 组件库实现现代化 UI
8+
- 📊 实时数据展示(每 5 秒自动刷新)
9+
- 📱 响应式设计,支持移动设备
10+
- 🌙 深色模式支持
11+
- 📈 多维度统计图表
12+
- 当日/当月/当年请求统计
13+
- 用户分布分析
14+
- ⚡ 性能监控
15+
- CPU 使用率
16+
- 内存使用情况
17+
- 连接数
18+
- 运行时间
19+
20+
## 技术栈
21+
22+
- [Vue 3](https://vuejs.org/) - 渐进式 JavaScript 框架
23+
- [TypeScript](https://www.typescriptlang.org/) - JavaScript 的超集
24+
- [Vite](https://vitejs.dev/) - 新一代前端构建工具
25+
- [PrimeVue](https://primevue.org/) - Vue UI 组件库
26+
- [TailwindCSS](https://tailwindcss.com/) - 实用优先的 CSS 框架
27+
- [Chart.js](https://www.chartjs.org/) - 图表库
28+
- [Vue Router](https://router.vuejs.org/) - Vue.js 官方路由
29+
30+
## 开发
31+
32+
```bash
33+
# 安装依赖
34+
npm install
35+
36+
# 启动开发服务器
37+
npm run dev
38+
39+
# 构建生产版本
40+
npm run build
41+
42+
# 预览生产版本
43+
npm run preview
44+
45+
# 格式化代码
46+
npm run format
47+
```
48+
49+
## 项目结构
50+
51+
```
52+
dashboard/
53+
├── src/
54+
│ ├── api/ # API 接口定义
55+
│ ├── component/ # 可复用组件
56+
│ ├── router/ # 路由配置
57+
│ ├── utils/ # 工具函数
58+
│ └── views/ # 页面视图
59+
├── public/ # 静态资源
60+
└── index.html # 入口 HTML
61+
```
62+
63+
## IDE 支持
64+
65+
推荐使用 [VSCode](https://code.visualstudio.com/) 配合以下插件:
66+
- [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (之前称为 Volar)
67+
- [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin)
68+
69+
## 类型支持
70+
71+
使用 Vue 3 `<script setup>` SFC,了解更多请参考 [script setup 文档](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup)
72+
73+
更多关于项目设置和 IDE 支持的信息,请参考 [Vue 文档 TypeScript 指南](https://vuejs.org/guide/typescript/overview.html#project-setup)

dashboard/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const items = ref([
1616
{
1717
label: 'GitHub',
1818
icon: 'pi pi-github',
19-
url: 'https://github.com/SilianZ/one-openbmclapi-dashboard'
19+
url: 'https://github.com/TTB-Network/python-openbmclapi-v2'
2020
}
2121
])
2222

dashboard/src/views/HomeView.vue

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { fetchStat } from '../api'
77
import { ref } from 'vue'
88
import { watch } from 'vue'
99
10-
const { data } = useRequest((): Promise<StatsRes> => fetchStat(), { pollingInterval: 100000 })
10+
const { data, refresh, loading, error } = useRequest((): Promise<StatsRes> => fetchStat(), {
11+
pollingInterval: 5000, // Poll every 5 seconds for real-time updates
12+
refreshOnWindowFocus: true // Refresh when user returns to tab
13+
})
1114
1215
const stats = ref<StatsRes | null>(null)
1316
@@ -24,7 +27,22 @@ watch(
2427
</script>
2528

2629
<template>
27-
<h1>主页</h1>
30+
<div class="flex justify-between items-center mb-4">
31+
<h1>主页</h1>
32+
<button
33+
@click="refresh"
34+
:disabled="loading"
35+
class="refresh-btn px-4 py-2 rounded-lg transition-colors"
36+
:class="loading ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-100 dark:hover:bg-gray-800'"
37+
>
38+
<i class="pi pi-refresh" :class="loading ? 'pi-spin' : ''"></i>
39+
刷新
40+
</button>
41+
</div>
42+
<div v-if="error" class="error-message p-4 mb-4 rounded-lg bg-red-100 dark:bg-red-900 text-red-800 dark:text-red-200">
43+
<i class="pi pi-exclamation-triangle mr-2"></i>
44+
加载数据时出错,请稍后重试
45+
</div>
2846
<StatsComponent :data="stats" />
2947
<ChartsComponent :data="stats" />
3048
</template>
@@ -41,9 +59,27 @@ h1 {
4159
unicode-bidi: isolate;
4260
}
4361
62+
.refresh-btn {
63+
border: 1px solid var(--p-content-border-color);
64+
background: var(--p-content-background);
65+
cursor: pointer;
66+
display: flex;
67+
align-items: center;
68+
gap: 0.5rem;
69+
}
70+
71+
.error-message {
72+
display: flex;
73+
align-items: center;
74+
}
75+
4476
@media screen and (max-width: 720px) {
4577
h1 {
4678
font-size: 30px;
4779
}
80+
.refresh-btn {
81+
font-size: 14px;
82+
padding: 0.5rem 1rem;
83+
}
4884
}
4985
</style>

0 commit comments

Comments
 (0)