useMenuSetting.ts 4.7 KB

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