feat(docs): 自适应系统暗色主题+持久化

This commit is contained in:
sight 2022-04-03 02:56:07 +08:00
parent 34f2c9d992
commit 4ada2ac9b5
2 changed files with 8 additions and 1 deletions

View File

@ -229,7 +229,9 @@ export default {
{ name: "zh_CN", locale: zh_CN, merge: true },
{ name: "en_US", locale: en_US, merge: true },
];
const theme = ref("light");
let isDark = (localStorage.getItem('layui-vue-theme-dark') !== "false") ||
window.matchMedia('prefers-color-scheme: dark').matches;
const theme = ref(isDark ? "dark":"light");
const themeVariable = ref({
"--global-primary-color": "#009688",
"--global-normal-color": "#1e9fff",
@ -285,6 +287,9 @@ export default {
locale.value = lang;
};
window.matchMedia('(prefers-color-scheme: dark)')
.addListener(e => theme.value = e.matches ? "dark" : "light");
provide("theme",theme);
provide('LayuiVueVersion', layuiVueVersion);

View File

@ -60,8 +60,10 @@ const changeTheme = (theme: string) => {
disableStyleSheetsProxy: false,
}
);
localStorage.setItem('layui-vue-theme-dark','true')
} else {
disableDarkMode();
localStorage.setItem('layui-vue-theme-dark','false')
}
};