|  |  |  | 
|---|
|  |  |  | <template> | 
|---|
|  |  |  | <div class="menu" :class="{collapse: menuData.collapse}"> | 
|---|
|  |  |  | <div class="logo"> | 
|---|
|  |  |  | <div><img src="@/assets/logo.png"></div> | 
|---|
|  |  |  | <h1 :class="{hidden: menuData.collapse}">华晟园区</h1> | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  | <div class="menu" :class="{ collapse: menuData.collapse }"> | 
|---|
|  |  |  | <scrollbar> | 
|---|
|  |  |  | <!--      :default-openeds="defaultOpeneds"--> | 
|---|
|  |  |  | <el-menu | 
|---|
|  |  |  | ref="menu" | 
|---|
|  |  |  | :unique-opened="true" | 
|---|
|  |  |  | :default-active="activeIndex" | 
|---|
|  |  |  | text-color="#fff" | 
|---|
|  |  |  | active-text-color="#fff" | 
|---|
|  |  |  | text-color="#333333" | 
|---|
|  |  |  | active-text-color="#207FF7" | 
|---|
|  |  |  | :collapse="menuData.collapse" | 
|---|
|  |  |  | :default-openeds="defaultOpeneds" | 
|---|
|  |  |  | :collapse-transition="false" | 
|---|
|  |  |  | unique-opened | 
|---|
|  |  |  | @select="handleSelect" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <MenuItems v-for="menu in menuData.list" :key="menu.index" :menu="menu" :is-root-menu="true"/> | 
|---|
|  |  |  | <MenuItems | 
|---|
|  |  |  | v-for="menu in menuData.list" | 
|---|
|  |  |  | :key="menu.index" | 
|---|
|  |  |  | :menu="menu" | 
|---|
|  |  |  | :is-root-menu="true" | 
|---|
|  |  |  | /> | 
|---|
|  |  |  | </el-menu> | 
|---|
|  |  |  | </scrollbar> | 
|---|
|  |  |  | </div> | 
|---|
|  |  |  | 
|---|
|  |  |  | computed: { | 
|---|
|  |  |  | ...mapState(['menuData']), | 
|---|
|  |  |  | // 选中的菜单index | 
|---|
|  |  |  | activeIndex () { | 
|---|
|  |  |  | activeIndex() { | 
|---|
|  |  |  | let path = this.$route.path | 
|---|
|  |  |  | if (path.endsWith('/')) { | 
|---|
|  |  |  | path = path.substring(0, path.length - 1) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const menuConfig = this.__getMenuConfig(path, 'url', this.menuData.list) | 
|---|
|  |  |  | const menuConfig = this.__getMenuConfig(path, 'index', this.menuData.list) | 
|---|
|  |  |  | if (menuConfig == null) { | 
|---|
|  |  |  | return null | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.$store.commit('pushtags', menuConfig) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // console.log(menuConfig.index); | 
|---|
|  |  |  | return menuConfig.index | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | // 默认展开的菜单index | 
|---|
|  |  |  | defaultOpeneds () { | 
|---|
|  |  |  | return this.menuData.list.map(menu => menu.index) | 
|---|
|  |  |  | defaultOpeneds() { | 
|---|
|  |  |  | // return this.menuData.list.map(menu => menu.index) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return [this.menuData.list[0].index] | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | methods: { | 
|---|
|  |  |  | // 处理菜单选中 | 
|---|
|  |  |  | handleSelect (menuIndex) { | 
|---|
|  |  |  | handleSelect(menuIndex) { | 
|---|
|  |  |  | const menuConfig = this.__getMenuConfig(menuIndex, 'index', this.menuData.list) | 
|---|
|  |  |  | // 找不到页面 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | require('@/views' + menuConfig.url) | 
|---|
|  |  |  | } catch (e) { | 
|---|
|  |  |  | this.$tip.error('未找到页面文件@/views' + menuConfig.url + '.vue,请检查菜单路径是否正确') | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 点击当前菜单不做处理 | 
|---|
|  |  |  | if (menuConfig.url === this.$route.path) { | 
|---|
|  |  |  | if (menuConfig.url === this.$route.path && (menuConfig.params == null || menuConfig.params == undefined || menuConfig.params == '' || menuConfig.params === this.$route.query.param)) { | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (menuConfig.url == null || menuConfig.url.trim().length === 0) { | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.$router.push(menuConfig.url) | 
|---|
|  |  |  | if (menuConfig.params != null && menuConfig.params != '') { | 
|---|
|  |  |  | this.$router.push({ path: menuConfig.url, query: { index: menuConfig.index, param: menuConfig.params } }) | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.$router.push(menuConfig.url) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.$store.commit('pushtags', menuConfig) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | // 获取菜单配置 | 
|---|
|  |  |  | __getMenuConfig (value, key, menus) { | 
|---|
|  |  |  | __getMenuConfig(value, key, menus) { | 
|---|
|  |  |  | for (const menu of menus) { | 
|---|
|  |  |  | if (menu[key] === value) { | 
|---|
|  |  |  | return menu | 
|---|
|  |  |  | 
|---|
|  |  |  | height: 100%; | 
|---|
|  |  |  | display: flex; | 
|---|
|  |  |  | flex-direction: column; | 
|---|
|  |  |  | // LOGO | 
|---|
|  |  |  | .logo { | 
|---|
|  |  |  | height: 60px; | 
|---|
|  |  |  | flex-shrink: 0; | 
|---|
|  |  |  | line-height: 60px; | 
|---|
|  |  |  | overflow: hidden; | 
|---|
|  |  |  | display: flex; | 
|---|
|  |  |  | background: $primary-color - 20; | 
|---|
|  |  |  | padding: 0 16px; | 
|---|
|  |  |  | & > div { | 
|---|
|  |  |  | width: 32px; | 
|---|
|  |  |  | flex-shrink: 0; | 
|---|
|  |  |  | margin-right: 12px; | 
|---|
|  |  |  | img { | 
|---|
|  |  |  | width: 100%; | 
|---|
|  |  |  | flex-shrink: 0; | 
|---|
|  |  |  | vertical-align: middle; | 
|---|
|  |  |  | position: relative; | 
|---|
|  |  |  | top: -2px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | h1 { | 
|---|
|  |  |  | font-size: 16px; | 
|---|
|  |  |  | font-weight: 500; | 
|---|
|  |  |  | transition: opacity ease .3s; | 
|---|
|  |  |  | overflow: hidden; | 
|---|
|  |  |  | &.hidden { | 
|---|
|  |  |  | opacity: 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </style> | 
|---|
|  |  |  | <style lang="scss"> | 
|---|
|  |  |  | 
|---|
|  |  |  | .el-menu { | 
|---|
|  |  |  | border-right: 0 !important; | 
|---|
|  |  |  | user-select: none; | 
|---|
|  |  |  | background: $primary-color !important; | 
|---|
|  |  |  | background: #fff !important; | 
|---|
|  |  |  | .el-menu-item { | 
|---|
|  |  |  | background: $primary-color; | 
|---|
|  |  |  | background: #fff; | 
|---|
|  |  |  | height: 48px; | 
|---|
|  |  |  | line-height: 48px; | 
|---|
|  |  |  | // 选中状态 | 
|---|
|  |  |  | &.is-active { | 
|---|
|  |  |  | background: $primary-color - 40 !important; | 
|---|
|  |  |  | background: #eff5fe !important; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 悬浮 | 
|---|
|  |  |  | &:hover { | 
|---|
|  |  |  | background-color: $primary-color - 12; | 
|---|
|  |  |  | background-color: #eff5fe; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | &:focus { | 
|---|
|  |  |  | background: $primary-color; | 
|---|
|  |  |  | background: #eff5fe; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 子菜单 | 
|---|
|  |  |  | .el-submenu { | 
|---|
|  |  |  | .el-submenu__title{ | 
|---|
|  |  |  | background-color: $primary-color; | 
|---|
|  |  |  | .el-submenu__title { | 
|---|
|  |  |  | background-color: #fff; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | &.is-active { | 
|---|
|  |  |  | .el-submenu__title{ | 
|---|
|  |  |  | background-color: $primary-color - 20; | 
|---|
|  |  |  | .el-submenu__title { | 
|---|
|  |  |  | background-color: #fff; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | .el-menu .el-menu-item{ | 
|---|
|  |  |  | background-color: $primary-color - 20; | 
|---|
|  |  |  | .el-menu .el-menu-item { | 
|---|
|  |  |  | background-color: #fff; | 
|---|
|  |  |  | // 悬浮 | 
|---|
|  |  |  | &:hover { | 
|---|
|  |  |  | background-color: $primary-color - 30; | 
|---|
|  |  |  | background-color: #eff5fe; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 菜单上下箭头 | 
|---|
|  |  |  | .el-submenu__title i { | 
|---|
|  |  |  | color: #f7f7f7; | 
|---|
|  |  |  | color: #979797; | 
|---|
|  |  |  | font-size: 14px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 菜单图标 | 
|---|
|  |  |  | i:not(.el-submenu__icon-arrow) { | 
|---|
|  |  |  | color: #f7f7f7 !important; | 
|---|
|  |  |  | color: #333333 !important; | 
|---|
|  |  |  | position: relative; | 
|---|
|  |  |  | top: -1px; | 
|---|
|  |  |  | // 自定义图标 | 
|---|