useMenuSetting.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import type { MenuSetting } from '/@/types/config';
  2. import { computed, unref, ref } from 'vue';
  3. import { appStore } from '/@/store/modules/app';
  4. import { SIDE_BAR_MINI_WIDTH, SIDE_BAR_SHOW_TIT_MINI_WIDTH } from '/@/enums/appEnum';
  5. import { MenuModeEnum, MenuTypeEnum, TriggerEnum } from '/@/enums/menuEnum';
  6. import { useFullContent } from '/@/hooks/web/useFullContent';
  7. const mixSideHasChildren = ref(false);
  8. // Get menu configuration
  9. const getMenuSetting = computed(() => appStore.getProjectConfig.menuSetting);
  10. const getCollapsed = computed(() => unref(getMenuSetting).collapsed);
  11. const getMenuType = computed(() => unref(getMenuSetting).type);
  12. const getMenuMode = computed(() => unref(getMenuSetting).mode);
  13. const getMenuFixed = computed(() => unref(getMenuSetting).fixed);
  14. const getShowMenu = computed(() => unref(getMenuSetting).show);
  15. const getMenuHidden = computed(() => unref(getMenuSetting).hidden);
  16. const getMenuWidth = computed(() => unref(getMenuSetting).menuWidth);
  17. const getTrigger = computed(() => unref(getMenuSetting).trigger);
  18. const getMenuTheme = computed(() => unref(getMenuSetting).theme);
  19. const getSplit = computed(() => unref(getMenuSetting).split);
  20. const getMenuBgColor = computed(() => unref(getMenuSetting).bgColor);
  21. const getMixSideTrigger = computed(() => unref(getMenuSetting).mixSideTrigger);
  22. const getCanDrag = computed(() => unref(getMenuSetting).canDrag);
  23. const getAccordion = computed(() => unref(getMenuSetting).accordion);
  24. const getMixSideFixed = computed(() => unref(getMenuSetting).mixSideFixed);
  25. const getTopMenuAlign = computed(() => unref(getMenuSetting).topMenuAlign);
  26. const getCloseMixSidebarOnChange = computed(() => unref(getMenuSetting).closeMixSidebarOnChange);
  27. const getIsSidebarType = computed(() => unref(getMenuType) === MenuTypeEnum.SIDEBAR);
  28. const getIsTopMenu = computed(() => unref(getMenuType) === MenuTypeEnum.TOP_MENU);
  29. const getCollapsedShowTitle = computed(() => unref(getMenuSetting).collapsedShowTitle);
  30. const getShowTopMenu = computed(() => {
  31. return unref(getMenuMode) === MenuModeEnum.HORIZONTAL || unref(getSplit);
  32. });
  33. const getShowHeaderTrigger = computed(() => {
  34. if (unref(getMenuType) === MenuTypeEnum.TOP_MENU || !unref(getShowMenu) || unref(getMenuHidden)) {
  35. return false;
  36. }
  37. return unref(getTrigger) === TriggerEnum.HEADER;
  38. });
  39. const getIsHorizontal = computed(() => {
  40. return unref(getMenuMode) === MenuModeEnum.HORIZONTAL;
  41. });
  42. const getIsMixSidebar = computed(() => {
  43. return unref(getMenuType) === MenuTypeEnum.MIX_SIDEBAR;
  44. });
  45. const getIsMixMode = computed(() => {
  46. return unref(getMenuMode) === MenuModeEnum.INLINE && unref(getMenuType) === MenuTypeEnum.MIX;
  47. });
  48. const getRealWidth = computed(() => {
  49. return unref(getCollapsed) && !unref(getMixSideFixed)
  50. ? unref(getMiniWidthNumber)
  51. : unref(getMenuWidth);
  52. });
  53. const getMiniWidthNumber = computed(() => {
  54. const { collapsedShowTitle } = unref(getMenuSetting);
  55. return collapsedShowTitle ? SIDE_BAR_SHOW_TIT_MINI_WIDTH : SIDE_BAR_MINI_WIDTH;
  56. });
  57. const getCalcContentWidth = computed(() => {
  58. const width =
  59. unref(getIsTopMenu) || !unref(getShowMenu) || (unref(getSplit) && unref(getMenuHidden))
  60. ? 0
  61. : unref(getIsMixSidebar)
  62. ? SIDE_BAR_SHOW_TIT_MINI_WIDTH +
  63. (unref(getMixSideFixed) && unref(mixSideHasChildren) ? unref(getRealWidth) : 0)
  64. : unref(getRealWidth);
  65. return `calc(100% - ${unref(width)}px)`;
  66. });
  67. const { getFullContent: fullContent } = useFullContent();
  68. const getShowSidebar = computed(() => {
  69. return (
  70. unref(getSplit) ||
  71. (unref(getShowMenu) && unref(getMenuMode) !== MenuModeEnum.HORIZONTAL && !unref(fullContent))
  72. );
  73. });
  74. // Set menu configuration
  75. function setMenuSetting(menuSetting: Partial<MenuSetting>): void {
  76. appStore.commitProjectConfigState({ menuSetting });
  77. }
  78. function toggleCollapsed() {
  79. setMenuSetting({
  80. collapsed: !unref(getCollapsed),
  81. });
  82. }
  83. export function useMenuSetting() {
  84. return {
  85. setMenuSetting,
  86. toggleCollapsed,
  87. getMenuFixed,
  88. getMenuSetting,
  89. getRealWidth,
  90. getMenuType,
  91. getMenuMode,
  92. getShowMenu,
  93. getCollapsed,
  94. getMiniWidthNumber,
  95. getCalcContentWidth,
  96. getMenuWidth,
  97. getTrigger,
  98. getSplit,
  99. getMenuTheme,
  100. getCanDrag,
  101. getCollapsedShowTitle,
  102. getIsHorizontal,
  103. getIsSidebarType,
  104. getAccordion,
  105. getShowTopMenu,
  106. getShowHeaderTrigger,
  107. getTopMenuAlign,
  108. getMenuHidden,
  109. getIsTopMenu,
  110. getMenuBgColor,
  111. getShowSidebar,
  112. getIsMixMode,
  113. getIsMixSidebar,
  114. getCloseMixSidebarOnChange,
  115. getMixSideTrigger,
  116. getMixSideFixed,
  117. mixSideHasChildren,
  118. };
  119. }