feat: 深色模式基础设施 (system theme + 跟随系统)

This commit is contained in:
2026-07-08 11:33:09 +08:00
parent a88c4da361
commit c43f1d7389
6 changed files with 88 additions and 4 deletions
+9 -4
View File
@@ -94,19 +94,24 @@ const setTheme = (id) => {
return theme
}
const getThemeStyle = (theme) => {
const getThemeStyle = (theme, isDark = false) => {
const t = theme || getCurrentTheme()
return `${BASE_VARS}--primary:${t.primary};--primary-light:${t.primaryLight};--primary-bg:${t.primaryBg};--primary-rgb:${t.primaryRgb};`
const baseVars = isDark
? '--text:#E5E5E7;--text-secondary:#98989F;--bg:#0F0F12;--card-bg:#1C1C1E;--border:#2C2C2E;--success:#30D158;'
: '--text:#333333;--text-secondary:#999999;--bg:#F5F5F5;--card-bg:#FFFFFF;--border:#EEEEEE;--success:#4CAF50;'
return `${baseVars}--primary:${t.primary};--primary-light:${t.primaryLight};--primary-bg:${t.primaryBg};--primary-rgb:${t.primaryRgb};`
}
const applyThemeToPage = (self) => {
const darkMod = require('./darkMode')
const theme = getCurrentTheme()
const nextStyle = getThemeStyle(theme)
const isDark = darkMod.getInitialDarkMode()
const nextStyle = getThemeStyle(theme, isDark)
// Skip setData if nothing changed — avoid unnecessary re-renders on every onShow
if (self.data && self.data.themeStyle === nextStyle) {
return
}
self.setData({ theme, themeStyle: nextStyle })
self.setData({ theme, themeStyle: nextStyle, isDark })
_setNavBarColor(theme.primary)
}