|
|
@ -99,10 +99,48 @@ router.beforeEach(async (to, from, next) => {
|
|
|
|
next({ name: childName });
|
|
|
|
next({ name: childName });
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
|
|
|
|
// 面包屑导航算法
|
|
|
|
|
|
|
|
const deep = (tree, condition) => {
|
|
|
|
|
|
|
|
let path = [];
|
|
|
|
|
|
|
|
// 根据路由名称找路由
|
|
|
|
|
|
|
|
let target = tree.find(condition);
|
|
|
|
|
|
|
|
if (target) {
|
|
|
|
|
|
|
|
// 找到了加入路由路径
|
|
|
|
|
|
|
|
path.push(target);
|
|
|
|
|
|
|
|
// 继续从其他同级路由的子级中递归查找
|
|
|
|
|
|
|
|
let tempPath = deep(
|
|
|
|
|
|
|
|
tree.filter((item) => !condition(item)),
|
|
|
|
|
|
|
|
condition
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
if (tempPath.length) {
|
|
|
|
|
|
|
|
// 找到了回退路由路径
|
|
|
|
|
|
|
|
path.pop();
|
|
|
|
|
|
|
|
// 将新路由路径拼接进来
|
|
|
|
|
|
|
|
path.push(...tempPath);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 没有找到,遍历查找这个层级所有元素
|
|
|
|
|
|
|
|
tree.find((item) => {
|
|
|
|
|
|
|
|
// 更新路由路径
|
|
|
|
|
|
|
|
path.push(item);
|
|
|
|
|
|
|
|
// 从子路由中递归查找
|
|
|
|
|
|
|
|
let tempPath = deep(item.children || [], condition);
|
|
|
|
|
|
|
|
if (tempPath.length) {
|
|
|
|
|
|
|
|
// 找到了拼接新路由路径
|
|
|
|
|
|
|
|
path.push(...tempPath);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 没找到回退路由路径
|
|
|
|
|
|
|
|
path.pop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const breakcrumbList = deep(store.state.auth.permission, (item) => item.name === to.name);
|
|
|
|
store.commit('layout/setActiveAside', to.matched[0].name);
|
|
|
|
store.commit('layout/setActiveAside', to.matched[0].name);
|
|
|
|
store.commit('layout/setActiveMenu', to.name);
|
|
|
|
store.commit('layout/setActiveMenu', to.name);
|
|
|
|
store.commit('layout/setActiveTab', to.name);
|
|
|
|
store.commit('layout/setActiveTab', to.name);
|
|
|
|
store.commit('layout/setBreakcrumbList', to.matched);
|
|
|
|
store.commit('layout/setBreakcrumbList', breakcrumbList);
|
|
|
|
store.commit('layout/addTab', to);
|
|
|
|
store.commit('layout/addTab', to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|