feat(components): 添加主题配置抽屉,添加暗黑主题

This commit is contained in:
Soybean
2021-09-01 17:43:25 +08:00
parent 205037397f
commit a87593f58a
27 changed files with 364 additions and 36 deletions

31
src/plugins/dark-mode.ts Normal file
View File

@ -0,0 +1,31 @@
import { watch } from 'vue';
import { useAppStore } from '@/store';
export default function setupWindicssDarkMode() {
const app = useAppStore();
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(
() => app.themeSettings.darkMode,
newValue => {
if (newValue) {
addDarkClass();
} else {
removeDarkClass();
}
}
);
}

View File

@ -1,4 +1,5 @@
import setupSmoothScroll from './smooth-scroll';
import setupNaive from './naive';
import setupWindicssDarkMode from './dark-mode';
export { setupSmoothScroll, setupNaive };
export { setupSmoothScroll, setupNaive, setupWindicssDarkMode };