Pre Merge pull request !410 from 璐先生/master

This commit is contained in:
璐先生
2022-03-05 14:12:10 +00:00
committed by Gitee
7 changed files with 851 additions and 850 deletions

View File

@ -92,16 +92,13 @@ export default {
const tmpPath = path.substring(1, path.length); const tmpPath = path.substring(1, path.length);
activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
} else if ("/index" == path || "" == path) { } else if ("/index" == path || "" == path) {
if (!this.isFrist) {
this.isFrist = true; this.isFrist = true;
} else {
activePath = "index";
}
} }
var routes = this.activeRoutes(activePath); var routes = this.activeRoutes(activePath);
if (routes.length === 0) { if (routes.length === 0) {
activePath = this.currentIndex || this.defaultRouter() this.$store.commit("SET_SIDEBAR_MENU_HIDE", true);
this.activeRoutes(activePath); }else {
this.$store.commit("SET_SIDEBAR_MENU_HIDE", false);
} }
return activePath; return activePath;
}, },
@ -142,22 +139,26 @@ export default {
// /redirect 路径内部打开 // /redirect 路径内部打开
this.$router.push({ path: key.replace("/redirect", "") }); this.$router.push({ path: key.replace("/redirect", "") });
} else { } else {
// 显示左侧联动菜单 // 显示左侧联动菜单顶部菜单
this.activeRoutes(key); this.activeRoutes(key,true);
} }
}, },
// 当前激活的路由 // 当前激活的路由
activeRoutes(key) { activeRoutes(key,isTop) {
var routes = []; var routes = [];
if (this.childrenMenus && this.childrenMenus.length > 0) { if (this.childrenMenus && this.childrenMenus.length > 0) {
this.childrenMenus.map((item) => { this.childrenMenus.map((item) => {
if (key == item.parentPath || (key == "index" && "" == item.path)) { if (key == item.parentPath) {
routes.push(item); routes.push(item);
} }
}); });
} }
if(routes.length > 0) { if(routes.length > 0) {
//TODO 第一个默认选中
this.$store.commit("SET_SIDEBAR_ROUTERS", routes); this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
if(isTop){
this.$router.push({path:routes[0].path});
}
} }
return routes; return routes;
}, },

View File

@ -1,5 +1,5 @@
<template> <template>
<div :class="{'has-logo':showLogo}" :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }"> <div v-show="!sidebarMenuHide" :class="{'has-logo':showLogo}" :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }">
<logo v-if="showLogo" :collapse="isCollapse" /> <logo v-if="showLogo" :collapse="isCollapse" />
<el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper"> <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
<el-menu <el-menu
@ -33,7 +33,7 @@ export default {
components: { SidebarItem, Logo }, components: { SidebarItem, Logo },
computed: { computed: {
...mapState(["settings"]), ...mapState(["settings"]),
...mapGetters(["sidebarRouters", "sidebar"]), ...mapGetters(["sidebarRouters", "sidebar","sidebarMenuHide"]),
activeMenu() { activeMenu() {
const route = this.$route; const route = this.$route;
const { meta, path } = route; const { meta, path } = route;

View File

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

View File

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

View File

@ -11,7 +11,8 @@ const permission = {
addRoutes: [], addRoutes: [],
defaultRoutes: [], defaultRoutes: [],
topbarRouters: [], topbarRouters: [],
sidebarRouters: [] sidebarRouters: [],
sidebarMenuHide: false
}, },
mutations: { mutations: {
SET_ROUTES: (state, routes) => { SET_ROUTES: (state, routes) => {
@ -22,15 +23,13 @@ const permission = {
state.defaultRoutes = constantRoutes.concat(routes) state.defaultRoutes = constantRoutes.concat(routes)
}, },
SET_TOPBAR_ROUTES: (state, routes) => { SET_TOPBAR_ROUTES: (state, routes) => {
// 顶部导航菜单默认添加统计报表栏指向首页 state.topbarRouters = routes;
const index = [{
path: 'index',
meta: { title: '统计报表', icon: 'dashboard' }
}]
state.topbarRouters = routes.concat(index);
}, },
SET_SIDEBAR_ROUTERS: (state, routes) => { SET_SIDEBAR_ROUTERS: (state, routes) => {
state.sidebarRouters = routes state.sidebarRouters = routes
}
,SET_SIDEBAR_MENU_HIDE: (state, sidebarMenuHide) => {
state.sidebarMenuHide = sidebarMenuHide
}, },
}, },
actions: { actions: {