1.把目录“首页”放在第一个菜单位置

2.有二级菜单,例如点击系统管理时 默认选中第一个子菜单--用户管理
3.没有二级菜单,左侧二级不显示,比如首页或以后新增目录
4.新建一个目录,下面没有子菜单,出不来对应的页面
This commit is contained in:
LILU
2022-01-11 22:38:52 +08:00
parent 869dcf73f8
commit a3b59a2b9f
6 changed files with 799 additions and 785 deletions

View File

@ -142,12 +142,12 @@ export default {
// /redirect 路径内部打开
this.$router.push({ path: key.replace("/redirect", "") });
} else {
// 显示左侧联动菜单
this.activeRoutes(key);
// 显示左侧联动菜单顶部菜单
this.activeRoutes(key,true);
}
},
// 当前激活的路由
activeRoutes(key) {
activeRoutes(key,isTop) {
var routes = [];
if (this.childrenMenus && this.childrenMenus.length > 0) {
this.childrenMenus.map((item) => {
@ -157,7 +157,13 @@ export default {
});
}
if(routes.length > 0) {
//TODO 第一个默认选中
this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
if(isTop){
this.$store.commit("SET_SIDEBAR_ACTIVE_MENU", routes[0].path);
let that = this;
that.$router.push({path:routes[0].path});
}
}
return routes;
},

View File

@ -132,6 +132,7 @@ export default {
addTags() {
const { name } = this.$route
if (name) {
this.$store.commit("SET_SIDEBAR_ACTIVE_MENU", this.$route.path);
this.$store.dispatch('tagsView/addView', this.$route)
}
return false
@ -190,6 +191,7 @@ export default {
})
},
toLastView(visitedViews, view) {
console.log("打开了2")
const latestView = visitedViews.slice(-1)[0]
if (latestView) {
this.$router.push(latestView.fullPath)
@ -205,6 +207,7 @@ export default {
}
},
openMenu(tag, e) {
console.log("打开了3",tag,e)
const menuMinWidth = 105
const offsetLeft = this.$el.getBoundingClientRect().left // container margin left
const offsetWidth = this.$el.offsetWidth // container width

View File

@ -12,7 +12,7 @@ module.exports = {
/**
* 是否显示顶部导航
*/
topNav: false,
topNav: true,
/**
* 是否显示 tagsView

View File

@ -14,5 +14,6 @@ const getters = {
topbarRouters:state => state.permission.topbarRouters,
defaultRoutes:state => state.permission.defaultRoutes,
sidebarRouters:state => state.permission.sidebarRouters,
sidebarActiveMenu:state => state.permission.sidebarActiveMenu,
}
export default getters

View File

@ -11,7 +11,8 @@ const permission = {
addRoutes: [],
defaultRoutes: [],
topbarRouters: [],
sidebarRouters: []
sidebarRouters: [],
sidebarActiveMenu: null
},
mutations: {
SET_ROUTES: (state, routes) => {
@ -31,6 +32,9 @@ const permission = {
},
SET_SIDEBAR_ROUTERS: (state, routes) => {
state.sidebarRouters = routes
}
,SET_SIDEBAR_ACTIVE_MENU: (state, sidebarActiveMenu) => {
state.sidebarActiveMenu = sidebarActiveMenu
},
},
actions: {