| | |
| | | <!-- 顶部导航封装 --> |
| | | <template> |
| | | <el-menu |
| | | :default-active="activeMenu" |
| | |
| | | @select="handleSelect" |
| | | > |
| | | <template v-for="(item, index) in topMenus"> |
| | | <el-menu-item :style="{'--theme': theme}" :index="item.path" :key="index" v-if="index < visibleNumber" |
| | | <el-menu-item |
| | | :style="{ '--theme': theme }" |
| | | :index="item.path" |
| | | :key="index" |
| | | v-if="index < visibleNumber" |
| | | ><svg-icon :icon-class="item.meta.icon" /> |
| | | {{ item.meta.title }}</el-menu-item |
| | | > |
| | | </template> |
| | | |
| | | <!-- 顶部菜单超出数量折叠 --> |
| | | <el-submenu :style="{'--theme': theme}" index="more" v-if="topMenus.length > visibleNumber"> |
| | | <el-submenu |
| | | :style="{ '--theme': theme }" |
| | | index="more" |
| | | v-if="topMenus.length > visibleNumber" |
| | | > |
| | | <template slot="title">更多菜单</template> |
| | | <template v-for="(item, index) in topMenus"> |
| | | <el-menu-item |
| | |
| | | import { constantRoutes } from "@/router"; |
| | | |
| | | // 隐藏侧边栏路由 |
| | | const hideList = ['/index', '/user/profile']; |
| | | const hideList = ["/index", "/user/profile"]; |
| | | |
| | | export default { |
| | | data() { |
| | |
| | | // 顶部栏初始数 |
| | | visibleNumber: 5, |
| | | // 当前激活菜单的 index |
| | | currentIndex: undefined |
| | | currentIndex: undefined, |
| | | }; |
| | | }, |
| | | computed: { |
| | |
| | | router.children[item].path = "/" + router.children[item].path; |
| | | } else { |
| | | if(!this.ishttp(router.children[item].path)) { |
| | | router.children[item].path = router.path + "/" + router.children[item].path; |
| | | router.children[item].path = |
| | | router.path + "/" + router.children[item].path; |
| | | } |
| | | } |
| | | router.children[item].parentPath = router.path; |
| | |
| | | activeMenu() { |
| | | const path = this.$route.path; |
| | | let activePath = path; |
| | | if (path !== undefined && path.lastIndexOf("/") > 0 && hideList.indexOf(path) === -1) { |
| | | if ( |
| | | path !== undefined && |
| | | path.lastIndexOf("/") > 0 && |
| | | hideList.indexOf(path) === -1 |
| | | ) { |
| | | const tmpPath = path.substring(1, path.length); |
| | | activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); |
| | | if (!this.$route.meta.link) { |
| | | this.$store.dispatch('app/toggleSideBarHide', false); |
| | | this.$store.dispatch("app/toggleSideBarHide", false); |
| | | } |
| | | } else if(!this.$route.children) { |
| | | activePath = path; |
| | | this.$store.dispatch('app/toggleSideBarHide', true); |
| | | this.$store.dispatch("app/toggleSideBarHide", true); |
| | | } |
| | | this.activeRoutes(activePath); |
| | | return activePath; |
| | | }, |
| | | }, |
| | | beforeMount() { |
| | | window.addEventListener('resize', this.setVisibleNumber) |
| | | window.addEventListener("resize", this.setVisibleNumber); |
| | | }, |
| | | beforeDestroy() { |
| | | window.removeEventListener('resize', this.setVisibleNumber) |
| | | window.removeEventListener("resize", this.setVisibleNumber); |
| | | }, |
| | | mounted() { |
| | | this.setVisibleNumber(); |
| | |
| | | // 菜单选择事件 |
| | | handleSelect(key, keyPath) { |
| | | this.currentIndex = key; |
| | | const route = this.routers.find(item => item.path === key); |
| | | const route = this.routers.find((item) => item.path === key); |
| | | if (this.ishttp(key)) { |
| | | // http(s):// 路径新窗口打开 |
| | | window.open(key, "_blank"); |
| | | } else if (!route || !route.children) { |
| | | // 没有子路由路径内部打开 |
| | | this.$router.push({ path: key }); |
| | | this.$store.dispatch('app/toggleSideBarHide', true); |
| | | this.$store.dispatch("app/toggleSideBarHide", true); |
| | | } else { |
| | | // 显示左侧联动菜单 |
| | | this.activeRoutes(key); |
| | | this.$store.dispatch('app/toggleSideBarHide', false); |
| | | this.$store.dispatch("app/toggleSideBarHide", false); |
| | | } |
| | | }, |
| | | // 当前激活的路由 |
| | |
| | | if(routes.length > 0) { |
| | | this.$store.commit("SET_SIDEBAR_ROUTERS", routes); |
| | | } else { |
| | | this.$store.dispatch('app/toggleSideBarHide', true); |
| | | this.$store.dispatch("app/toggleSideBarHide", true); |
| | | } |
| | | }, |
| | | ishttp(url) { |
| | | return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1 |
| | | } |
| | | return url.indexOf("http://") !== -1 || url.indexOf("https://") !== -1; |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | |
| | | margin: 0 10px !important; |
| | | } |
| | | |
| | | .topmenu-container.el-menu--horizontal > .el-menu-item.is-active, .el-menu--horizontal > .el-submenu.is-active .el-submenu__title { |
| | | border-bottom: 2px solid #{'var(--theme)'} !important; |
| | | .topmenu-container.el-menu--horizontal > .el-menu-item.is-active, |
| | | .el-menu--horizontal > .el-submenu.is-active .el-submenu__title { |
| | | border-bottom: 2px solid #{"var(--theme)"} !important; |
| | | color: #303133; |
| | | } |
| | | |