index.vue
2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<style lang="scss" scoped>
</style>
<template>
<el-breadcrumb class="app-breadcrumb" separator="/">
<transition-group name="breadcrumb">
<template>
<el-breadcrumb-item v-for="(item,index) in levelList" :key="item.id">
<span
v-if="item.redirect==='noRedirect'||index===levelList.length-1"
class="no-redirect"
>{{ item.name }}</span>
<a v-else @click.prevent="handleLink(item)">{{ item.name }}</a>
</el-breadcrumb-item>
</template>
</transition-group>
</el-breadcrumb>
</template>
<script>
import pathToRegexp from 'path-to-regexp';
import {getFirstNav} from '@/utils';
export default {
data() {
return {
levelList: null
};
},
watch: {
$route(route) {
// if you go to the redirect page, do not update the breadcrumbs
if (route.path.startsWith('/redirect/')) {
return;
}
this.getBreadcrumb();
}
},
created() {
this.getBreadcrumb();
},
methods: {
getBreadcrumb() {
// only show routes with meta.title
const crumbList = this.$store.state.permission.crumbList;
const matched = [{id: '*', name: '启效', routeUrl: '/'}].concat(crumbList);
this.levelList = matched.filter(
item => item.name
);
},
isDashboard(route) {
const name = route && route.name;
if (!name) {
return false;
}
return (
name.trim().toLocaleLowerCase() === 'Dashboard'.toLocaleLowerCase()
);
},
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);
},
handleLink(item) {
let location = item.routeUrl;
if (!location && item.childList) {
location = getFirstNav(item.childList);
}
if (location) {
this.$router.push(location);
}
}
}
};
</script>