handler.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { HandlerEnum } from './enum';
  2. import { updateHeaderBgColor, updateSidebarBgColor } from '@/logics/theme/updateBackground';
  3. import { updateColorWeak } from '@/logics/theme/updateColorWeak';
  4. import { updateGrayMode } from '@/logics/theme/updateGrayMode';
  5. import { useAppStore } from '@/store/modules/app';
  6. import { ProjectConfig } from '#/config';
  7. import { updateDarkTheme } from '@/logics/theme/dark';
  8. import { useRootSetting } from '@/hooks/setting/useRootSetting';
  9. export function baseHandler(event: HandlerEnum, value: any) {
  10. const appStore = useAppStore();
  11. const config = handler(event, value);
  12. appStore.setProjectConfig(config);
  13. if (event === HandlerEnum.CHANGE_THEME) {
  14. updateHeaderBgColor();
  15. updateSidebarBgColor();
  16. }
  17. }
  18. export function handler(event: HandlerEnum, value: any): DeepPartial<ProjectConfig> {
  19. const appStore = useAppStore();
  20. const { getThemeColor, getDarkMode } = useRootSetting();
  21. switch (event) {
  22. case HandlerEnum.CHANGE_LAYOUT:
  23. const { mode, type, split } = value;
  24. const splitOpt = split === undefined ? { split } : {};
  25. return {
  26. menuSetting: {
  27. mode,
  28. type,
  29. collapsed: false,
  30. show: true,
  31. hidden: false,
  32. ...splitOpt,
  33. },
  34. };
  35. case HandlerEnum.CHANGE_THEME_COLOR:
  36. if (getThemeColor.value === value) {
  37. return {};
  38. }
  39. return { themeColor: value };
  40. case HandlerEnum.CHANGE_THEME:
  41. if (getDarkMode.value === value) {
  42. return {};
  43. }
  44. updateDarkTheme(value);
  45. return {};
  46. case HandlerEnum.MENU_HAS_DRAG:
  47. return { menuSetting: { canDrag: value } };
  48. case HandlerEnum.MENU_ACCORDION:
  49. return { menuSetting: { accordion: value } };
  50. case HandlerEnum.MENU_TRIGGER:
  51. return { menuSetting: { trigger: value } };
  52. case HandlerEnum.MENU_TOP_ALIGN:
  53. return { menuSetting: { topMenuAlign: value } };
  54. case HandlerEnum.MENU_COLLAPSED:
  55. return { menuSetting: { collapsed: value } };
  56. case HandlerEnum.MENU_WIDTH:
  57. return { menuSetting: { menuWidth: value } };
  58. case HandlerEnum.MENU_SHOW_SIDEBAR:
  59. return { menuSetting: { show: value } };
  60. case HandlerEnum.MENU_COLLAPSED_SHOW_TITLE:
  61. return { menuSetting: { collapsedShowTitle: value } };
  62. case HandlerEnum.MENU_THEME:
  63. updateSidebarBgColor(value);
  64. return { menuSetting: { bgColor: value } };
  65. case HandlerEnum.MENU_SPLIT:
  66. return { menuSetting: { split: value } };
  67. case HandlerEnum.MENU_CLOSE_MIX_SIDEBAR_ON_CHANGE:
  68. return { menuSetting: { closeMixSidebarOnChange: value } };
  69. case HandlerEnum.MENU_FIXED:
  70. return { menuSetting: { fixed: value } };
  71. case HandlerEnum.MENU_TRIGGER_MIX_SIDEBAR:
  72. return { menuSetting: { mixSideTrigger: value } };
  73. case HandlerEnum.MENU_FIXED_MIX_SIDEBAR:
  74. return { menuSetting: { mixSideFixed: value } };
  75. // ============transition==================
  76. case HandlerEnum.OPEN_PAGE_LOADING:
  77. appStore.setPageLoading(false);
  78. return { transitionSetting: { openPageLoading: value } };
  79. case HandlerEnum.ROUTER_TRANSITION:
  80. return { transitionSetting: { basicTransition: value } };
  81. case HandlerEnum.OPEN_ROUTE_TRANSITION:
  82. return { transitionSetting: { enable: value } };
  83. case HandlerEnum.OPEN_PROGRESS:
  84. return { transitionSetting: { openNProgress: value } };
  85. // ============root==================
  86. case HandlerEnum.LOCK_TIME:
  87. return { lockTime: value };
  88. case HandlerEnum.FULL_CONTENT:
  89. return { fullContent: value };
  90. case HandlerEnum.CONTENT_MODE:
  91. return { contentMode: value };
  92. case HandlerEnum.SHOW_BREADCRUMB:
  93. return { showBreadCrumb: value };
  94. case HandlerEnum.SHOW_BREADCRUMB_ICON:
  95. return { showBreadCrumbIcon: value };
  96. case HandlerEnum.GRAY_MODE:
  97. updateGrayMode(value);
  98. return { grayMode: value };
  99. case HandlerEnum.SHOW_FOOTER:
  100. return { showFooter: value };
  101. case HandlerEnum.COLOR_WEAK:
  102. updateColorWeak(value);
  103. return { colorWeak: value };
  104. case HandlerEnum.SHOW_LOGO:
  105. return { showLogo: value };
  106. // ============tabs==================
  107. case HandlerEnum.TABS_SHOW_QUICK:
  108. return { multiTabsSetting: { showQuick: value } };
  109. case HandlerEnum.TABS_SHOW:
  110. return { multiTabsSetting: { show: value } };
  111. case HandlerEnum.TABS_SHOW_REDO:
  112. return { multiTabsSetting: { showRedo: value } };
  113. case HandlerEnum.TABS_SHOW_FOLD:
  114. return { multiTabsSetting: { showFold: value } };
  115. case HandlerEnum.TABS_AUTO_COLLAPSE:
  116. return { multiTabsSetting: { autoCollapse: value } };
  117. // ============header==================
  118. case HandlerEnum.HEADER_THEME:
  119. updateHeaderBgColor(value);
  120. return { headerSetting: { bgColor: value } };
  121. case HandlerEnum.HEADER_SEARCH:
  122. return { headerSetting: { showSearch: value } };
  123. case HandlerEnum.HEADER_FIXED:
  124. return { headerSetting: { fixed: value } };
  125. case HandlerEnum.HEADER_SHOW:
  126. return { headerSetting: { show: value } };
  127. default:
  128. return {};
  129. }
  130. }