mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-03 12:05:28 +08:00
前端和后端源码,合并到一个git仓库中,方便用户下载,避免前后端不匹配的问题
This commit is contained in:
24
jeecgboot-vue3/src/logics/theme/dark.ts
Normal file
24
jeecgboot-vue3/src/logics/theme/dark.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { darkCssIsReady, loadDarkThemeCss } from '@rys-fe/vite-plugin-theme/es/client';
|
||||
import { addClass, hasClass, removeClass } from '/@/utils/domUtils';
|
||||
|
||||
export async function updateDarkTheme(mode: string | null = 'light') {
|
||||
const htmlRoot = document.getElementById('htmlRoot');
|
||||
if (!htmlRoot) {
|
||||
return;
|
||||
}
|
||||
const hasDarkClass = hasClass(htmlRoot, 'dark');
|
||||
if (mode === 'dark') {
|
||||
if (import.meta.env.PROD && !darkCssIsReady) {
|
||||
await loadDarkThemeCss();
|
||||
}
|
||||
htmlRoot.setAttribute('data-theme', 'dark');
|
||||
if (!hasDarkClass) {
|
||||
addClass(htmlRoot, 'dark');
|
||||
}
|
||||
} else {
|
||||
htmlRoot.setAttribute('data-theme', 'light');
|
||||
if (hasDarkClass) {
|
||||
removeClass(htmlRoot, 'dark');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user