index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 { closeWebsocket } from "@/utils/websocket";
  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. // 这里时为了面包屑再作业执行-作业状态离开之后关闭那个页面的websocket
  26. if (route.name !== '作业执行-作业状态') {
  27. closeWebsocket();
  28. }
  29. this.getBreadcrumb()
  30. }
  31. },
  32. created() {
  33. this.getBreadcrumb()
  34. },
  35. beforeRouteEnter(to, from, next) {
  36. if (to.query.ticketId !== "null" && to.query.ticketId) {
  37. to.meta.title = "作业管理-编辑作业票"; // 动态修改标题
  38. } else {
  39. to.meta.title = "作业管理-新建作业票"; // 动态修改标题
  40. }
  41. next();
  42. },
  43. methods: {
  44. getBreadcrumb() {
  45. // only show routes with meta.title
  46. let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
  47. const first = matched[0]
  48. if (!this.isDashboard(first)) {
  49. matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
  50. }
  51. this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
  52. },
  53. isDashboard(route) {
  54. const name = route && route.name
  55. if (!name) {
  56. return false
  57. }
  58. return name.trim() === 'Index'
  59. },
  60. handleLink(item) {
  61. const { redirect, path } = item
  62. if (redirect) {
  63. this.$router.push(redirect)
  64. return
  65. }
  66. this.$router.push(path)
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .app-breadcrumb.el-breadcrumb {
  73. display: inline-block;
  74. font-size: 14px;
  75. line-height: 50px;
  76. margin-left: 8px;
  77. .no-redirect {
  78. color: #97a8be;
  79. cursor: text;
  80. }
  81. }
  82. </style>