feat(docs): 自适应系统暗色主题+持久化
This commit is contained in:
parent
34f2c9d992
commit
4ada2ac9b5
@ -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);
|
||||
|
||||
|
@ -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')
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user