home copy.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="w-full h-full">
  3. <el-container>
  4. <el-header class="bg-sky-800 leading-10 flex flex-row justify-between">
  5. <div class=" flex flex-row justify-start items-center text-white flex-1">
  6. <div v-for="routerItem in routerList"
  7. :class="`border-b-2 border-transparent hover:border-white p-2 mr-4 multipleyHeader ${activeRouter?.path === routerItem.path ? 'border-white' : ''}`"
  8. :key="routerItem.path">
  9. <div v-if="!routerItem.children" @click="setCurrentRouter(routerItem)">
  10. {{ routerItem.name }}
  11. </div>
  12. <div v-else class="flex justify-center items-center">
  13. <el-dropdown>
  14. <div class="text-white w-full h-full headerText">
  15. {{ routerItem.name }}
  16. <el-icon class="el-icon--right">
  17. <arrow-down />
  18. </el-icon>
  19. </div>
  20. <template #dropdown>
  21. <el-dropdown-menu>
  22. <el-dropdown-item v-for="child in routerItem.children"
  23. :key="child.path"
  24. @click="setCurrentRouter(child)">
  25. {{ child.name }}
  26. </el-dropdown-item>
  27. </el-dropdown-menu>
  28. </template>
  29. </el-dropdown>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="flex flex-row justify-start items-center text-white">
  34. <el-icon :size="26" class="ml-4 cursor-pointer">
  35. <Bell />
  36. </el-icon>
  37. <div>
  38. <img class="w-8 h-8 rounded-full ml-4 cursor-pointer" :src="defaultCover" alt="" @click="logout()">
  39. </div>
  40. <el-icon :size="26" class="ml-4 cursor-pointer">
  41. <Grid />
  42. </el-icon>
  43. </div>
  44. </el-header>
  45. <el-main>
  46. <router-view />
  47. </el-main>
  48. </el-container>
  49. </div>
  50. </template>
  51. <script lang="ts" setup>
  52. import { onMounted, ref } from 'vue';
  53. import { RouteRecordRaw, useRouter } from 'vue-router';
  54. import { useStore } from "@/store"
  55. import defaultCover from "@/assets/defaultCover.png";
  56. const { getRoutersList } = useStore()
  57. const router = useRouter();
  58. const routerList = ref<RouteRecordRaw[]>([]);
  59. const activeRouter = ref<RouteRecordRaw>();
  60. const setCurrentRouter = (item: RouteRecordRaw) => {
  61. activeRouter.value = item;
  62. if (item.children && item.children.length > 0) {
  63. router.push({ path: item.children[0].path });
  64. return
  65. }
  66. router.push({ path: item.path });
  67. };
  68. const logout = () => {
  69. router.push({ path: '/login' });
  70. };
  71. onMounted(() => {
  72. routerList.value = getRoutersList;
  73. activeRouter.value = routerList.value.find((item) => item.path === router.currentRoute.value.path);
  74. console.log("routerList", routerList);
  75. })
  76. </script>
  77. <style scoped lang="scss">
  78. .multipleyHeader {
  79. height: 96%;
  80. display: flex;
  81. align-items: center;
  82. .headerText {
  83. font-size: 16px;
  84. }
  85. }
  86. </style>