index.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <app-tabs class="app-tabs--primary" :data-list="threeMenus" v-model:data-index="dataIndex" @change="onTabChange">
  3. <template #navbar>
  4. <slot></slot>
  5. </template>
  6. <!-- 三级路由 -->
  7. <router-view v-slot="{ Component, route }">
  8. <component :is="Component" :key="route.fullPath" />
  9. </router-view>
  10. </app-tabs>
  11. </template>
  12. <script lang="ts" setup>
  13. import { shallowRef } from 'vue'
  14. import { useAuth } from '@/hooks/auth'
  15. import { AuthMenu } from '@/hooks/auth/interface'
  16. import AppTabs from '@/components/base/tabs/index.vue'
  17. const { route, router, getChildrenMenus } = useAuth()
  18. const parentRoute = route.matched[route.matched.length - 2] // 父级路由信息
  19. const threeMenus = shallowRef<AuthMenu[]>([]) // 三级菜单
  20. const dataIndex = shallowRef(0) // 选中的标签
  21. if (parentRoute) {
  22. const menus = getChildrenMenus(parentRoute.name?.toString())
  23. const index = menus.findIndex((e) => e.name === route.name)
  24. threeMenus.value = menus
  25. if (index > -1) {
  26. dataIndex.value = index
  27. }
  28. }
  29. // 切换标签
  30. const onTabChange = (index: number, { name }: AuthMenu) => {
  31. router.push({ name })
  32. }
  33. </script>
  34. <style lang="less">
  35. @import './index.less';
  36. </style>