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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
<el-breadcrumb separator="/">
<el-breadcrumb-item
:to='item.path'
:key='index'
v-for="(item, index) in breadcrumb"
>
{{item.name}}
</el-breadcrumb-item>
</el-breadcrumb>
</template>
<script>
// 获取多级菜单
const types = {
list: '列表',
add: '新增',
edit: '编辑',
view: '查看',
importView: '导入',
resetPwdView:'重置密码',
};
const findEntity = (list, value, key) => {
let data = {};
list.forEach((item, i)=>{
if(item[key] === value) {
data = item;
return;
}
})
return data;
};
const find = (list, path, arr) => {
// 获取二级菜单
let newList = JSON.parse(JSON.stringify(list));
let data = findEntity(newList, path, 'path');
let parentId = data.parentId;
arr.push(data);
// 获取一级菜单
if(parentId){
let parent = findEntity(newList, parentId, 'id');
arr.unshift(parent);
}
return arr
}
export default {
props: {
list: {
type: Array,
default: () => []
}
},
watch: {
'$route'(route) {
this.query = route.query;
}
},
computed: {
breadcrumb() {
// 如果用户指定面包屑,则使用用户配置
if(this.list.length) {
return this.list;
}
const path = this.$route.path.replace(/\/(list|add|edit|importView|view|resetPwdView)$/, '/list');
const group = find(this.menu, path, []);
let urlArray = this.$route.path.split('/');
const type = urlArray.pop();
if(types[type]) {
group.push({
name: types[type]
})
}
console.log("group",group)
return group
},
menu() {
return this.$store.state.userData.flat || [];
},
},
data() {
return {
}
}
}
</script>
<style lang="less">
.el-breadcrumb{
font-size: 12px;
}
</style>