index.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <el-menu class="app-sidemenu" :default-active="activeMenu" unique-opened>
  3. <AppSubmenu :data-list="menus" @click="onMenuClick" />
  4. <!--系统管理,生产环境需隐藏-->
  5. <!-- <el-menu-item index="system" @click="routerTo">
  6. <app-icon class="menu-icon" icon="Setting" />
  7. <span>系统管理</span>
  8. </el-menu-item> -->
  9. </el-menu>
  10. </template>
  11. <script lang="ts" setup>
  12. import { computed } from 'vue'
  13. import { useMenu } from '@/hooks/menu'
  14. import AppIcon from '@pc/components/base/icon/index.vue'
  15. import AppSubmenu from './submenu.vue'
  16. const emit = defineEmits(['click'])
  17. const { route, router, getMenus } = useMenu()
  18. const level = 1 // 菜单层级
  19. const menus = getMenus(level) // 如果是无限级菜单,activeMenu 应该直接返回 route.name
  20. // 高亮菜单
  21. const activeMenu = computed(() => {
  22. return route.matched[level - 1]?.name ?? route.name
  23. })
  24. // 点击菜单
  25. const onMenuClick = (active: string) => {
  26. emit('click', active)
  27. }
  28. // 路由跳转
  29. const routerTo = () => {
  30. router.push({ name: 'system_menu' })
  31. }
  32. </script>