fix: 面包屑

fix/0524_ch
向文可 3 years ago
parent 927b446f2b
commit 0d90d9e8a7

@ -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);
} }
} }

@ -104,6 +104,7 @@ const actions = {
returnUrl = returnUrl || router.currentRoute.value.fullPath; returnUrl = returnUrl || router.currentRoute.value.fullPath;
console.info('[logout]', returnUrl); console.info('[logout]', returnUrl);
commit('local/setToken', null, { root: true }); commit('local/setToken', null, { root: true });
commit('auth/setPermission', [], { root: true });
commit('layout/setReturnUrl', returnUrl, { root: true }); commit('layout/setReturnUrl', returnUrl, { root: true });
router.push({ name: 'Login', query: { returnUrl } }); router.push({ name: 'Login', query: { returnUrl } });
}, },

Loading…
Cancel
Save