|
@@ -2,61 +2,84 @@
|
|
|
<div class="sidemenu">
|
|
|
<div style="height: 100%" v-if="mode">
|
|
|
<el-menu
|
|
|
- :style="{width: width + 'px', display: 'inline-block', height: '100%'}"
|
|
|
- background-color="#464C5B"
|
|
|
- text-color="#fff"
|
|
|
- :default-active="activeName"
|
|
|
- :active-text-color="color">
|
|
|
+ :style="{
|
|
|
+ width: width + 'px',
|
|
|
+ display: 'inline-block',
|
|
|
+ height: '100%',
|
|
|
+ }"
|
|
|
+ background-color="#464C5B"
|
|
|
+ text-color="#fff"
|
|
|
+ :default-active="activeName"
|
|
|
+ :active-text-color="color"
|
|
|
+ >
|
|
|
<el-menu-item
|
|
|
- v-for="(item) in menuList"
|
|
|
- :class="[item.title === activeName && activeName!== '首页' ? 'menuSet' : '']"
|
|
|
- :index="item.title"
|
|
|
- :key="item.id"
|
|
|
- @click="jump(item)">
|
|
|
+ v-for="item in menuList"
|
|
|
+ :class="[
|
|
|
+ item.title === activeName && activeName !== '首页' ? 'menuSet' : '',
|
|
|
+ ]"
|
|
|
+ :index="item.title"
|
|
|
+ :key="item.id"
|
|
|
+ @click="jump(item)"
|
|
|
+ >
|
|
|
<template slot="title">
|
|
|
- <span>{{item.title}}</span>
|
|
|
+ <span>{{ item.title }}</span>
|
|
|
</template>
|
|
|
</el-menu-item>
|
|
|
</el-menu>
|
|
|
- <div v-show="isShow && activeName!== '首页'" class="subsidemenu">
|
|
|
- <div class="menu-header">{{selectItem.title}}</div>
|
|
|
+ <div v-show="isShow && activeName !== '首页'" class="subsidemenu">
|
|
|
+ <div class="menu-header">{{ selectItem.title }}</div>
|
|
|
<ul class="menu-item-children">
|
|
|
<li
|
|
|
- v-for="item in selectItem.children"
|
|
|
- class="menuChildren"
|
|
|
- :style="{color: item.url == activeUrl ? color : '#999'}"
|
|
|
- @click="go(item)"
|
|
|
- :key="item.id">{{item.title}}</li>
|
|
|
+ v-for="item in selectItem.children"
|
|
|
+ class="menuChildren"
|
|
|
+ :style="{ color: item.url == activeUrl ? color : '#999' }"
|
|
|
+ @click="go(item)"
|
|
|
+ :key="item.id"
|
|
|
+ >
|
|
|
+ {{ item.title }}
|
|
|
+ </li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div style="height: 100%" v-else>
|
|
|
<el-menu
|
|
|
- router
|
|
|
- :style="{width: '249px', display: 'inline-block', height: '100%'}"
|
|
|
- background-color="#464C5B"
|
|
|
- text-color="#fff"
|
|
|
- :default-active="routerName"
|
|
|
- :active-text-color="color">
|
|
|
- <template v-for="item in menuList">
|
|
|
- <el-submenu :key="item.id" v-if="item.children.length > 0 && item.url !== 'dashboard'" :index="item.url">
|
|
|
- <span slot="title">{{item.title}}</span>
|
|
|
- <el-menu-item v-for="list in item.children" :key="list.id" :index="list.url">{{list.title}}</el-menu-item>
|
|
|
- </el-submenu>
|
|
|
- <el-menu-item :key="item.id" v-else :index="item.url">{{item.title}}</el-menu-item>
|
|
|
- </template>
|
|
|
+ router
|
|
|
+ :style="{ width: '249px', display: 'inline-block', height: '100%' }"
|
|
|
+ background-color="#464C5B"
|
|
|
+ text-color="#fff"
|
|
|
+ :default-active="routerName"
|
|
|
+ :active-text-color="color"
|
|
|
+ >
|
|
|
+ <template v-for="item in menuList">
|
|
|
+ <el-submenu
|
|
|
+ :key="item.id"
|
|
|
+ v-if="item.children.length > 0 && item.url !== 'dashboard'"
|
|
|
+ :index="item.url"
|
|
|
+ >
|
|
|
+ <span slot="title">{{ item.title }}</span>
|
|
|
+ <el-menu-item
|
|
|
+ v-for="list in item.children"
|
|
|
+ :key="list.id"
|
|
|
+ :index="list.url"
|
|
|
+ >{{ list.title }}</el-menu-item
|
|
|
+ >
|
|
|
+ </el-submenu>
|
|
|
+ <el-menu-item :key="item.id" v-else :index="item.url">{{
|
|
|
+ item.title
|
|
|
+ }}</el-menu-item>
|
|
|
+ </template>
|
|
|
</el-menu>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { mapState } from 'vuex'
|
|
|
-import { getUserMenu} from "../utils/api";
|
|
|
+import { mapState } from "vuex";
|
|
|
+import { getUserMenu } from "../utils/api";
|
|
|
export default {
|
|
|
name: "SideMenu",
|
|
|
computed: {
|
|
|
- ...mapState(['color', 'mode'])
|
|
|
+ ...mapState(["color", "mode"]),
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
@@ -64,10 +87,10 @@ export default {
|
|
|
width: 249,
|
|
|
isShow: false,
|
|
|
selectItem: {},
|
|
|
- activeUrl: '',
|
|
|
- activeName: '首页',
|
|
|
- routerName: 'dashboard'
|
|
|
- }
|
|
|
+ activeUrl: "",
|
|
|
+ activeName: "首页",
|
|
|
+ routerName: "dashboard",
|
|
|
+ };
|
|
|
},
|
|
|
watch: {
|
|
|
$route(newVal) {
|
|
@@ -75,21 +98,20 @@ export default {
|
|
|
let name = newVal.meta.title;
|
|
|
let parentName = newVal.meta.parentName;
|
|
|
let routerName = newVal.meta.permission;
|
|
|
- this.$emit('setRouterName', {name: name, router: routerName});
|
|
|
- if(this.mode) {
|
|
|
+ this.$emit("setRouterName", { name: name, router: routerName });
|
|
|
+ if (this.mode) {
|
|
|
this.activeName = parentName;
|
|
|
- this.activeUrl = routerName
|
|
|
+ this.activeUrl = routerName;
|
|
|
var that = this;
|
|
|
|
|
|
that.selectItem = that.getFilter(that.menuList, parentName)[0];
|
|
|
- if (that.selectItem.children.length > 0) {
|
|
|
- that.isShow = true;
|
|
|
- } else {
|
|
|
- that.isShow = false;
|
|
|
- }
|
|
|
-
|
|
|
+ if (that.selectItem.children.length > 0) {
|
|
|
+ that.isShow = true;
|
|
|
+ } else {
|
|
|
+ that.isShow = false;
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.routerName = routerName
|
|
|
+ this.routerName = routerName;
|
|
|
}
|
|
|
},
|
|
|
mode(newVal) {
|
|
@@ -97,7 +119,7 @@ export default {
|
|
|
let routerName = this.$route.meta.permission;
|
|
|
// 上级菜单名字
|
|
|
let parentName = this.$route.meta.parentName;
|
|
|
- if(newVal) {
|
|
|
+ if (newVal) {
|
|
|
this.selectItem = this.getFilter(this.menuList, parentName)[0];
|
|
|
this.activeUrl = routerName;
|
|
|
this.activeName = parentName;
|
|
@@ -111,8 +133,8 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
isShow(newVal) {
|
|
|
- if(newVal) {
|
|
|
- if(this.activeName === '首页') {
|
|
|
+ if (newVal) {
|
|
|
+ if (this.activeName === "首页") {
|
|
|
this.width = 249;
|
|
|
} else {
|
|
|
this.width = 100;
|
|
@@ -125,11 +147,11 @@ export default {
|
|
|
methods: {
|
|
|
init() {
|
|
|
let params = {
|
|
|
- userId: localStorage.getItem('UserId')
|
|
|
- }
|
|
|
+ userId: localStorage.getItem("UserId"),
|
|
|
+ };
|
|
|
let parentName = this.$route.meta.parentName;
|
|
|
- getUserMenu(params).then(res => {
|
|
|
- if(res.code === 10000) {
|
|
|
+ getUserMenu(params).then((res) => {
|
|
|
+ if (res.code === 10000) {
|
|
|
this.menuList = res.data;
|
|
|
this.selectItem = this.getFilter(this.menuList, parentName)[0];
|
|
|
if (this.selectItem.children.length > 0) {
|
|
@@ -138,61 +160,63 @@ export default {
|
|
|
this.isShow = false;
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
jump(item) {
|
|
|
this.activeName = item.title;
|
|
|
- if(item.children.length > 0 && item.url !== "dashboard") {
|
|
|
+ if (item.children.length > 0 && item.url !== "dashboard") {
|
|
|
this.isShow = true;
|
|
|
this.selectItem = item;
|
|
|
this.$router.push({
|
|
|
- path: '/' + item.children[0].url
|
|
|
- })
|
|
|
+ path: "/" + item.children[0].url,
|
|
|
+ });
|
|
|
} else {
|
|
|
this.isShow = false;
|
|
|
this.$router.push({
|
|
|
- path: '/' + item.url
|
|
|
- })
|
|
|
+ path: "/" + item.url,
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
go(item) {
|
|
|
this.activeUrl = item.url;
|
|
|
this.$router.push({
|
|
|
- path: '/' + item.url
|
|
|
- })
|
|
|
+ path: "/" + item.url,
|
|
|
+ });
|
|
|
},
|
|
|
// 过滤找到自己上级
|
|
|
getFilter(list, name) {
|
|
|
- let childrenList = [];
|
|
|
- const targetList = list.filter((item) => {
|
|
|
- if(item.title == name) {
|
|
|
- return true
|
|
|
- } else if(item.children && item.children.length) {
|
|
|
- childrenList = childrenList.concat(this.getFilter(item.children, name));
|
|
|
- return false
|
|
|
+ let childrenList = [];
|
|
|
+ const targetList = list.filter((item) => {
|
|
|
+ if (item.title == name) {
|
|
|
+ return true;
|
|
|
+ } else if (item.children && item.children.length) {
|
|
|
+ childrenList = childrenList.concat(
|
|
|
+ this.getFilter(item.children, name)
|
|
|
+ );
|
|
|
+ return false;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
return targetList.concat(childrenList);
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
created() {
|
|
|
- this.init()
|
|
|
+ this.init();
|
|
|
},
|
|
|
mounted() {
|
|
|
// // 路由地址
|
|
|
let routerName = this.$route.meta.permission;
|
|
|
// 上级菜单名字
|
|
|
let parentName = this.$route.meta.parentName;
|
|
|
- if(this.mode) {
|
|
|
+ if (this.mode) {
|
|
|
this.activeUrl = routerName;
|
|
|
this.activeName = parentName;
|
|
|
} else {
|
|
|
this.routerName = routerName;
|
|
|
}
|
|
|
- }
|
|
|
-}
|
|
|
+ },
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
@@ -225,7 +249,7 @@ export default {
|
|
|
.menu-item-children {
|
|
|
width: 100%;
|
|
|
height: calc(100% - 52px);
|
|
|
- background-color: #EAEDF1;
|
|
|
+ background-color: #eaedf1;
|
|
|
margin: 0;
|
|
|
padding: 0;
|
|
|
list-style: none;
|
|
@@ -237,20 +261,19 @@ export default {
|
|
|
border-bottom: 1px solid #ddd;
|
|
|
font-size: 14px;
|
|
|
cursor: pointer;
|
|
|
- color: #BCBCBC;
|
|
|
+ color: #bcbcbc;
|
|
|
}
|
|
|
.menuSet {
|
|
|
position: relative;
|
|
|
}
|
|
|
.menuSet:after {
|
|
|
- content: '';
|
|
|
+ content: "";
|
|
|
position: absolute;
|
|
|
width: 18px;
|
|
|
height: 18px;
|
|
|
top: 20px;
|
|
|
left: 92px;
|
|
|
transform: rotate(45deg);
|
|
|
- background-color: #EAEDF1;
|
|
|
-
|
|
|
+ background-color: #eaedf1;
|
|
|
}
|
|
|
</style>
|