index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <!-- 面包屑 -->
  3. <el-breadcrumb class="app-breadcrumb" separator="/">
  4. <transition-group name="breadcrumb">
  5. <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
  6. <span v-if="item.redirect === 'noRedirect' || index == levelList.length - 1" class="no-redirect">{{ item.meta.title }}</span>
  7. <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
  8. </el-breadcrumb-item>
  9. </transition-group>
  10. </el-breadcrumb>
  11. </template>
  12. <script setup>
  13. const route = useRoute();
  14. const router = useRouter();
  15. const levelList = ref([])
  16. function getBreadcrumb() {
  17. let matched = route.matched.filter(item => item.meta && item.meta.title);
  18. const first = matched[0]
  19. if (!first) {
  20. levelList.value = []
  21. return
  22. }
  23. // ===================== 【核心:子系统与总后台各自只显示自己的层级】 =====================
  24. const isSubSystem = route.path.startsWith(first.path);
  25. // ===================== 【核心:彻底隔离子系统 / 总后台】 =====================
  26. if (isSubSystem) {
  27. // 子系统:只保留子系统路由,过滤总后台
  28. levelList.value = matched.filter(item =>
  29. item.meta && item.meta.title && item.meta.breadcrumb !== false && item.path.startsWith(first.path)
  30. )
  31. } else {
  32. // 总后台:过滤掉所有子系统路由
  33. levelList.value = matched.filter(item =>
  34. item.meta && item.meta.title && item.meta.breadcrumb !== false && !item.path.startsWith(first.path)
  35. )
  36. }
  37. }
  38. function handleLink(item) {
  39. const {redirect, path} = item
  40. if (redirect) {
  41. router.push(redirect)
  42. return
  43. }
  44. router.push(path)
  45. }
  46. watchEffect(() => {
  47. if (route.path.startsWith('/redirect/')) {
  48. return
  49. }
  50. getBreadcrumb()
  51. })
  52. getBreadcrumb();
  53. </script>
  54. <style lang='scss' scoped>
  55. .app-breadcrumb.el-breadcrumb {
  56. display: inline-block;
  57. font-size: 14px;
  58. line-height: 50px;
  59. margin-left: 8px;
  60. .no-redirect {
  61. color: #97a8be;
  62. cursor: text;
  63. }
  64. }
  65. </style>