Commit 360dbb0b authored by sheng du's avatar sheng du
Browse files

未登录判断

parent 00fc4c57
No related merge requests found
Pipeline #804 failed with stages
......@@ -30,11 +30,11 @@ export default {
computed: {
paths() {
const matched = this.$route.matched.filter(
(item) => item.meta && item.meta.title
(item) => item?.meta && item?.meta.title
);
this.changeRouter(matched);
// console.log(matched.filter((item) => item.meta && item.meta.title));
return matched.filter((item) => (item.meta ? item.meta.title : ""));
return matched.filter((item) => (item?.meta ? item?.meta.title : ""));
},
pageName() {
return this.$route.matched[this.$route.matched.length - 1]?.meta?.title;
......@@ -53,16 +53,16 @@ export default {
if (matched.length > 1) {
matched = [matched[matched.length - 1]];
}
if (matched[0].meta.disTab) {
if (matched[0]?.meta.disTab) {
return;
}
//从左侧导航打开页面时添加在头部导航,没有则只定位
let paths = this.pathList.map((item) => item.path);
if (paths.includes(matched[0].path)) {
this.activeName = matched[0].path;
let paths = this.pathList.map((item) => item?.path);
if (paths.includes(matched[0]?.path)) {
this.activeName = matched[0]?.path;
} else {
this.pathList = [...this.pathList, ...matched];
this.activeName = matched[0].path;
this.activeName = matched[0]?.path;
}
// this.pathList = [...this.pathList, ...matched];
// console.log(this.pathList);
......@@ -75,17 +75,17 @@ export default {
return;
}
//删除缓存页面
let findItem = this.pathList.find((item) => item.path == targetName);
let findItem = this.pathList.find((item) => item?.path == targetName);
// console.log(findItem);
this.$store.dispatch("app/removeCacheRoutes", findItem.name);
if (findItem.parent) {
this.$store.dispatch("app/removeCacheRoutes", findItem.parent.name);
}
//从列表去掉
this.pathList = this.pathList.filter((item) => item.path != targetName);
this.pathList = this.pathList.filter((item) => item?.path != targetName);
if (this.$route.path == targetName) {
//关闭当前页面跳转到最后一个页面
this.$router.replace(this.pathList[this.pathList.length - 1].path);
this.$router.replace(this.pathList[this.pathList.length - 1]?.path);
// this.activeName = matched[0].path;
}
}
......
......@@ -27,7 +27,7 @@ export default {
console.log(allMenu);
// let findFatherItem = allMenu;
return allMenu;
return allMenu || [];
// let findFatherItem = allMenu.find(
// (item) => item.name == this.mainMenuName
// );
......@@ -70,7 +70,7 @@ export default {
res = res.filter(
(item) => !item.meta.hidden && this.userAuth.includes(item.name)
);
return res.length ? res : null;
return res?.length ? res : null;
},
routeTo(indexs) {
let path = "";
......
......@@ -76,6 +76,7 @@ const routes = [
},
{
path: "/login",
name:'login',
component: () =>
import(/* webpackChunkName: "accout" */ "@/views/login.vue"),
// redirect: "/index"
......@@ -97,11 +98,19 @@ const router = new VueRouter({
});
router.beforeEach((to, from, next) => {
// console.log(to, from);
let userAuth = store.state.user.userAuth;
console.log(to, userAuth);
if (to.meta.keepAlive) {
store.dispatch("app/addCacheRoutes", to.name);
}
next();
if (
(userAuth && userAuth.includes(to.matched[0]?.name)) ||
["login"].includes(to.matched[0]?.name)
) {
next();
} else {
router.replace("/login");
}
});
router.addRoutes(asyncRoutes);
......
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