¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <el-menu |
| | | :default-active="activeMenu" |
| | | mode="horizontal" |
| | | @select="handleSelect" |
| | | > |
| | | <template v-for="(item, index) in topMenus"> |
| | | <el-menu-item :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 index="more" v-if="topMenus.length > visibleNumber"> |
| | | <template slot="title">æ´å¤èå</template> |
| | | <template v-for="(item, index) in topMenus"> |
| | | <el-menu-item |
| | | :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> |
| | | </el-menu> |
| | | </template> |
| | | |
| | | <script> |
| | | import { constantRoutes } from "@/router"; |
| | | |
| | | // ä¸éè¦æ¿æ´»çè·¯ç± |
| | | const noactiveList = ["/user/profile", "/dict/type", "/gen/edit", "/job/log"]; |
| | | |
| | | export default { |
| | | data() { |
| | | return { |
| | | // 顶鍿 åå§æ° |
| | | visibleNumber: 5, |
| | | // æ¯å¦ä¸ºé¦æ¬¡å è½½ |
| | | isFrist: false, |
| | | }; |
| | | }, |
| | | computed: { |
| | | // 顶鍿¾ç¤ºèå |
| | | topMenus() { |
| | | let topMenus = []; |
| | | this.routers.map((menu) => { |
| | | if (menu.hidden !== true) { |
| | | topMenus.push(menu); |
| | | } |
| | | }); |
| | | return topMenus; |
| | | }, |
| | | // ææçè·¯ç±ä¿¡æ¯ |
| | | routers() { |
| | | return this.$store.state.permission.topbarRouters; |
| | | }, |
| | | // 设置åè·¯ç± |
| | | childrenMenus() { |
| | | var childrenMenus = []; |
| | | this.routers.map((router) => { |
| | | for (var item in router.children) { |
| | | if (router.children[item].parentPath === undefined) { |
| | | router.children[item].path = router.path + "/" + router.children[item].path; |
| | | router.children[item].parentPath = router.path; |
| | | } |
| | | childrenMenus.push(router.children[item]); |
| | | } |
| | | }); |
| | | return constantRoutes.concat(childrenMenus); |
| | | }, |
| | | // é»è®¤æ¿æ´»çèå |
| | | activeMenu() { |
| | | const path = this.$route.path; |
| | | let activePath = this.routers[0].path; |
| | | var noactive = noactiveList.some(function (item) { |
| | | return path.indexOf(item) !== -1; |
| | | }); |
| | | if (noactive) { |
| | | return; |
| | | } |
| | | if (path.lastIndexOf("/") > 0) { |
| | | const tmpPath = path.substring(1, path.length); |
| | | activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); |
| | | } else if ("/index" == path || "" == path) { |
| | | if (!this.isFrist) { |
| | | this.isFrist = true; |
| | | } else { |
| | | activePath = "index"; |
| | | } |
| | | } |
| | | this.activeRoutes(activePath); |
| | | return activePath; |
| | | }, |
| | | }, |
| | | beforeMount() { |
| | | window.addEventListener('resize', this.setVisibleNumber) |
| | | }, |
| | | beforeDestroy() { |
| | | window.removeEventListener('resize', this.setVisibleNumber) |
| | | }, |
| | | mounted() { |
| | | this.setVisibleNumber(); |
| | | }, |
| | | methods: { |
| | | // æ ¹æ®å®½åº¦è®¡ç®è®¾ç½®æ¾ç¤ºæ æ° |
| | | setVisibleNumber() { |
| | | const width = document.body.getBoundingClientRect().width / 3; |
| | | this.visibleNumber = parseInt(width / 85); |
| | | }, |
| | | // èåéæ©äºä»¶ |
| | | handleSelect(key, keyPath) { |
| | | if (key.indexOf("http://") !== -1 || key.indexOf("https://") !== -1) { |
| | | // http(s):// è·¯å¾æ°çªå£æå¼ |
| | | window.open(key, "_blank"); |
| | | } else { |
| | | this.activeRoutes(key); |
| | | } |
| | | }, |
| | | // å½åæ¿æ´»çè·¯ç± |
| | | activeRoutes(key) { |
| | | var routes = []; |
| | | if (this.childrenMenus && this.childrenMenus.length > 0) { |
| | | this.childrenMenus.map((item) => { |
| | | if (key == item.parentPath || (key == "index" && "" == item.path)) { |
| | | routes.push(item); |
| | | } |
| | | }); |
| | | } |
| | | this.$store.commit("SET_SIDEBAR_ROUTERS", routes); |
| | | } |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style lang="scss" scoped> |
| | | .el-menu--horizontal > .el-menu-item { |
| | | float: left; |
| | | height: 50px; |
| | | line-height: 50px; |
| | | margin: 0; |
| | | border-bottom: 3px solid transparent; |
| | | color: #999093; |
| | | padding: 0 5px; |
| | | margin: 0 10px; |
| | | } |
| | | |
| | | .el-menu--horizontal > .el-menu-item.is-active { |
| | | border-bottom: 3px solid #409eff; |
| | | color: #303133; |
| | | } |
| | | </style> |