index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. export default {
  13. data() {
  14. return {
  15. levelList: null
  16. }
  17. },
  18. watch: {
  19. $route(route) {
  20. // if you go to the redirect page, do not update the breadcrumbs
  21. if (route.path.startsWith('/redirect/')) {
  22. return
  23. }
  24. this.getBreadcrumb()
  25. }
  26. },
  27. created() {
  28. this.getBreadcrumb()
  29. },
  30. beforeRouteEnter(to, from, next) {
  31. if (to.query.ticketId !== "null" && to.query.ticketId) {
  32. to.meta.title = "作业管理-编辑作业票"; // 动态修改标题
  33. } else {
  34. to.meta.title = "作业管理-新建作业票"; // 动态修改标题
  35. }
  36. next();
  37. },
  38. methods: {
  39. getBreadcrumb() {
  40. // only show routes with meta.title
  41. let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
  42. const first = matched[0]
  43. if (!this.isDashboard(first)) {
  44. matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
  45. }
  46. this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
  47. },
  48. isDashboard(route) {
  49. const name = route && route.name
  50. if (!name) {
  51. return false
  52. }
  53. return name.trim() === 'Index'
  54. },
  55. handleLink(item) {
  56. const { redirect, path } = item
  57. if (redirect) {
  58. this.$router.push(redirect)
  59. return
  60. }
  61. this.$router.push(path)
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .app-breadcrumb.el-breadcrumb {
  68. display: inline-block;
  69. font-size: 14px;
  70. line-height: 50px;
  71. margin-left: 8px;
  72. .no-redirect {
  73. color: #97a8be;
  74. cursor: text;
  75. }
  76. }
  77. </style>