2017-04-18 07:09:13 +00:00
|
|
|
<template>
|
2017-11-24 06:34:19 +00:00
|
|
|
<el-breadcrumb class="app-breadcrumb" separator="/">
|
|
|
|
<transition-group name="breadcrumb">
|
2019-01-15 08:36:03 +00:00
|
|
|
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
|
2019-04-01 09:07:16 +00:00
|
|
|
<span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{
|
|
|
|
generateTitle(item.meta.title) }}</span>
|
2018-11-09 09:59:34 +00:00
|
|
|
<a v-else @click.prevent="handleLink(item)">{{ generateTitle(item.meta.title) }}</a>
|
2017-11-24 06:34:19 +00:00
|
|
|
</el-breadcrumb-item>
|
|
|
|
</transition-group>
|
2017-04-18 07:09:13 +00:00
|
|
|
</el-breadcrumb>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2017-12-06 06:18:28 +00:00
|
|
|
import { generateTitle } from '@/utils/i18n'
|
2018-09-30 05:45:38 +00:00
|
|
|
import pathToRegexp from 'path-to-regexp'
|
2017-12-06 06:18:28 +00:00
|
|
|
|
2017-08-22 07:43:34 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
levelList: null
|
|
|
|
}
|
|
|
|
},
|
2017-11-27 02:46:08 +00:00
|
|
|
watch: {
|
|
|
|
$route() {
|
|
|
|
this.getBreadcrumb()
|
|
|
|
}
|
|
|
|
},
|
2018-08-19 08:55:24 +00:00
|
|
|
created() {
|
|
|
|
this.getBreadcrumb()
|
|
|
|
},
|
2017-08-22 07:43:34 +00:00
|
|
|
methods: {
|
2017-12-06 06:18:28 +00:00
|
|
|
generateTitle,
|
2017-08-22 07:43:34 +00:00
|
|
|
getBreadcrumb() {
|
2019-01-15 08:36:03 +00:00
|
|
|
let matched = this.$route.matched.filter(item => item.name)
|
|
|
|
|
2017-08-22 07:43:34 +00:00
|
|
|
const first = matched[0]
|
2018-08-19 08:55:24 +00:00
|
|
|
if (first && first.name.trim().toLocaleLowerCase() !== 'Dashboard'.toLocaleLowerCase()) {
|
2017-11-24 07:35:38 +00:00
|
|
|
matched = [{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched)
|
2017-04-18 07:09:13 +00:00
|
|
|
}
|
2019-01-15 08:36:03 +00:00
|
|
|
|
|
|
|
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
|
2018-11-09 05:37:23 +00:00
|
|
|
},
|
|
|
|
pathCompile(path) {
|
|
|
|
// To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
|
|
|
|
const { params } = this.$route
|
|
|
|
var toPath = pathToRegexp.compile(path)
|
|
|
|
return toPath(params)
|
2018-11-09 09:59:34 +00:00
|
|
|
},
|
|
|
|
handleLink(item) {
|
|
|
|
const { redirect, path } = item
|
|
|
|
if (redirect) {
|
|
|
|
this.$router.push(redirect)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.$router.push(this.pathCompile(path))
|
2017-08-22 07:43:34 +00:00
|
|
|
}
|
2017-07-06 09:56:17 +00:00
|
|
|
}
|
2017-08-22 07:43:34 +00:00
|
|
|
}
|
2017-04-18 07:09:13 +00:00
|
|
|
</script>
|
2017-06-14 10:02:12 +00:00
|
|
|
|
2019-04-01 09:07:16 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.app-breadcrumb.el-breadcrumb {
|
|
|
|
display: inline-block;
|
|
|
|
font-size: 14px;
|
|
|
|
line-height: 50px;
|
|
|
|
margin-left: 8px;
|
|
|
|
|
|
|
|
.no-redirect {
|
|
|
|
color: #97a8be;
|
|
|
|
cursor: text;
|
2017-07-06 09:56:17 +00:00
|
|
|
}
|
2019-04-01 09:07:16 +00:00
|
|
|
}
|
2017-04-18 07:09:13 +00:00
|
|
|
</style>
|