index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <div class="app-page">
  3. <div class="app-page__sidebar">
  4. <app-sidebar v-model:collapse="isCollapse" />
  5. </div>
  6. <div class="app-page__wrapper">
  7. <div class="app-page__header">
  8. <app-header>
  9. <template #left>
  10. <i class="icon-fold-expand" title="折叠/展开" @click="isCollapse = !isCollapse">
  11. <span :class="isCollapse ? 'g-icon--expand' : 'g-icon--fold'"></span>
  12. </i>
  13. </template>
  14. </app-header>
  15. </div>
  16. <app-tabs class="app-page__tabs" prop-label="title" :data-list="secondMenus" v-model:data-index="dataIndex"
  17. @change="onTabChange">
  18. <div id="appPageTeleport" class="app-page__main app-page__teleport"></div>
  19. <router-view v-slot="{ Component, route }">
  20. <component class="app-page__main" :is="Component" :key="route.fullPath" />
  21. </router-view>
  22. </app-tabs>
  23. <div class="app-page__footer">
  24. <app-footer />
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import { shallowRef, watch } from 'vue'
  31. import { useMenu } from '@/hooks/menu'
  32. import { globalStore } from '@/stores'
  33. import AppTabs from '@/components/base/tabs/index.vue'
  34. import AppHeader from '../header/index.vue'
  35. import AppFooter from '../footer/index.vue'
  36. import AppSidebar from '../sidebar/index.vue'
  37. const { route, router, getChildrenMenus } = useMenu()
  38. const isCollapse = shallowRef(globalStore.state.isMobile)
  39. const secondMenus = shallowRef<Ermcp.UserRoutes[]>([]) // 二级菜单
  40. const dataIndex = shallowRef(-1) // 选中的标签
  41. // 切换标签
  42. const onTabChange = (index: number, { code }: Ermcp.UserRoutes) => {
  43. router.push({ name: code })
  44. }
  45. watch(() => route.matched, (newMatched, oldMatched) => {
  46. const parentRoute = newMatched[newMatched.length - 2] // 父级路由信息
  47. if (parentRoute) {
  48. const old = oldMatched && oldMatched[oldMatched.length - 2]
  49. // 判断当前路由和上个路由是否属于同个父级路由
  50. if (parentRoute.name !== old?.name) {
  51. secondMenus.value = getChildrenMenus(parentRoute.name?.toString())
  52. dataIndex.value = secondMenus.value.findIndex((e) => e.code === route.name)
  53. }
  54. } else {
  55. secondMenus.value = []
  56. dataIndex.value = -1
  57. }
  58. }, {
  59. immediate: true
  60. })
  61. </script>
  62. <style lang="less">
  63. @import './index.less';
  64. </style>