index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div class="top-menu-row" v-if="routeData.length">
  3. <span v-for="(item,index) in routeData" :key="index" :class="['s-span',{'active-span':currentPath === item.path}]">
  4. <el-button :icon="item.icon" @click="router.push(item.path)">
  5. {{ item.title }}
  6. </el-button>
  7. </span>
  8. </div>
  9. </template>
  10. <script setup lang="ts">
  11. import {menuData} from "./menu"
  12. import {useRoute, useRouter} from "vue-router"
  13. import {onMounted, watch} from "vue";
  14. const router = useRouter()
  15. const route = useRoute()
  16. const routeData = ref([])
  17. const currentPath = ref("")
  18. const findMatchingArray = (path) => {
  19. currentPath.value = path
  20. return menuData.find(group =>
  21. group.some(item => item.path === path || item.path.endsWith(path))
  22. ) || [];
  23. }
  24. watch(() => route.path, (value) => {
  25. routeData.value = findMatchingArray(value)
  26. })
  27. onMounted(() => {
  28. routeData.value = findMatchingArray(route.path)
  29. })
  30. </script>
  31. <style scoped lang="scss">
  32. .top-menu-row {
  33. border-bottom: 1px solid rgba($color: #e6e6e6, $alpha: .6);
  34. background: rgba($color: #f9f9f9, $alpha: .3);
  35. display: flex;
  36. align-items: flex-start;
  37. padding-left: 20px;
  38. margin-bottom: 5px;
  39. box-shadow: 0 1px 2px 0 rgba($color: #000000, $alpha: .05);
  40. .s-span {
  41. margin-right: 30px;
  42. .el-button--default {
  43. background: none;
  44. border: 0;
  45. padding: 0;
  46. }
  47. padding: 4px 0;
  48. }
  49. .active-span {
  50. border-bottom: 3px solid #409eff;
  51. margin-bottom: -1px;
  52. .el-button--default {
  53. color: #409eff;
  54. font-weight: bold;
  55. }
  56. }
  57. }
  58. </style>