updateBackground.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { /** colorIsDark */ lighten, darken } from '/@/utils/color';
  2. import { useAppStore } from '/@/store/modules/app';
  3. import { ThemeEnum } from '/@/enums/appEnum';
  4. import { setCssVar } from './util';
  5. import { SIDE_BAR_BG_COLOR_LIST, SIDER_LOGO_BG_COLOR_LIST } from '/@/settings/designSetting';
  6. const HEADER_BG_COLOR_VAR = '--vent-header-bg-color';
  7. const HEADER_BG_HOVER_COLOR_VAR = '--header-bg-hover-color';
  8. const HEADER_MENU_ACTIVE_BG_COLOR_VAR = '--header-active-menu-bg-color';
  9. const SIDER_LOGO_BG_COLOR = '--sider-logo-bg-color';
  10. const SIDER_DARK_BG_COLOR = '--sider-dark-bg-color';
  11. const SIDER_DARK_DARKEN_BG_COLOR = '--sider-dark-darken-bg-color';
  12. const SIDER_LIGHTEN_BG_COLOR = '--sider-dark-lighten-bg-color';
  13. /**
  14. * [deprecated] Change the background color of the top header
  15. * @param color
  16. */
  17. export function updateHeaderBgColor(color?: string) {
  18. const appStore = useAppStore();
  19. // const defaultMode = appStore.getDarkMode === ThemeEnum.VENT1;
  20. appStore.setProjectConfig({
  21. headerSetting: {
  22. theme: appStore.getDarkMode as ThemeEnum,
  23. },
  24. });
  25. // if theme is not default, set the colors in /design/colors or /design/themify/
  26. if (!color) {
  27. return;
  28. }
  29. // if (!color) {
  30. // color = appStore.getHeaderSetting.bgColor;
  31. // }
  32. // bg color
  33. setCssVar(HEADER_BG_COLOR_VAR, color);
  34. // hover color
  35. const hoverColor = lighten(color!, 6);
  36. setCssVar(HEADER_BG_HOVER_COLOR_VAR, hoverColor);
  37. setCssVar(HEADER_MENU_ACTIVE_BG_COLOR_VAR, hoverColor);
  38. // Determine the depth of the color value and automatically switch the theme
  39. // const isDark = colorIsDark(color!);
  40. }
  41. /**
  42. * [deprecated] Change the background color of the left menu
  43. * @param color bg color
  44. */
  45. export function updateSidebarBgColor(color?: string) {
  46. const appStore = useAppStore();
  47. // if (!isHexColor(color)) return;
  48. // const defaultMode = appStore.getDarkMode === ThemeEnum.VENT1;
  49. appStore.setProjectConfig({
  50. headerSetting: {
  51. theme: appStore.getDarkMode as ThemeEnum,
  52. },
  53. });
  54. // if theme is not default, set the colors in /design/colors or /design/themify/
  55. if (!color) {
  56. return;
  57. }
  58. // if (!color) {
  59. // color = appStore.getMenuSetting.bgColor;
  60. // }
  61. // update-begin--author:liaozhiyang---date:20230811---for:【QQYUN-5922】logo背景色渐变
  62. const findIndex = SIDE_BAR_BG_COLOR_LIST.findIndex((item) => item === color);
  63. setCssVar(SIDER_LOGO_BG_COLOR, findIndex == -1 ? 'linear-gradient(180deg, #000000, #282828)' : SIDER_LOGO_BG_COLOR_LIST[findIndex]);
  64. // update-end--author:liaozhiyang---date:20230811---for:【QQYUN-5922】llogo背景色渐变
  65. setCssVar(SIDER_DARK_BG_COLOR, color);
  66. setCssVar(SIDER_DARK_DARKEN_BG_COLOR, darken(color!, 6));
  67. setCssVar(SIDER_LIGHTEN_BG_COLOR, lighten(color!, 5));
  68. // only #ffffff is light
  69. // Only when the background color is #fff, the theme of the menu will be changed to light
  70. // const isLight = ['#fff', '#ffffff'].includes(color!.toLowerCase());
  71. }