----修改主题功能
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
import { colorIsDark, lighten, darken } from '/@/utils/color';
|
||||
import { useAppStore } from '/@/store/modules/app';
|
||||
import { ThemeEnum } from '/@/enums/appEnum';
|
||||
import { ThemeEnum } from '/@/enums/appEnum';
|
||||
import { setCssVar } from './util';
|
||||
import { MenuThemeInfo } from '/@/enums/menuEnum';
|
||||
|
||||
const HEADER_BG_COLOR_VAR = '--header-bg-color';
|
||||
const HEADER_BG_HOVER_COLOR_VAR = '--header-bg-hover-color';
|
||||
@ -73,3 +74,37 @@ export function updateSidebarBgColor(color?: string) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function updateMenuTheme(info?: MenuThemeInfo) {
|
||||
console.log("主题切换",info);
|
||||
setCssVar(HEADER_BG_COLOR_VAR, info?.background);
|
||||
setCssVar(HEADER_BG_HOVER_COLOR_VAR, info?.hover);
|
||||
setCssVar(HEADER_MENU_ACTIVE_BG_COLOR_VAR, info?.hover);
|
||||
|
||||
setCssVar(SIDER_DARK_BG_COLOR, info?.background);
|
||||
setCssVar(SIDER_DARK_DARKEN_BG_COLOR,info?.hover);
|
||||
setCssVar(SIDER_LIGHTEN_BG_COLOR, lighten(info?.hover!, 5));
|
||||
let color = info?.background;
|
||||
const appStore = useAppStore();
|
||||
const darkMode = appStore.getDarkMode === ThemeEnum.DARK;
|
||||
if (!color) {
|
||||
if (darkMode) {
|
||||
color = '#151515';
|
||||
} else {
|
||||
color = appStore.getHeaderSetting.bgColor;
|
||||
}
|
||||
}
|
||||
|
||||
const isLight = ['#fff', '#ffffff'].includes(color!.toLowerCase());
|
||||
const isDark = colorIsDark(color!);
|
||||
appStore.setProjectConfig({
|
||||
menuSetting: {
|
||||
theme: isLight && !darkMode ? ThemeEnum.LIGHT : ThemeEnum.DARK,
|
||||
},
|
||||
headerSetting: {
|
||||
theme: isDark || darkMode ? ThemeEnum.DARK : ThemeEnum.LIGHT,
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user