feat: 管理后台自定义代码

This commit is contained in:
naiba 2024-08-14 00:24:17 +08:00
parent da8fb57268
commit daab64d232
14 changed files with 43 additions and 20 deletions

View File

@ -99,7 +99,6 @@ func (p *commonPage) service(c *gin.Context) {
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServicesStatus"}), "Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "ServicesStatus"}),
"Services": res.([]interface{})[0], "Services": res.([]interface{})[0],
"CycleTransferStats": res.([]interface{})[1], "CycleTransferStats": res.([]interface{})[1],
"CustomCode": singleton.Conf.Site.CustomCode,
})) }))
} }
@ -204,7 +203,6 @@ func (cp *commonPage) network(c *gin.Context) {
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/network"), mygin.CommonEnvironment(c, gin.H{ c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/network"), mygin.CommonEnvironment(c, gin.H{
"Servers": string(serversBytes), "Servers": string(serversBytes),
"MonitorInfos": string(monitorInfos), "MonitorInfos": string(monitorInfos),
"CustomCode": singleton.Conf.Site.CustomCode,
"MaxTCPPingValue": singleton.Conf.MaxTCPPingValue, "MaxTCPPingValue": singleton.Conf.MaxTCPPingValue,
})) }))
} }
@ -254,8 +252,7 @@ func (cp *commonPage) home(c *gin.Context) {
return return
} }
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/home"), mygin.CommonEnvironment(c, gin.H{ c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/home"), mygin.CommonEnvironment(c, gin.H{
"Servers": string(stat), "Servers": string(stat),
"CustomCode": singleton.Conf.Site.CustomCode,
})) }))
} }

View File

@ -908,6 +908,7 @@ type settingForm struct {
Theme string Theme string
DashboardTheme string DashboardTheme string
CustomCode string CustomCode string
CustomCodeDashboard string
ViewPassword string ViewPassword string
IgnoredIPNotification string IgnoredIPNotification string
IPChangeNotificationTag string // IP变更提醒的通知组 IPChangeNotificationTag string // IP变更提醒的通知组
@ -973,6 +974,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
singleton.Conf.Site.Theme = sf.Theme singleton.Conf.Site.Theme = sf.Theme
singleton.Conf.Site.DashboardTheme = sf.DashboardTheme singleton.Conf.Site.DashboardTheme = sf.DashboardTheme
singleton.Conf.Site.CustomCode = sf.CustomCode singleton.Conf.Site.CustomCode = sf.CustomCode
singleton.Conf.Site.CustomCodeDashboard = sf.CustomCodeDashboard
singleton.Conf.Site.ViewPassword = sf.ViewPassword singleton.Conf.Site.ViewPassword = sf.ViewPassword
singleton.Conf.Oauth2.Admin = sf.Admin singleton.Conf.Oauth2.Admin = sf.Admin
// 保证NotificationTag不为空 // 保证NotificationTag不为空

View File

@ -80,12 +80,13 @@ type Config struct {
Debug bool // debug模式开关 Debug bool // debug模式开关
Language string // 系统语言,默认 zh-CN Language string // 系统语言,默认 zh-CN
Site struct { Site struct {
Brand string // 站点名称 Brand string // 站点名称
CookieName string // 浏览器 Cookie 名称 CookieName string // 浏览器 Cookie 名称
Theme string Theme string
DashboardTheme string DashboardTheme string
CustomCode string CustomCode string
ViewPassword string // 前台查看密码 CustomCodeDashboard string
ViewPassword string // 前台查看密码
} }
Oauth2 struct { Oauth2 struct {
Type string Type string

View File

@ -26,6 +26,8 @@ func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H {
data["Version"] = singleton.Version data["Version"] = singleton.Version
data["Conf"] = singleton.Conf data["Conf"] = singleton.Conf
data["Themes"] = model.Themes data["Themes"] = model.Themes
data["CustomCode"] = singleton.Conf.Site.CustomCode
data["CustomCodeDashboard"] = singleton.Conf.Site.CustomCodeDashboard
// 是否是管理页面 // 是否是管理页面
data["IsAdminPage"] = adminPage[data["MatchedPath"].(string)] data["IsAdminPage"] = adminPage[data["MatchedPath"].(string)]
// 站点标题 // 站点标题

View File

@ -37,8 +37,7 @@ func ValidateViewPassword(opt ValidateViewPasswordOption) gin.HandlerFunc {
} }
if opt.IsPage { if opt.IsPage {
c.HTML(http.StatusOK, GetPreferredTheme(c, "/viewpassword"), CommonEnvironment(c, gin.H{ c.HTML(http.StatusOK, GetPreferredTheme(c, "/viewpassword"), CommonEnvironment(c, gin.H{
"Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "VerifyPassword"}), "Title": singleton.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "VerifyPassword"}),
"CustomCode": singleton.Conf.Site.CustomCode,
})) }))
} else { } else {

View File

@ -331,6 +331,9 @@ other = "Frontend Theme"
[CustomCodes] [CustomCodes]
other = "Custom Codes (Style and Script)" other = "Custom Codes (Style and Script)"
[CustomCodesDashboard]
other = "Custom Codes for Dashboard"
[AccessPassword] [AccessPassword]
other = "Frontend Access Password" other = "Frontend Access Password"

View File

@ -331,6 +331,9 @@ other = "Tema de Frontend"
[CustomCodes] [CustomCodes]
other = "Códigos Personalizados (Incluye style y script)" other = "Códigos Personalizados (Incluye style y script)"
[CustomCodesDashboard]
other = "Custom Codes for Dashboard"
[AccessPassword] [AccessPassword]
other = "Contraseña de Acceso al Frontend" other = "Contraseña de Acceso al Frontend"

View File

@ -331,6 +331,9 @@ other = "前台界面主题"
[CustomCodes] [CustomCodes]
other = "自定义代码(包括 style 和 script" other = "自定义代码(包括 style 和 script"
[CustomCodesDashboard]
other = "Custom Codes for Dashboard"
[AccessPassword] [AccessPassword]
other = "前台访问密码" other = "前台访问密码"

View File

@ -331,6 +331,9 @@ other = "前台界面主題"
[CustomCodes] [CustomCodes]
other = "自定義代碼(包括 style 和 script" other = "自定義代碼(包括 style 和 script"
[CustomCodesDashboard]
other = "Custom Codes for Dashboard"
[AccessPassword] [AccessPassword]
other = "前台訪問密碼" other = "前台訪問密碼"

View File

@ -14,8 +14,7 @@
<script> <script>
(function () { (function () {
updateLang({{.LANG }}); updateLang({{.LANG }});
document.documentElement.setAttribute('nz-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') })();
}) ();
</script> </script>
</body> </body>

View File

@ -13,6 +13,10 @@
<link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css"> <link rel="stylesheet" type="text/css" href="/static/semantic-ui-alerts.min.css">
<link rel="stylesheet" type="text/css" href="/static/main.css?v20240813"> <link rel="stylesheet" type="text/css" href="/static/main.css?v20240813">
<link rel="stylesheet" type="text/css" href="/static/darkmode.css?v20240813"> <link rel="stylesheet" type="text/css" href="/static/darkmode.css?v20240813">
<script>
document.documentElement.setAttribute('nz-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
</script>
</head> </head>
{{if ts .CustomCodeDashboard}} {{.CustomCodeDashboard|safe}} {{end}}
<body> <body>
{{end}} {{end}}

View File

@ -41,6 +41,10 @@
<label>{{tr "CustomCodes"}}</label> <label>{{tr "CustomCodes"}}</label>
<textarea name="CustomCode">{{.Conf.Site.CustomCode}}</textarea> <textarea name="CustomCode">{{.Conf.Site.CustomCode}}</textarea>
</div> </div>
<div class="field">
<label>{{tr "CustomCodesDashboard"}}</label>
<textarea name="CustomCodeDashboard">{{.Conf.Site.CustomCodeDashboard}}</textarea>
</div>
<div class="field"> <div class="field">
<label>{{tr "AccessPassword"}}</label> <label>{{tr "AccessPassword"}}</label>
<input type="text" name="ViewPassword" placeholder="" value="{{.Conf.Site.ViewPassword}}"> <input type="text" name="ViewPassword" placeholder="" value="{{.Conf.Site.ViewPassword}}">
@ -128,13 +132,13 @@
}) })
$('.checkbox').checkbox() $('.checkbox').checkbox()
$('#settingForm').find("select[name=Cover]").val({{.Conf.Cover }}); $('#settingForm').find("select[name=Cover]").val({{.Conf.Cover }});
{{if .Conf.EnableIPChangeNotification}} {{ if .Conf.EnableIPChangeNotification}}
$('.checkbox.ip-change').checkbox('set checked') $('.checkbox.ip-change').checkbox('set checked')
{{ end }} {{ end }}
{{if .Conf.EnablePlainIPInNotification}} {{ if .Conf.EnablePlainIPInNotification}}
$('.checkbox.plain-ip').checkbox('set checked') $('.checkbox.plain-ip').checkbox('set checked')
{{ end }} {{ end }}
{{if .Conf.DisableSwitchTemplateInFrontend }} {{ if .Conf.DisableSwitchTemplateInFrontend }}
$('.checkbox.disable-switch-template').checkbox('set checked') $('.checkbox.disable-switch-template').checkbox('set checked')
{{ end }} {{ end }}
</script> </script>

View File

@ -14,7 +14,6 @@
// console.log("currentBackendTheme:",currentBackendTheme); // console.log("currentBackendTheme:",currentBackendTheme);
} }
showSwitchTemplate({{ .Themes }}, {{ .Conf.Site.Theme }}) showSwitchTemplate({{ .Themes }}, {{ .Conf.Site.Theme }})
document.documentElement.setAttribute('nz-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
</script> </script>
{{ end }} {{ end }}
<script> <script>

View File

@ -1,6 +1,7 @@
{{define "theme-default/header"}} {{define "theme-default/header"}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{.Conf.Language}}"> <html lang="{{.Conf.Language}}">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -21,7 +22,10 @@
<script src="https://unpkg.com/echarts@5.5.0/dist/echarts.min.js"></script> <script src="https://unpkg.com/echarts@5.5.0/dist/echarts.min.js"></script>
<script src="/static/semantic-ui-alerts.min.js"></script> <script src="/static/semantic-ui-alerts.min.js"></script>
<script src="/static/theme-default/js/mixin.js?v20240302"></script> <script src="/static/theme-default/js/mixin.js?v20240302"></script>
<script>
document.documentElement.setAttribute('nz-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
</script>
</head> </head>
<body> <body>
{{end}} {{end}}