Skip to content

Commit 0ca534a

Browse files
committed
fix: dashboard weekly statistics NaN undefined error
1 parent 175fcd2 commit 0ca534a

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,43 @@
77

88
NodePassDash是一个现代化的 NodePass 管理界面,基于 Go 后端 + React + Vite、HeroUI 和 TypeScript 构建。提供实时隧道监控、流量统计和端点管理功能。
99

10-
> **⚠️ 重大版本升级通知**
11-
> **version 3.x 是一个重大版本更新!** 核心架构全面重构,从 Next.js 迁移至 Vite,后端升级至 GORM + Gin 架构。
10+
> ## 📋 2.x 升级到 3.x 迁移指南
11+
> **version 3.x 是一个重大版本更新!** 核心架构全面重构,从 Next.js 打包更换为 Vite 打包,后端重构为 GORM + Gin 架构。
1212
>
13+
> ### 升级步骤
14+
>
15+
> 1. **导出主控数据**
16+
>
17+
> - 在 2.x 版本的主控列表中,使用导出功能保存所有主控配置数据
18+
>
19+
> 2. **更新 Docker 配置**
20+
>
21+
> - 从仓库获取最新的 `docker-compose.yml` 配置文件
22+
>
23+
> 3. **拉取最新镜像**
24+
>
25+
> ```bash
26+
> docker pull ghcr.io/nodepassproject/nodepassdash:latest
27+
> ```
28+
>
29+
> 4. **重启容器**
30+
>
31+
> ```bash
32+
> # 在容器所在的compose文件目录运行
33+
> docker compose down && docker compose up -d
34+
> ```
35+
>
36+
> 5. **重新导入数据**
37+
>
38+
> - 访问新版本界面,重新创建主控配置
39+
> - 导入之前导出的主控数据
40+
> - 验证所有功能正常工作
41+
>
42+
> ### ⚠️ 注意事项
1343
> ***此版本不向下兼容,升级前请务必备份/导出主控数据,建议全新创建主控避免旧数据的影响!***
44+
> - **数据库不兼容**: 3.x 版本使用全新的数据库表结构,无法直接迁移 2.x 数据
45+
> - **配置格式变更**: 主控配置格式有所调整,建议手动重新配置重要隧道
46+
> - **功能变化**: 部分功能界面和操作方式有所变化,建议查看新版本文档
1447
1548
## ✨ 主要特性
1649

web/src/components/ui/weekly-stats-chart.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ function WeeklyStatsChartComponent({
166166
/>
167167
<YAxis
168168
axisLine={false}
169+
domain={[0, 'dataMax']}
169170
style={{ fontSize: "var(--heroui-font-size-tiny)" }}
170-
tickFormatter={(value) => formatBytes(value)}
171+
tickFormatter={(value) => formatBytes(Math.max(0, value))}
171172
tickLine={false}
172173
/>
173174
<Tooltip
@@ -179,7 +180,7 @@ function WeeklyStatsChartComponent({
179180
</span>
180181
{payload?.map((p, index) => {
181182
const name = p.name;
182-
const value = p.value;
183+
const value = Math.max(0, Number(p.value) || 0);
183184
const category =
184185
categories.find((c) => c === name) ?? name;
185186

@@ -197,7 +198,7 @@ function WeeklyStatsChartComponent({
197198
<div className="text-default-700 flex w-full items-center justify-between gap-x-2 pr-1 text-xs">
198199
<span className="text-default-500">{category}</span>
199200
<span className="text-default-700 font-mono font-medium">
200-
{formatBytes(value as number)}
201+
{formatBytes(value)}
201202
</span>
202203
</div>
203204
</div>

web/src/pages/dashboard/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ export default function DashboardPage() {
443443
// 转换后端数据格式为图表组件需要的格式
444444
let chartData = result.data.map((item: any) => ({
445445
weekday: item.weekday,
446-
"TCP In": item.tcp_in,
447-
"TCP Out": item.tcp_out,
448-
"UDP In": item.udp_in,
449-
"UDP Out": item.udp_out,
446+
"TCP In": Math.max(0, Number(item.tcp_in) || 0),
447+
"TCP Out": Math.max(0, Number(item.tcp_out) || 0),
448+
"UDP In": Math.max(0, Number(item.udp_in) || 0),
449+
"UDP Out": Math.max(0, Number(item.udp_out) || 0),
450450
}));
451451

452452
// 如果后端没有返回数据或数据不足7天,生成默认的7天0值数据

0 commit comments

Comments
 (0)