From 1c2cc5dcab14a096020013a1dae9998faff9a549 Mon Sep 17 00:00:00 2001 From: naiba Date: Sat, 16 Jan 2021 11:42:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20improve:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=20close=20#55=20close=20#56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/controller/common_page.go | 19 +++++-------------- pkg/mygin/mygin.go | 9 +++++++++ resource/template/common/menu.html | 18 ++++++++++++++---- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index 9e5094e..3954204 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -67,29 +67,20 @@ func (p *commonPage) service(c *gin.Context) { } } - u, ok := c.Get(model.CtxKeyAuthorizedUser) - data := mygin.CommonEnvironment(c, gin.H{ + c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/service", mygin.CommonEnvironment(c, gin.H{ "Title": "服务状态", "Services": msm, - }) - if ok { - data["Admin"] = u - } - c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/service", data) + })) } func (cp *commonPage) home(c *gin.Context) { dao.ServerLock.RLock() defer dao.ServerLock.RUnlock() - data := gin.H{ + + c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/home", mygin.CommonEnvironment(c, gin.H{ "Servers": dao.SortedServerList, "CustomCode": dao.Conf.Site.CustomCode, - } - u, ok := c.Get(model.CtxKeyAuthorizedUser) - if ok { - data["Admin"] = u - } - c.HTML(http.StatusOK, "theme-"+dao.Conf.Site.Theme+"/home", mygin.CommonEnvironment(c, data)) + })) } var upgrader = websocket.Upgrader{} diff --git a/pkg/mygin/mygin.go b/pkg/mygin/mygin.go index c2e984d..7af4cca 100644 --- a/pkg/mygin/mygin.go +++ b/pkg/mygin/mygin.go @@ -10,9 +10,18 @@ import ( "github.com/naiba/nezha/service/dao" ) +var adminPage = map[string]bool{ + "/server": true, + "/monitor": true, + "/setting": true, + "/notification": true, +} + func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H { data["MatchedPath"] = c.MustGet("MatchedPath") data["Version"] = dao.Version + // 是否是管理页面 + data["IsAdminPage"] = adminPage[data["MatchedPath"].(string)] // 站点标题 if t, has := data["Title"]; !has { data["Title"] = dao.Conf.Site.Brand diff --git a/resource/template/common/menu.html b/resource/template/common/menu.html index 3cc678b..635f348 100644 --- a/resource/template/common/menu.html +++ b/resource/template/common/menu.html @@ -4,13 +4,14 @@
- 首页 - 服务状态 - {{if .Admin}} + {{if .IsAdminPage}} 服务器 - 监控 + 服务监控 通知 设置 + {{else}} + 首页 + 服务状态 {{end}}