mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(components): 添加主题配置抽屉,添加暗黑主题
This commit is contained in:
31
src/plugins/dark-mode.ts
Normal file
31
src/plugins/dark-mode.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
@ -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 };
|
||||
|
Reference in New Issue
Block a user