fix: 手机状态栏暗黑模式背景颜色显示不正确

This commit is contained in:
CH-122
2025-08-15 14:52:30 +08:00
parent 72e7ccf262
commit c1d19b854b
2 changed files with 45 additions and 1 deletions

View File

@@ -26,7 +26,28 @@ export default defineNuxtConfig({
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = mode === 'dark' || mode === 'light' ? mode : (prefersDark ? 'dark' : 'light');
document.documentElement.dataset.theme = theme;
} catch (e) {}
let themeColor = '#fff';
if (theme === 'dark') {
themeColor = '#333';
} else {
themeColor = '#ffffff';
}
const androidMeta = document.createElement('meta');
androidMeta.name = 'theme-color';
androidMeta.content = themeColor;
const iosMeta = document.createElement('meta');
iosMeta.name = 'apple-mobile-web-app-status-bar-style';
iosMeta.content = themeColor;
document.head.appendChild(androidMeta);
document.head.appendChild(iosMeta);
} catch (e) {
console.warn('Theme initialization failed:', e);
}
})();
`,
},