diff --git a/klp-ui/src/layout/components/Sidebar/SidebarItem.vue b/klp-ui/src/layout/components/Sidebar/SidebarItem.vue index 10813cd04..6c5d4021e 100644 --- a/klp-ui/src/layout/components/Sidebar/SidebarItem.vue +++ b/klp-ui/src/layout/components/Sidebar/SidebarItem.vue @@ -88,17 +88,19 @@ export default { return this.basePath }, subMenuRoute() { - const title = (this.item.meta && this.item.meta.title) || this.item.name || '' - return { - path: '/redirect/subMenu', - query: { - parent: this.basePath, - title: title - } - } + return this.findFirstLeaf(this.item, this.basePath) } }, methods: { + findFirstLeaf(item, basePath) { + const visibleChildren = (item.children || []).filter(c => !c.hidden) + if (visibleChildren.length === 0) { + return basePath + } + const firstChild = visibleChildren[0] + const childPath = path.resolve(basePath, firstChild.path) + return this.findFirstLeaf(firstChild, childPath) + }, hasOneShowingChild(children = [], parent) { if (!children) { children = []; diff --git a/klp-ui/src/layout/components/Sidebar/index.vue b/klp-ui/src/layout/components/Sidebar/index.vue index 39c3db0bf..028256a5b 100644 --- a/klp-ui/src/layout/components/Sidebar/index.vue +++ b/klp-ui/src/layout/components/Sidebar/index.vue @@ -1,40 +1,123 @@ + + + + diff --git a/klp-ui/src/layout/components/SubNav.vue b/klp-ui/src/layout/components/SubNav.vue index 424d4eef3..b18e123fa 100644 --- a/klp-ui/src/layout/components/SubNav.vue +++ b/klp-ui/src/layout/components/SubNav.vue @@ -61,8 +61,16 @@ export default { computed: { subNavItems() { const sidebarRouters = this.$store.state.permission.sidebarRouters - const items = this.getThirdLevelMenus(sidebarRouters) - return items + const activeTop = this.$store.state.permission.activeTopMenu + const topMenus = this.$store.state.permission.topMenuList + const menu = topMenus.find(m => m.path === activeTop) + const basePath = menu ? menu.path : '' + + let currentPath = this.$route.path + if (currentPath === '/redirect/subMenu' && this.$route.query.parent) { + currentPath = this.$route.query.parent + } + return this.findActiveLevel2(sidebarRouters, currentPath, 0, basePath) || [] }, hasItems() { return this.subNavItems.length > 0 @@ -108,13 +116,6 @@ export default { isChildActive(child) { return this.$route.path === child._ownPath || this.$route.path.startsWith(child._ownPath + '/') }, - getThirdLevelMenus(routes) { - let currentPath = this.$route.path - if (currentPath === '/redirect/subMenu' && this.$route.query.parent) { - currentPath = this.$route.query.parent - } - return this.findActiveLevel2(routes, currentPath, 0, '') || [] - }, findActiveLevel2(routes, currentPath, depth, basePath) { for (const route of routes) { if (route.hidden) continue diff --git a/klp-ui/src/store/getters.js b/klp-ui/src/store/getters.js index 1fbd69ec1..3437c1648 100644 --- a/klp-ui/src/store/getters.js +++ b/klp-ui/src/store/getters.js @@ -18,6 +18,8 @@ const getters = { topbarRouters:state => state.permission.topbarRouters, defaultRoutes:state => state.permission.defaultRoutes, sidebarRouters:state => state.permission.sidebarRouters, + topMenuList: state => state.permission.topMenuList, + activeTopMenu: state => state.permission.activeTopMenu, productList: state => state.category.productList, rawMaterialList: state => state.category.rawMaterialList, bomMap: state => state.category.bomMap, diff --git a/klp-ui/src/store/modules/permission.js b/klp-ui/src/store/modules/permission.js index 228766550..5d11f93ae 100644 --- a/klp-ui/src/store/modules/permission.js +++ b/klp-ui/src/store/modules/permission.js @@ -4,6 +4,7 @@ import { getRouters } from '@/api/menu' import Layout from '@/layout/index' import ParentView from '@/components/ParentView' import InnerLink from '@/layout/components/InnerLink' +import Cookies from 'js-cookie' const permission = { state: { @@ -11,7 +12,9 @@ const permission = { addRoutes: [], defaultRoutes: [], topbarRouters: [], - sidebarRouters: [] + sidebarRouters: [], + topMenuList: [], + activeTopMenu: Cookies.get('activeTopMenu') || '' }, mutations: { SET_ROUTES: (state, routes) => { @@ -27,6 +30,13 @@ const permission = { SET_SIDEBAR_ROUTERS: (state, routes) => { state.sidebarRouters = routes }, + SET_TOP_MENU_LIST: (state, menus) => { + state.topMenuList = menus + }, + SET_ACTIVE_TOP_MENU: (state, path) => { + state.activeTopMenu = path + Cookies.set('activeTopMenu', path) + }, }, actions: { // 生成路由 @@ -45,9 +55,19 @@ const permission = { commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes)) commit('SET_DEFAULT_ROUTES', sidebarRoutes) commit('SET_TOPBAR_ROUTES', sidebarRoutes) + commit('SET_TOP_MENU_LIST', sidebarRoutes) resolve(rewriteRoutes) }) }) + }, + + selectTopMenu({ commit, state }, menuPath) { + const menu = state.topMenuList.find(m => m.path === menuPath) + if (menu) { + commit('SET_ACTIVE_TOP_MENU', menuPath) + const children = menu.children ? menu.children.filter(c => !c.hidden) : [] + commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(children)) + } } } } diff --git a/klp-ui/src/views/system/menu/index.vue b/klp-ui/src/views/system/menu/index.vue index 483cc77dd..6c2fe9395 100644 --- a/klp-ui/src/views/system/menu/index.vue +++ b/klp-ui/src/views/system/menu/index.vue @@ -100,6 +100,13 @@ @click="handleAdd(scope.row)" v-hasPermi="['system:menu:add']" >新增 + 复制新增