|
@@ -1,9 +1,10 @@
|
|
|
<script>
|
|
|
+import {requireImg} from "@/utils/requireImg";
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- title: '',
|
|
|
+ selectedKeys: [],
|
|
|
highLight: {backgroundColor: '#e9f6fd'},
|
|
|
routers: [],
|
|
|
menuList: [],
|
|
@@ -12,49 +13,37 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
let app = this;
|
|
|
- // let ele = document.getElementsByClassName('home-page')[0];
|
|
|
- // this.$util.eleResizeListener(ele, function () {
|
|
|
- // let height = ele.clientHeight;
|
|
|
- // app.height = height+'px'
|
|
|
- // })
|
|
|
-
|
|
|
this.routers = this.$router.options.routes;
|
|
|
- this.$nextTick(()=>{
|
|
|
+ this.$nextTick(() => {
|
|
|
app.getCurrMenuList()
|
|
|
})
|
|
|
|
|
|
},
|
|
|
methods: {
|
|
|
+ requireImg,
|
|
|
getCurrMenuList() {
|
|
|
let arr = this.$route.matched;
|
|
|
- let route = this.routers;
|
|
|
- let num = arr.length-1;
|
|
|
- if (arr.length===2) {
|
|
|
- num = 2
|
|
|
- }
|
|
|
- for (let i = 0; i < num; i++) {
|
|
|
- let obj = route.find((e) => (e.name == arr[i].name));
|
|
|
+ let route = this.routers[0].children;
|
|
|
+ if (arr.length>1) {
|
|
|
+ let obj = route.find((e) => (e.path == arr[1].path));
|
|
|
route = obj.children;
|
|
|
- this.title = obj.meta.breadcrumb;
|
|
|
}
|
|
|
this.menuList = JSON.parse(JSON.stringify(route))
|
|
|
- if (this.menuList.length>0 && arr.length<=2) {
|
|
|
- this.handleClick(this.menuList[0])
|
|
|
- } else {
|
|
|
- for (let obj of this.menuList) {
|
|
|
- obj.selected = false;
|
|
|
- if (obj.path == this.$route.path) {
|
|
|
- obj.selected = true;
|
|
|
- }
|
|
|
+ this.selectedKeys = [];
|
|
|
+ if (arr.length>2) {
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ this.selectedKeys.push(arr[i].path)
|
|
|
+ }
|
|
|
+ } else if (arr.length===2) {
|
|
|
+ if (this.menuList.length>0 && !this.menuList[0].children) {
|
|
|
+ this.handleClick(this.menuList[0]);
|
|
|
+ this.selectedKeys.push(this.menuList[0].path)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
handleClick(item) {
|
|
|
- for (let obj of this.menuList) {
|
|
|
- obj.selected = false;
|
|
|
- }
|
|
|
- item.selected = true;
|
|
|
- this.$router.push(item.path)
|
|
|
+ let path = item.path?item.path:item.key
|
|
|
+ this.$router.push({path: path})
|
|
|
this.$forceUpdate()
|
|
|
}
|
|
|
}
|
|
@@ -63,43 +52,82 @@ export default {
|
|
|
|
|
|
<template>
|
|
|
<div class="containerAside" :style="{height: '100%'}">
|
|
|
- <div class="containerAside-title">
|
|
|
- {{ title }}
|
|
|
- </div>
|
|
|
- <div class="containerAside-item" :style="item.selected?highLight:{}" v-for="item in menuList" :key="item.name" @click="handleClick(item)">
|
|
|
- {{ item.meta.breadcrumb }}
|
|
|
- </div>
|
|
|
+ <a-menu
|
|
|
+ style="width: 100%;padding-top: 8px;height: 100%"
|
|
|
+ mode="inline"
|
|
|
+ theme="dark"
|
|
|
+ v-model:selectedKeys="selectedKeys"
|
|
|
+ @click="handleClick"
|
|
|
+ >
|
|
|
+ <template v-for="item in menuList">
|
|
|
+ <a-menu-item class="menuItem" :key="item.path" :route="item.key" v-if="!item.children">
|
|
|
+ <span class="anticon" style="vertical-align: text-top">
|
|
|
+ <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
|
|
|
+ </span>
|
|
|
+ <span >
|
|
|
+ {{ item.meta.breadcrumb }}
|
|
|
+ </span>
|
|
|
+ </a-menu-item>
|
|
|
+
|
|
|
+ <a-sub-menu :key="item.name" v-else>
|
|
|
+ <template #title>
|
|
|
+ <span class="anticon" style="vertical-align: text-top">
|
|
|
+ <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
|
|
|
+ </span>
|
|
|
+ <span>{{ item.meta.breadcrumb }}</span>
|
|
|
+ </template>
|
|
|
+ <a-menu-item v-for="subItem in item.children" :key="subItem.path" :route="subItem.path">
|
|
|
+ <span class="anticon" style="vertical-align: text-top">
|
|
|
+ <a-avatar class="function-avatar" shape="square" :size="20" :src="requireImg(item.icon)"></a-avatar>
|
|
|
+ </span>
|
|
|
+ <span>{{ subItem.meta.breadcrumb }}</span>
|
|
|
+ </a-menu-item>
|
|
|
+ </a-sub-menu>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ </a-menu>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
+@menu-dark-bg: #ffffff;
|
|
|
+@menu-dark-submenu-bg: #ffffff;
|
|
|
+@menu-dark-color: #808080;
|
|
|
+@menu-dark-arrow-color: #808080;
|
|
|
+@menu-dark-highlight-color: #808080;
|
|
|
+@menu-dark-item-active-bg: #e5f4ff;
|
|
|
+@menu-dark-selected-item-icon-color: #808080;
|
|
|
+@menu-dark-selected-item-text-color: #808080;
|
|
|
.containerAside {
|
|
|
- width: 220px;
|
|
|
+ width: 170px;
|
|
|
height: 100%;
|
|
|
border-right: 1px solid #eeeeee;
|
|
|
display: inline-block;
|
|
|
vertical-align: top;
|
|
|
- .containerAside-title {
|
|
|
- text-align: center;
|
|
|
- height: 60px;
|
|
|
- line-height: 60px;
|
|
|
- width: 100%;
|
|
|
- background-color: #d8d8d8;
|
|
|
- cursor: default;
|
|
|
+
|
|
|
+ .menuItem {
|
|
|
+ margin: 15px 0;
|
|
|
+ }
|
|
|
+ /deep/ .ant-menu-sub {
|
|
|
+ box-shadow: none !important;
|
|
|
+ background-color: white;
|
|
|
+ margin: 0 !important;
|
|
|
+ }
|
|
|
+ /deep/ .ant-menu-item-selected {
|
|
|
+ color: @menu-dark-selected-item-text-color !important;
|
|
|
}
|
|
|
- .containerAside-item {
|
|
|
- text-align: center;
|
|
|
- line-height: 50px;
|
|
|
- height: 50px;
|
|
|
- width: 100%;
|
|
|
- margin: 8px 0;
|
|
|
- cursor: pointer;
|
|
|
+ /deep/ .ant-menu-dark .ant-menu-submenu-title:hover {
|
|
|
+ color: @menu-dark-selected-item-text-color;
|
|
|
}
|
|
|
- .containerAside-item:hover {
|
|
|
- background-color: #eeeeee;
|
|
|
+ .ant-menu-inline-collapsed > .ant-menu-item {
|
|
|
+ padding: 0 !important;
|
|
|
+ margin-left: 0 !important;
|
|
|
+ padding-left: 33% !important;
|
|
|
}
|
|
|
- .containerAside-item .selected {
|
|
|
- background-color: #e9f6fd;
|
|
|
+ /deep/ .ant-menu-inline-collapsed > .ant-menu-item-group > .ant-menu-item-group-list > .ant-menu-item {
|
|
|
+ padding: 0 !important;
|
|
|
+ margin-left: 0 !important;
|
|
|
+ padding-left: 33% !important;
|
|
|
}
|
|
|
}
|
|
|
</style>
|