Commit 841dd0d2 authored by jiaxu.yan's avatar jiaxu.yan

Merge branch 'develop' of http://gitlab.91isoft.com:90/car-test/web into develop

parents bb2cab8e 8d869221
...@@ -36,19 +36,34 @@ export default { ...@@ -36,19 +36,34 @@ export default {
}, },
methods: { methods: {
getBreadcrumb() { getBreadcrumb() {
// only show routes with meta.title // // only show routes with meta.title
let matched = this.$route.matched.filter( let matched = this.$route.matched.filter(
item => item.meta && item.meta.title item => item.meta && item.meta.title
) )
const first = matched[0] const first = matched[0]
if (!this.isDashboard(first)) { if (!this.isDashboard(first)) {
matched = [{ path: '/index', meta: { title: '首页' } }].concat(matched) matched = [{ path: '/index', meta: { title: '首页' } }].concat(matched)
} }
const temp = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
this.levelList = matched.filter( // 为三级面包屑提供逻辑 从$route parentName取值
item => item.meta && item.meta.title && item.meta.breadcrumb !== false if (this.$route.meta.secondaryMenuName) {
) temp.splice(-1, 0, { redirect: 'noRedirect', meta: { title: this.$route.meta.secondaryMenuName }, path: 'secondaryMenuName' })
}
this.levelList = this.removeDuplicateTitles(temp)
},
// 去除同名title的面包屑
removeDuplicateTitles(arr) {
const titles = new Set() // 用于存储已经遇到的title值
const result = [] // 存储最终的结果数组
for (let i = 0; i < arr.length; i++) {
const title = arr[i].meta.title
console.log('面包屑', title)
if (!titles.has(title)) {
titles.add(title)
result.push(arr[i])
}
}
return result
}, },
isDashboard(route) { isDashboard(route) {
const name = route && route.name const name = route && route.name
......
...@@ -37,14 +37,22 @@ const permission = { ...@@ -37,14 +37,22 @@ const permission = {
const sdata = JSON.parse(JSON.stringify(res.data)) const sdata = JSON.parse(JSON.stringify(res.data))
const rdata = JSON.parse(JSON.stringify(res.data)) const rdata = JSON.parse(JSON.stringify(res.data))
const sidebarRoutes = filterAsyncRouter(sdata) const sidebarRoutes = filterAsyncRouter(sdata)
sidebarRoutes.forEach(item => {
if (item.children && item.children.length > 0){
item.children.forEach(c => {
c.meta['activeMenu'] = `${item.path === '/' ? '' : item.path}/${item.children[0].path}`
})
}
})
const rewriteRoutes = filterAsyncRouter(rdata, false, true) const rewriteRoutes = filterAsyncRouter(rdata, false, true)
console.log('rewriteRoutes', rewriteRoutes)
rewriteRoutes.forEach(item => { rewriteRoutes.forEach(item => {
if (item.children && item.children.length > 0){ if (item.children && item.children.length > 0){
for (let i = 0; i < item.children.length; i++) { for (let i = 0; i < item.children.length; i++) {
// 将parentName字段放入meta中 // 将parentName字段放入meta中
if (item.children[i].secondaryMenuName) { if (item.children[i].secondaryMenuName) {
item.children[i].meta['secondaryMenuName'] = item.children[i].secondaryMenuName item.children[i].meta['secondaryMenuName'] = item.children[i].secondaryMenuName
// item.children[i - 1].meta['activeMenu'] = `${item.path === '/' ? '' : item.path}/${item.children[i].path}` item.children[i].meta['activeMenu'] = `${item.path === '/' ? '' : item.path}/${item.children[i + 1].path}`
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment