From 433277df2edb2b7f7996cc20c48aa5c6ce7f8b2d Mon Sep 17 00:00:00 2001 From: liuyanxi975 Date: Tue, 31 May 2022 13:18:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B5=81=E9=87=8F=E5=89=A9=E4=BD=99?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=A2=9E=E5=8A=A0=E8=AF=A6=E7=BB=86=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加流量剩余显示的详细剩余流量 改进CSS,优化显示效果 --- cmd/dashboard/controller/controller.go | 23 +++++++++++++++++++- resource/template/theme-default/service.html | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index f655620..cb7f4fa 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -148,13 +148,34 @@ var funcMap = template.FuncMap{ "add": func(a, b int) int { return a + b }, - "Transleft": func(a, b float64) (n float64) { + "TransLeftPercent": func(a, b float64) (n float64) { n, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (100-(a/b)*100)), 64) if n < 0 { n = 0 } return }, + "TransLeft": func(a, b uint64) string { + if a < b { + return "0KB" + } + return bytefmt.ByteSize(a - b) + }, + "TransClassName": func(a float64) string { + if a == 0 { + return "offline" + } + if a > 50 { + return "fine" + } + if a > 20 { + return "warning" + } + if a > 0 { + return "error" + } + return "offline" + }, "UintToFloat": func(a uint64) (n float64) { n, _ = strconv.ParseFloat((strconv.FormatUint(a, 10)), 64) return diff --git a/resource/template/theme-default/service.html b/resource/template/theme-default/service.html index b7d03ce..c79ec61 100644 --- a/resource/template/theme-default/service.html +++ b/resource/template/theme-default/service.html @@ -59,6 +59,7 @@ {{range $id, $stats := .CycleTransferStats}} {{range $innerId, $transfer := $stats.Transfer}} + {{$TransLeftPercent := TransLeftPercent (UintToFloat $transfer) (UintToFloat $stats.Max)}} {{$id}} {{$stats.Name}} @@ -69,7 +70,7 @@ {{$stats.Min|bf}} {{(index $stats.NextUpdate $innerId)|sft}} {{$transfer|bf}} -
{{Transleft (UintToFloat $transfer) (UintToFloat $stats.Max)}} %
+
{{TransLeft $stats.Max $transfer}} / {{$TransLeftPercent}} %
{{end}} {{end}} From cdc44ede31e7b46d17b4f8aa550be16e36342c1b Mon Sep 17 00:00:00 2001 From: liuyanxi975 Date: Tue, 31 May 2022 15:12:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/controller/controller.go | 2 +- resource/template/theme-default/service.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index cb7f4fa..d03268c 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -157,7 +157,7 @@ var funcMap = template.FuncMap{ }, "TransLeft": func(a, b uint64) string { if a < b { - return "0KB" + return "0B" } return bytefmt.ByteSize(a - b) }, diff --git a/resource/template/theme-default/service.html b/resource/template/theme-default/service.html index c79ec61..53ddb74 100644 --- a/resource/template/theme-default/service.html +++ b/resource/template/theme-default/service.html @@ -70,7 +70,7 @@ {{$stats.Min|bf}} {{(index $stats.NextUpdate $innerId)|sft}} {{$transfer|bf}} -
{{TransLeft $stats.Max $transfer}} / {{$TransLeftPercent}} %
+
{{TransLeft $stats.Max $transfer}} / {{$TransLeftPercent}} %
{{end}} {{end}}