重构: 前端Vue3+Tailwind+Vite构建管线+设置组件拆分

This commit is contained in:
2026-05-27 02:42:25 +08:00
parent f3148bf72f
commit aee7997195
44 changed files with 4309 additions and 1720 deletions

View File

@@ -62,50 +62,33 @@ func buildWallpaperHTML(cfg *Config) string {
if cfg.HideWallpaper {
bgWrapped = `<div id="bg-layer" style="display:none"></div>`
}
html := strings.Replace(overlayHTML, "{{BACKGROUND}}", bgWrapped, 1)
html = strings.Replace(html, "{{LAYOUT}}", string(cfg.Layout), 1)
var bodyClasses []string
if cfg.HideTime {
bodyClasses = append(bodyClasses, "hide-time")
}
if cfg.HideWeather {
bodyClasses = append(bodyClasses, "hide-weather")
}
if cfg.HideZodiac {
bodyClasses = append(bodyClasses, "hide-zodiac")
}
showSec := "false"
if cfg.ShowSeconds {
showSec = "true"
}
html = strings.Replace(html, "{{SHOW_SECONDS}}", showSec, 1)
if cfg.HideAINews {
bodyClasses = append(bodyClasses, "hide-ainews")
}
if cfg.HideKnowledge {
bodyClasses = append(bodyClasses, "hide-knowledge")
}
if cfg.HidePhoto {
bodyClasses = append(bodyClasses, "hide-photo")
}
if cfg.PhotoFrameMode && cfg.PhotoDir != "" {
bodyClasses = append(bodyClasses, "photo-frame-mode")
}
if len(bodyClasses) > 0 {
cls := strings.Join(bodyClasses, " ")
html = strings.Replace(html, "{{BODY_CLASSES}}", cls, 1)
} else {
html = strings.Replace(html, " {{BODY_CLASSES}}", "", 1)
initialData := map[string]interface{}{
"backgroundHtml": bgWrapped,
"layout": string(cfg.Layout),
"showSeconds": cfg.ShowSeconds,
"userZodiac": cfg.Zodiac,
"wallpaperVisible": !cfg.HideWallpaper,
"photoFrameMode": cfg.PhotoFrameMode && cfg.PhotoDir != "",
"cardVisibility": map[string]bool{
"time": !cfg.HideTime,
"weather": !cfg.HideWeather,
"zodiac": !cfg.HideZodiac,
"knowledge": !cfg.HideKnowledge,
"ainews": !cfg.HideAINews,
"photo": !cfg.HidePhoto,
},
}
dataJSON, _ := json.Marshal(initialData)
inject := fmt.Sprintf(`<script>window.__INITIAL_DATA__=%s;</script>`, string(dataJSON))
// 注入自定义文字
if cfg.WallpaperType == WPTheme && cfg.Theme == ThemeText && cfg.WallpaperText != "" {
escaped, _ := json.Marshal(cfg.WallpaperText)
html = strings.Replace(html, "</script>", `window.wallpaperText = `+string(escaped)+`;</script>`, 1)
inject += fmt.Sprintf(`<script>window.wallpaperText=%s;</script>`, string(escaped))
}
return html
return strings.Replace(overlayHTML, "</head>", inject+"</head>", 1)
}
func imageToDataURI(path string) string {
@@ -194,7 +177,10 @@ func updateBackground(cfg *Config) {
display = ` style="display:none"`
}
html := fmt.Sprintf(`<div id="bg-layer"%s>%s</div>`, display, bg)
evalJS(fmt.Sprintf(`var el=document.getElementById('bg-layer'); if(el){el.outerHTML=%q;}`, html))
// Update Vue reactive state via bridge
evalJS(fmt.Sprintf(`if(window.__updateBackgroundHtml) window.__updateBackgroundHtml(%q);`, html))
// Fallback: direct DOM update for non-Vue contexts
evalJS(fmt.Sprintf(`var el=document.getElementById('bg-layer'); if(el && !window.__updateBackgroundHtml){el.outerHTML=%q;}`, html))
}
func reloadAllCards() {