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"}),
"Services": res.([]interface{})[0],
"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{
"Servers": string(serversBytes),
"MonitorInfos": string(monitorInfos),
"CustomCode": singleton.Conf.Site.CustomCode,
"MaxTCPPingValue": singleton.Conf.MaxTCPPingValue,
}))
}
@ -254,8 +252,7 @@ func (cp *commonPage) home(c *gin.Context) {
return
}
c.HTML(http.StatusOK, mygin.GetPreferredTheme(c, "/home"), mygin.CommonEnvironment(c, gin.H{
"Servers": string(stat),
"CustomCode": singleton.Conf.Site.CustomCode,
"Servers": string(stat),
}))
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,8 +14,7 @@
<script>
(function () {
updateLang({{.LANG }});
document.documentElement.setAttribute('nz-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
}) ();
})();
</script>
</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/main.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>
{{if ts .CustomCodeDashboard}} {{.CustomCodeDashboard|safe}} {{end}}
<body>
{{end}}

View File

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

View File

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

View File

@ -1,6 +1,7 @@
{{define "theme-default/header"}}
<!DOCTYPE html>
<html lang="{{.Conf.Language}}">
<head>
<meta charset="UTF-8">
<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="/static/semantic-ui-alerts.min.js"></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>
<body>
{{end}}
{{end}}