index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <el-scrollbar class="vab-side-bar" :class="{ 'is-collapse': collapse }">
  3. <vab-logo v-if="layout === 'comprehensive' || layout === 'vertical'" class="fixed-logo" />
  4. <el-menu
  5. background-color="var(--el-menu-background-color)"
  6. :collapse="collapse"
  7. :collapse-transition="false"
  8. :default-active="activeMenu.data"
  9. :default-openeds="defaultOpeneds"
  10. menu-trigger="click"
  11. mode="vertical"
  12. text-color="var(--el-menu-color-text)"
  13. :unique-opened="uniqueOpened"
  14. >
  15. <vab-menu v-for="(item, index) in handleRoutes" :key="index + item.name" :item="item" />
  16. </el-menu>
  17. </el-scrollbar>
  18. </template>
  19. <script lang="ts" setup>
  20. import { defaultOpeneds, uniqueOpened } from '/@/config'
  21. import { useRoutesStore } from '/@/store/modules/routes'
  22. import { useSettingsStore } from '/@/store/modules/settings'
  23. defineOptions({
  24. name: 'VabSideBar',
  25. })
  26. const props = defineProps({
  27. layout: {
  28. type: String,
  29. default: 'vertical',
  30. },
  31. })
  32. const settingsStore = useSettingsStore()
  33. const { collapse } = storeToRefs(settingsStore)
  34. const routesStore = useRoutesStore()
  35. const { getRoutes: routes, getActiveMenu: activeMenu, getPartialRoutes: partialRoutes } = storeToRefs(routesStore)
  36. const handleRoutes = computed(() =>
  37. props.layout === 'comprehensive'
  38. ? partialRoutes.value
  39. : routes.value.flatMap((route: any) => (route.meta.levelHidden && route.children ? [...route.children] : route))
  40. )
  41. </script>
  42. <style lang="scss" scoped>
  43. @mixin active {
  44. &:hover {
  45. color: var(--el-color-white);
  46. background-color: var(--el-color-primary);
  47. }
  48. &.is-active {
  49. color: var(--el-color-white);
  50. background-color: var(--el-color-primary);
  51. }
  52. }
  53. .vab-side-bar {
  54. position: fixed;
  55. top: 0;
  56. bottom: 0;
  57. left: 0;
  58. width: var(--el-left-menu-width);
  59. overflow: hidden;
  60. background: var(--el-menu-background-color);
  61. transition: var(--el-transition);
  62. .fixed-logo {
  63. position: absolute;
  64. top: 0;
  65. left: 0;
  66. z-index: var(--el-z-index);
  67. width: 100%;
  68. height: var(--el-header-height);
  69. background: var(--el-menu-background-color);
  70. }
  71. &.is-collapse {
  72. z-index: calc(var(--el-z-index) + 1);
  73. width: var(--el-left-menu-width-min);
  74. border-right: 0;
  75. :deep() {
  76. .el-menu {
  77. border-right: 0 !important;
  78. }
  79. .el-menu--collapse.el-menu {
  80. > .el-menu-item,
  81. > .el-sub-menu .el-sub-menu__title {
  82. justify-content: center;
  83. height: calc(var(--el-menu-item-height) - 6px);
  84. padding: 0;
  85. line-height: calc(var(--el-menu-item-height) - 6px);
  86. text-align: center;
  87. [class*='ri'] {
  88. display: block;
  89. padding: 0 !important;
  90. margin: 0 !important;
  91. }
  92. .el-tag {
  93. display: none;
  94. }
  95. }
  96. }
  97. .el-menu-item,
  98. .el-sub-menu {
  99. text-align: left;
  100. }
  101. .el-menu--collapse {
  102. border-right: 0;
  103. .el-sub-menu__icon-arrow {
  104. right: 10px;
  105. margin-top: -3px;
  106. }
  107. }
  108. }
  109. }
  110. :deep() {
  111. .el-menu.el-menu--vertical {
  112. margin-top: var(--el-header-height);
  113. }
  114. .el-scrollbar__wrap {
  115. overflow-x: hidden;
  116. }
  117. .el-menu-item,
  118. .el-sub-menu__title {
  119. height: var(--el-menu-item-height);
  120. margin: 0 10px 5px 10px;
  121. overflow: hidden;
  122. line-height: var(--el-menu-item-height);
  123. text-overflow: ellipsis;
  124. white-space: nowrap;
  125. border-radius: var(--el-border-radius-base);
  126. @include active;
  127. }
  128. }
  129. }
  130. </style>
  131. <style lang="scss">
  132. .el-menu {
  133. border-right: 0;
  134. }
  135. .el-menu--popup-right-start {
  136. --el-menu-hover-bg-color: var(--el-color-primary) !important;
  137. --el-menu-active-color: var(--el-color-white) !important;
  138. .is-active {
  139. background: var(--el-color-primary) !important;
  140. }
  141. }
  142. </style>