阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.7 KiB

3 years ago
  1. <template>
  2. <el-breadcrumb class="app-breadcrumb" separator="/">
  3. <transition-group name="breadcrumb">
  4. <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
  5. <span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{ item.meta.title }}</span>
  6. <a v-else @click.prevent="handleLink(item)">{{ item.meta.title }}</a>
  7. </el-breadcrumb-item>
  8. </transition-group>
  9. </el-breadcrumb>
  10. </template>
  11. <script>
  12. import pathToRegexp from 'path-to-regexp'
  13. export default {
  14. data() {
  15. return {
  16. levelList: null
  17. }
  18. },
  19. watch: {
  20. $route(route) {
  21. // if you go to the redirect page, do not update the breadcrumbs
  22. if (route.path.startsWith('/redirect/')) {
  23. return
  24. }
  25. this.getBreadcrumb()
  26. }
  27. },
  28. created() {
  29. this.getBreadcrumb()
  30. },
  31. methods: {
  32. getBreadcrumb() {
  33. // only show routes with meta.title
  34. let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
  35. const first = matched[0]
  36. if (!this.isDashboard(first)) {
  37. matched = [{ path: '/dashboard', meta: { title: '首页' }}].concat(matched)
  38. }
  39. this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
  40. },
  41. isDashboard(route) {
  42. const name = route && route.name
  43. if (!name) {
  44. return false
  45. }
  46. return name.trim().toLocaleLowerCase() === 'Dashboard'.toLocaleLowerCase()
  47. },
  48. pathCompile(path) {
  49. // To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
  50. const { params } = this.$route
  51. var toPath = pathToRegexp.compile(path)
  52. return toPath(params)
  53. },
  54. handleLink(item) {
  55. const { redirect, path } = item
  56. if (redirect) {
  57. this.$router.push(redirect)
  58. return
  59. }
  60. this.$router.push(this.pathCompile(path))
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .app-breadcrumb.el-breadcrumb {
  67. position: relative;
  68. flex: 1;
  69. font-size: 14px;
  70. line-height: 50px;
  71. padding-left: 30px;
  72. &::before {
  73. position: absolute;
  74. left: 6px;
  75. top: 50%;
  76. font-family: "iconfont" !important;
  77. font-style: normal;
  78. -webkit-font-smoothing: antialiased;
  79. -moz-osx-font-smoothing: grayscale;
  80. content: "\e60d";
  81. color: #339CFF;
  82. transform: translateY(-50%);
  83. }
  84. .el-breadcrumb__item:last-child{
  85. .el-breadcrumb__inner .no-redirect{
  86. color: #fff;
  87. }
  88. }
  89. ::v-deep .el-breadcrumb__separator{
  90. color: #339CFF;
  91. }
  92. .no-redirect {
  93. color: #339CFF;
  94. cursor: text;
  95. }
  96. }
  97. </style>