useMenuSetting.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import type { MenuSetting } from '/@/types/config';
  2. import { computed, unref } 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. export function useMenuSetting() {
  7. // Get menu configuration
  8. const getMenuSetting = computed(() => appStore.getProjectConfig.menuSetting);
  9. const getCollapsed = computed(() => unref(getMenuSetting).collapsed);
  10. const getMenuType = computed(() => unref(getMenuSetting).type);
  11. const getMenuMode = computed(() => unref(getMenuSetting).mode);
  12. const getMenuFixed = computed(() => unref(getMenuSetting).fixed);
  13. const getShowMenu = computed(() => unref(getMenuSetting).show);
  14. const getMenuHidden = computed(() => unref(getMenuSetting).hidden);
  15. const getMenuWidth = computed(() => unref(getMenuSetting).menuWidth);
  16. const getTrigger = computed(() => unref(getMenuSetting).trigger);
  17. const getMenuTheme = computed(() => unref(getMenuSetting).theme);
  18. const getSplit = computed(() => unref(getMenuSetting).split);
  19. const getMenuBgColor = computed(() => unref(getMenuSetting).bgColor);
  20. const getCanDrag = computed(() => unref(getMenuSetting).canDrag);
  21. const getAccordion = computed(() => unref(getMenuSetting).accordion);
  22. const getCollapsedShowTitle = computed(() => unref(getMenuSetting).collapsedShowTitle);
  23. const getTopMenuAlign = computed(() => unref(getMenuSetting).topMenuAlign);
  24. const getIsSidebarType = computed(() => unref(getMenuType) === MenuTypeEnum.SIDEBAR);
  25. const getIsTopMenu = computed(() => unref(getMenuType) === MenuTypeEnum.TOP_MENU);
  26. const getShowTopMenu = computed(() => {
  27. return unref(getMenuMode) === MenuModeEnum.HORIZONTAL || unref(getSplit);
  28. });
  29. const getShowHeaderTrigger = computed(() => {
  30. if (
  31. unref(getMenuType) === MenuTypeEnum.TOP_MENU ||
  32. !unref(getShowMenu) ||
  33. !unref(getMenuHidden)
  34. ) {
  35. return false;
  36. }
  37. return unref(getTrigger) === TriggerEnum.HEADER;
  38. });
  39. const getIsHorizontal = computed(() => {
  40. return unref(getMenuMode) === MenuModeEnum.HORIZONTAL;
  41. });
  42. const getRealWidth = computed(() => {
  43. return unref(getCollapsed) ? unref(getMiniWidthNumber) : unref(getMenuWidth);
  44. });
  45. const getMiniWidthNumber = computed(() => {
  46. const { collapsedShowTitle } = unref(getMenuSetting);
  47. return collapsedShowTitle ? SIDE_BAR_SHOW_TIT_MINI_WIDTH : SIDE_BAR_MINI_WIDTH;
  48. });
  49. const getCalcContentWidth = computed(() => {
  50. const width = unref(getIsTopMenu) || !unref(getShowMenu) ? 0 : unref(getRealWidth);
  51. return `calc(100% - ${unref(width)}px)`;
  52. });
  53. // Set menu configuration
  54. function setMenuSetting(menuSetting: Partial<MenuSetting>): void {
  55. appStore.commitProjectConfigState({ menuSetting });
  56. }
  57. function toggleCollapsed() {
  58. setMenuSetting({
  59. collapsed: !unref(getCollapsed),
  60. });
  61. }
  62. return {
  63. setMenuSetting,
  64. toggleCollapsed,
  65. getMenuFixed,
  66. getMenuSetting,
  67. getRealWidth,
  68. getMenuType,
  69. getMenuMode,
  70. getShowMenu,
  71. getCollapsed,
  72. getMiniWidthNumber,
  73. getCalcContentWidth,
  74. getMenuWidth,
  75. getTrigger,
  76. getSplit,
  77. getMenuTheme,
  78. getCanDrag,
  79. getIsHorizontal,
  80. getCollapsedShowTitle,
  81. getIsSidebarType,
  82. getAccordion,
  83. getShowTopMenu,
  84. getShowHeaderTrigger,
  85. getTopMenuAlign,
  86. getMenuHidden,
  87. getIsTopMenu,
  88. getMenuBgColor,
  89. };
  90. }