feat(pages): 认证页与门户页文案可配置,不再写死

需求:登录页与门户页的内容应可自定义。

实现(配置存数据卷、后台可改、留空回落内置默认,不配置行为不变):
- pages.go:pageStr 读取 pageInfo;renderPortalPage 优先数据卷
  <data>/portal/index.html 整页覆盖,否则用内置模板替换占位符;
  authPageInfo 提供登录页字段
- auth.go:登录页标题/副标题/徽标/页脚改为模板数据(含备案号)
- gateway.go:kind=portal 的首页改由 admin-server /portal-page 渲染
  (静态资源仍由 nginx 提供),使文案可配置
- portal/index.html:加入 <!--PAGE_TITLE--> / <!--HERO_TITLE--> /
  <!--HERO_SUBTITLE--> / <!--FOOTER--> 占位符
- 后台「站点信息」新增六项文案输入(含回填与保存),并提示整页覆盖方式
- README 新增「认证页与门户页文案(可配置,不写死)」含字段表与自检命令

测试:默认回落、配置取值去空白、认证页字段读取、数据卷覆盖优先、空白覆盖忽略。
This commit is contained in:
HomeDash Bot
2026-09-12 09:12:13 +08:00
parent 352aa570ec
commit 472d8d1cd0
7 changed files with 248 additions and 11 deletions

View File

@ -877,6 +877,13 @@ func handlePageInfo(w http.ResponseWriter, r *http.Request) {
ICP *string `json:"icp"`
Gongan *string `json:"gongan"`
NavLinks *[]map[string]any `json:"navLinks"`
// 认证页与门户页的可配置文案(原先写死在代码/镜像里)
AuthTitle *string `json:"authTitle"`
AuthSubtitle *string `json:"authSubtitle"`
AuthLogo *string `json:"authLogo"`
PortalTitle *string `json:"portalTitle"`
HeroTitle *string `json:"heroTitle"`
HeroSubtitle *string `json:"heroSubtitle"`
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
jsonErr(w, 400, err.Error())
@ -901,7 +908,23 @@ func handlePageInfo(w http.ResponseWriter, r *http.Request) {
// 页脚为空(留空 = 交给模板)时,按备案号重新生成。
if strings.TrimSpace(mapString(cfg.PageInfo, "footer")) == "" {
cfg.PageInfo["footer"] = beianFooter(mapString(cfg.PageInfo, "icp"), mapString(cfg.PageInfo, "gongan"))
} // 认证页 / 门户页文案:空串表示回落到内置默认值
setPageStr := func(k string, v *string) {
if v != nil {
if strings.TrimSpace(*v) == "" {
delete(cfg.PageInfo, k)
} else {
cfg.PageInfo[k] = strings.TrimSpace(*v)
}
}
}
setPageStr("authTitle", body.AuthTitle)
setPageStr("authSubtitle", body.AuthSubtitle)
setPageStr("authLogo", body.AuthLogo)
setPageStr("portalTitle", body.PortalTitle)
setPageStr("heroTitle", body.HeroTitle)
setPageStr("heroSubtitle", body.HeroSubtitle)
if body.NavLinks != nil {
cfg.PageInfo["navLinks"] = *body.NavLinks
}
@ -1206,6 +1229,8 @@ func main() {
http.HandleFunc("/api/gateway/import", cors(handleGatewayImport))
// 统一登录的账号设置(存数据卷,改完立即生效,不用重新部署)
http.HandleFunc("/api/portal-auth", cors(handlePortalAuthSettings))
// 门户首页渲染(可配置文案 + 数据卷整页覆盖),供 gateway 的 kind=portal 反代
http.HandleFunc("/portal-page", handlePortalPage)
// 历史记录管理:列表 / 清空全部 / 删除单条
http.HandleFunc("/api/history", cors(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {