fe-drone-ci/src/components/Breadcrumb/index.vue

74 lines
1.9 KiB
Vue
Raw Normal View History

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">
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path">
2019-03-17 09:40:51 +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'
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()
}
},
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() {
let matched = this.$route.matched.filter(item => item.name)
2017-08-22 07:43:34 +00:00
const first = matched[0]
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
}
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
2017-04-18 07:09:13 +00:00
<style rel="stylesheet/scss" lang="scss" scoped>
2017-11-24 06:34:19 +00:00
.app-breadcrumb.el-breadcrumb {
2017-07-06 09:56:17 +00:00
display: inline-block;
font-size: 14px;
line-height: 50px;
2019-02-11 09:42:31 +00:00
margin-left: 8px;
2017-07-06 09:56:17 +00:00
.no-redirect {
color: #97a8be;
cursor: text;
2017-04-18 07:09:13 +00:00
}
2017-07-06 09:56:17 +00:00
}
2017-04-18 07:09:13 +00:00
</style>