Commit e950a68d by Tang

feat: 侧边栏功能优化

parent bfd2ab18
...@@ -87,7 +87,7 @@ export default { ...@@ -87,7 +87,7 @@ export default {
if (this.$route.path.startsWith(nav_.link)) { if (this.$route.path.startsWith(nav_.link)) {
this.currentNav = nav_.id; this.currentNav = nav_.id;
nav_.children && nav_.children &&
nav_.children.legnth > 0 && nav_.children.length > 0 &&
this.$store.commit("system/SET_SUB_NAV", nav_.children); this.$store.commit("system/SET_SUB_NAV", nav_.children);
if (nav_.link === this.$route.path) { if (nav_.link === this.$route.path) {
nav_.breadcrumb && nav_.breadcrumb &&
......
...@@ -40,7 +40,7 @@ export const nav = [ ...@@ -40,7 +40,7 @@ export const nav = [
id: "2", id: "2",
name: "业务大厅", name: "业务大厅",
index: 2, index: 2,
link: "/buiss", link: "/Business",
children: [], children: [],
}, },
{ {
......
<template> <template>
<el-menu <el-menu
:default-active="activeMenu" :default-active="activeMenu"
class="el-menu-vertical gs-subnav" class="el-menu-vertical gs-subnav"
:collapse="false" :collapse="false"
@select="handleSelect" @select="handleSelect"
> >
<template v-for="submenu in subNav"> <template v-for="submenu in subNav">
<el-submenu <el-submenu
v-if="submenu.children && submenu.children.length > 0" v-if="submenu.children && submenu.children.length > 0"
:key="submenu.id" :key="submenu.id"
:index="submenu.name" :index="submenu.name"
> >
<template slot="title"> <template slot="title">
<span style="margin-left: 6px">{{ submenu.name }}</span> <span>{{ submenu.name }}</span>
</template> </template>
<template v-for="item in submenu.children"> <template v-for="item in submenu.children">
<template v-if="item.children && item.children.length > 0"> <template v-if="item.children && item.children.length > 0">
<el-submenu <el-submenu
:index="item.name" :index="item.name"
:key="item.id" :key="item.id"
:background-color="theme.subMenuBg"
:text-color="theme.menuText"
:active-text-color="theme.menuActiveText"
> >
<template slot="title"> <template slot="title">
<i
v-show="item.icon_name"
:style="{ color: theme.menuText }"
style="font-size: 13px"
:class="['qycloud', `${item.icon_name}`]"
/>
<span style="margin-left: 6px">{{ item.name }}</span> <span style="margin-left: 6px">{{ item.name }}</span>
</template> </template>
<template v-for="third in item.children"> <template v-for="third in item.children">
<el-menu-item <el-menu-item
:key="third.id" :key="third.id"
:index="third.name" :index="third.name"
:class="{ 'is-active': activeMenu === third.id }" :class="{ 'is-active': activeMenu === third.id }"
> >
{{ third.name }} {{ third.name }}
</el-menu-item> </el-menu-item>
</template> </template>
</el-submenu> </el-submenu>
</template> </template>
<template v-else> <template v-else>
<el-menu-item <el-menu-item
:key="item.id" :key="item.id"
:index="item.name" :index="item.name"
:class="{ 'is-active': activeMenu === item.id }" :class="{ 'is-active': activeMenu === item.id }"
> >
{{ item.name }} {{ item.name }}
</el-menu-item> </el-menu-item>
...@@ -57,17 +47,10 @@ ...@@ -57,17 +47,10 @@
</el-submenu> </el-submenu>
<template v-else> <template v-else>
<el-menu-item <el-menu-item
:key="submenu.id" :key="submenu.id"
:index="submenu.name" :index="submenu.name"
:class="{ 'is-active': activeMenu === submenu.id }" :class="{ 'is-active': activeMenu === submenu.id }"
> >
{{ submenu.name }}
<i
v-show="submenu.icon_name"
:style="{ color: theme.menuText }"
style="font-size: 13px;margin-right: 6px"
:class="['qycloud', `${submenu.icon_name}`]"
/>
<span>{{ submenu.name }}</span> <span>{{ submenu.name }}</span>
</el-menu-item> </el-menu-item>
</template> </template>
...@@ -75,12 +58,12 @@ ...@@ -75,12 +58,12 @@
</el-menu> </el-menu>
</template> </template>
<script> <script>
import { mapState } from "vuex"; import {mapState} from "vuex";
export default { export default {
data() { data() {
return { return {
defaultOpeneds: ["1", "2"], activeMenu: '',
}; };
}, },
computed: { computed: {
...@@ -90,6 +73,60 @@ export default { ...@@ -90,6 +73,60 @@ export default {
console.log(this.subNav); console.log(this.subNav);
}, },
methods: { methods: {
handleSelect(index, indexP) {
console.log(index, indexP);
const temp = JSON.parse(JSON.stringify(indexP));
const key = temp.shift();
this.subNav.forEach((item) => {
if (item.name === key) {
if (temp.length > 1) {
this.checkChildren(index, temp, item.children);
} else if (temp.length === 0) {
this.activeMenu = item.name;
this.showApp(item);
} else {
item.children.forEach((_item) => {
if (_item.name === index) {
this.activeMenu = _item.name;
this.showApp(_item);
}
});
}
}
});
},
checkChildren(index, indexP, list) {
const key = indexP.shift();
list.forEach((item) => {
console.log(key);
if (item.name === key) {
if (indexP.length > 1) {
this.checkChildren(index, indexP, item.children);
} else {
item.children.forEach((_item) => {
if (_item.name === index) {
this.activeMenu = _item.name;
this.showApp(_item);
}
});
}
}
});
},
showApp(item) {
console.log(item)
if(item.link.startsWith('http')){
window.open(item.link)
}else{
if (item.breadcrumb) {
this.$store.commit('system/SET_BREADCRUMB', item.breadcrumb)
}
this.$router.push({path: item.link})
}
},
handleOpen(key, keyPath) { handleOpen(key, keyPath) {
console.log(key, keyPath); console.log(key, keyPath);
}, },
...@@ -103,11 +140,13 @@ export default { ...@@ -103,11 +140,13 @@ export default {
.el-menu.gs-subnav { .el-menu.gs-subnav {
border-right: none; border-right: none;
background: $side-bg-color; background: $side-bg-color;
.el-submenu__title { .el-submenu__title {
background: $side-bg-color; background: $side-bg-color;
height: 44px; height: 44px;
line-height: 44px; line-height: 44px;
} }
.menu-title { .menu-title {
margin-top: 25px; margin-top: 25px;
margin-bottom: 10px; margin-bottom: 10px;
...@@ -115,12 +154,14 @@ export default { ...@@ -115,12 +154,14 @@ export default {
font-size: 14px; font-size: 14px;
color: #b7b6b6; color: #b7b6b6;
} }
.el-menu-item { .el-menu-item {
height: 44px; height: 44px;
line-height: 44px; line-height: 44px;
color: #6b6a6a; color: #6b6a6a;
background: transparent; background: transparent;
font-size: 14px; font-size: 14px;
i { i {
color: $side-bg-color; color: $side-bg-color;
font-size: 25px; font-size: 25px;
...@@ -128,6 +169,7 @@ export default { ...@@ -128,6 +169,7 @@ export default {
top: 15px; top: 15px;
right: 15px; right: 15px;
} }
&:hover, &:hover,
&:focus, &:focus,
&.is-active { &.is-active {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment