feat: 支持跟随系统深色/浅色模式(darkmode + theme.json + 主题检测)

This commit is contained in:
2026-08-06 16:40:03 +08:00
parent 06ae61f083
commit e01951cd0e
8 changed files with 66 additions and 5 deletions
+8 -2
View File
@@ -262,8 +262,14 @@ export function setTheme(theme: ThemeMode) {
/** 根据自动模式解析实际生效主题 */
export function resolveTheme(mode: ThemeMode): 'light' | 'dark' {
if (mode === 'auto') {
const info = Taro.getSystemInfoSync()
return info.theme === 'dark' ? 'dark' : 'light'
// 需 app.json 开启 darkmode 后 theme 字段才有效;getSystemInfoSync 已废弃,改用 getAppBaseInfo
try {
const info = Taro.getAppBaseInfo()
return info.theme === 'dark' ? 'dark' : 'light'
} catch {
const info = Taro.getSystemInfoSync()
return info.theme === 'dark' ? 'dark' : 'light'
}
}
return mode
}