CNCEC_APP/uni_modules/uview-pro/libs/util/system-theme.ts

26 lines
728 B
TypeScript
Raw Normal View History

2026-03-25 14:54:15 +08:00
declare const uni: any;
type SystemTheme = 'light' | 'dark';
/**
* H5
*/
export function getSystemDarkMode(): SystemTheme {
try {
if (typeof uni !== 'undefined' && typeof uni.getSystemInfoSync === 'function') {
const systemInfo = uni.getSystemInfoSync();
const theme = systemInfo.osTheme || systemInfo.theme || 'light';
if (theme === 'dark') {
return 'dark';
}
if (theme === 'light') {
return 'light';
}
}
} catch (e) {
// 获取失败时默认返回亮色
console.warn('[system-theme] getSystemDarkMode failed', e);
}
return 'light';
}