mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-21 02:56:38 +08:00
32 lines
638 B
TypeScript
32 lines
638 B
TypeScript
import { watch } from 'vue';
|
|
import { useThemeStore } from '@/store';
|
|
|
|
export default function setupWindicssDarkMode() {
|
|
const theme = useThemeStore();
|
|
|
|
const DARK_CLASS = 'dark';
|
|
|
|
function getHtmlElement() {
|
|
return document.querySelector('html')!;
|
|
}
|
|
function addDarkClass() {
|
|
const html = getHtmlElement();
|
|
html.classList.add(DARK_CLASS);
|
|
}
|
|
function removeDarkClass() {
|
|
const html = getHtmlElement();
|
|
html.classList.remove(DARK_CLASS);
|
|
}
|
|
|
|
watch(
|
|
() => theme.darkMode,
|
|
newValue => {
|
|
if (newValue) {
|
|
addDarkClass();
|
|
} else {
|
|
removeDarkClass();
|
|
}
|
|
}
|
|
);
|
|
}
|