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}}