index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!-- 分栏布局 -->
  2. <template>
  3. <el-container class="layout-wrap--columns">
  4. <div class="aside-split">
  5. <div class="logo">
  6. <!-- <img class="logo-img" src="@/assets/images/logo.svg" alt="logo" />-->
  7. <!-- <SvgIcon class="logo-img sidebar-logo" icon-class="logo" />-->
  8. <img class="logo-img" src="@/assets/icons/logo.svg" alt="logo" />
  9. </div>
  10. <el-scrollbar>
  11. <div class="split-list">
  12. <div
  13. v-for="item in menuList"
  14. :key="item.path"
  15. class="split-item"
  16. :class="{ 'split-active': splitActive === item.path || `/${splitActive.split('/')[1]}` === item.path }"
  17. @click="changeSubMenu(item)"
  18. >
  19. <MenuIcon v-if="item.meta?.icon" :icon-class="item.meta.icon"></MenuIcon>
  20. <!-- <el-icon>
  21. <component :is="item.meta.icon"></component>
  22. </el-icon>-->
  23. <span class="title">{{ generateTitle(item.meta.title) }}</span>
  24. </div>
  25. </div>
  26. </el-scrollbar>
  27. </div>
  28. <el-aside :class="{ 'not-aside': !subMenuList.length }" :style="{ width: isCollapse ? '65px' : '210px' }">
  29. <div class="logo">
  30. <span v-show="subMenuList.length" class="text-overflow_ellipsis logo-text" :title="title">{{ title }}</span>
  31. </div>
  32. <el-scrollbar>
  33. <el-menu class="layout-menu-wrap" :router="false" :default-active="activeMenu" :collapse="isCollapse" :unique-opened="accordion" :collapse-transition="false">
  34. <SubMenu :menu-list="subMenuList" />
  35. </el-menu>
  36. </el-scrollbar>
  37. </el-aside>
  38. <el-container>
  39. <el-header>
  40. <ToolBarLeft />
  41. <ToolBarRight />
  42. </el-header>
  43. <AppMain />
  44. </el-container>
  45. </el-container>
  46. </template>
  47. <script setup lang="ts" name="layoutColumns">
  48. import { ref, computed, watch } from 'vue'
  49. import { useRoute, useRouter } from 'vue-router'
  50. // import { useAuthStore } from '@/stores/modules/auth'
  51. // import { useGlobalStore } from '@/stores/modules/global'
  52. // import Main from '@/layouts/components/Main/index.vue'
  53. import AppMain from '@/layout/components/AppMain.vue'
  54. import ToolBarLeft from '@/layout/components/Header/ToolBarLeft.vue'
  55. import ToolBarRight from '@/layout/components/Header/ToolBarRight.vue'
  56. import SubMenu from '@/layout/components/Menu/SubMenu.vue'
  57. import MenuIcon from '@/layout/components/Menu/MenuIcon.vue'
  58. import useStore from '@/store'
  59. import { generateTitle } from '@/utils/i18n'
  60. const title = import.meta.env.VITE_APP_TITLE
  61. const route = useRoute()
  62. const router = useRouter()
  63. const { permission, setting, app } = useStore()
  64. // const authStore = useAuthStore()
  65. // const globalStore = useGlobalStore()
  66. // const accordion = computed(() => globalStore.accordion)
  67. // const isCollapse = computed(() => globalStore.isCollapse)
  68. // const menuList = computed(() => authStore.showMenuListGet)
  69. const accordion = computed(() => setting.accordion || false) // todo...
  70. const isCollapse = computed(() => setting.isCollapse)
  71. const menuList = computed(() => permission.showMenuList)
  72. const activeMenu = computed(() => (route.meta.activeMenu ? route.meta.activeMenu : route.path) as string)
  73. const subMenuList = ref<Menu.MenuOptions[]>([])
  74. const splitActive = ref('')
  75. watch(
  76. () => [menuList, route],
  77. () => {
  78. // 当前菜单没有数据直接 return
  79. if (!menuList.value.length) return
  80. splitActive.value = route.path
  81. const menuItem = menuList.value.filter((item: Menu.MenuOptions) => {
  82. return route.path === item.path || `/${route.path.split('/')[1]}` === item.path
  83. // const pathArr = route.path.split('/')
  84. // const childPath = pathArr.length > 1 ? `/${pathArr[1]}` : pathArr[0]
  85. // return route.path === item.path || childPath === item.path
  86. })
  87. if (menuItem[0]?.children?.length) return (subMenuList.value = menuItem[0].children)
  88. subMenuList.value = []
  89. },
  90. {
  91. deep: true,
  92. immediate: true
  93. }
  94. )
  95. // change SubMenu
  96. const changeSubMenu = (item: Menu.MenuOptions) => {
  97. splitActive.value = item.path
  98. if (item.children?.length) return (subMenuList.value = item.children)
  99. subMenuList.value = []
  100. router.push(item.path)
  101. }
  102. </script>
  103. <style lang="scss">
  104. @import './index.scss';
  105. </style>