From e1aa0ecffbabd618c71e4ad94370fb8dffe6ee1c Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期日, 21 一月 2024 20:54:49 +0800
Subject: [PATCH] 优化
---
src/views/layout/components/Menu/index.vue | 345 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 239 insertions(+), 106 deletions(-)
diff --git a/src/views/layout/components/Menu/index.vue b/src/views/layout/components/Menu/index.vue
index 8ad84aa..5302c98 100644
--- a/src/views/layout/components/Menu/index.vue
+++ b/src/views/layout/components/Menu/index.vue
@@ -1,128 +1,261 @@
<template>
- <div class="Menu">
- <!-- 鑿滃崟鏍� -->
- <el-aside width="200px" class="menu">
- <h2 class="siderbar-title">閬傛槍鎵ф硶骞冲彴</h2>
- <el-scrollbar class="MenuScroll">
- <!-- 璺敱 -->
- <el-menu class="el-menu-vertical">
- <el-menu-item v-for="item in menu" :key="item.name" class="firstMenu" @click="Jump(item.index)">
- <template slot="title" class="firstSpan">
- <span slot="prefix" class="icon-padding fisrtSpan">
- <svg-icon :icon-class="item.icon"></svg-icon>
- </span>
- <span class="fisrtSpan">{{item.name}}</span>
- </template>
- </el-menu-item>
- </el-menu>
- </el-scrollbar>
- </el-aside>
- </div>
+ <div>
+ <!-- 渚ц竟瀵艰埅鏍� -->
+ <el-aside width="200px">
+ <h2 class="siderbar-title" @click="toHome()">閬傛槍鎵ф硶骞冲彴</h2>
+ <el-scrollbar>
+ <!-- 璺敱 -->
+ <el-menu
+ router
+ class="el-menu-vertical"
+ :default-active="$route.path.name"
+ @select="handleSelect"
+ >
+ <el-submenu
+ :index="String(menu.id)"
+ v-for="menu in menuList"
+ :key="menu.id"
+ class="firstMenu"
+ >
+ <template slot="title">
+ <span slot="prefix" class="icon-padding fisrtSpan">
+ <svg-icon
+ class="icon-title"
+ v-bind:class="menu.icon"
+ :icon-class="menu.icon"
+ ></svg-icon>
+ </span>
+ <span class="fisrtSpan">{{ menu.title }}</span>
+ </template>
+ <template v-if="menu.menuVoArrayList.length > 0">
+ <template
+ v-for="secondMenu in menu.menuVoArrayList"
+ >
+ <el-submenu
+ :key="secondMenu.id"
+ v-if="secondMenu.menuVoArrayList.length > 0"
+ :index="
+ secondMenu.url
+ ? secondMenu.url
+ : secondMenu.id.toString()
+ "
+ class="secondMenu"
+ :class="
+ secondMenu.menuVoArrayList.length > 0
+ ? 'is-Active'
+ : 'none-Active'
+ "
+ >
+ <template slot="title">
+ <span class="secondSpan">{{
+ secondMenu.title
+ }}</span>
+ </template>
+ <el-menu-item
+ v-for="thirdMenu in secondMenu.menuVoArrayList"
+ :key="thirdMenu.id"
+ :index="`${thirdMenu.id}`"
+ :route="{ name: thirdMenu.url }"
+ v-if="thirdMenu.id != '65'"
+ >
+ <template>
+ {{ thirdMenu.title }}
+ </template></el-menu-item
+ >
+ </el-submenu>
+ <el-menu-item
+ v-else
+ :index="`${secondMenu.id}`"
+ :route="{ name: secondMenu.url }"
+ >{{ secondMenu.title }}</el-menu-item
+ >
+ </template>
+ </template>
+ <el-menu-item
+ v-else
+ :key="menu.id"
+ :index="`${menu.id}`"
+ :route="{ name: menu.url }"
+ >{{ menu.title }}</el-menu-item
+ >
+ </el-submenu>
+ </el-menu>
+ </el-scrollbar>
+ </el-aside>
+ </div>
</template>
<script>
+import users from "@/api/users";
+import router from "@/router";
+
export default {
- data() {
- return {
- menu: [
- {
- name: "绯荤粺璁剧疆", icon: "system", index: "/home/system",
+ data() {
+ return {
+ menuList: [],
+ isActive: ''
+ };
+ },
+ created() {
+ this.loadMenu();
+ },
+ watch: {
+ $route() {
+ this.handleSelect(this.$route.fullPath)
},
- {
- name: "杩愯惀绠$悊", icon: "operate", index: "/home/operate",
+ '$route.path'(toPath, fromPath) {
+ this.handleSelect(toPath)
+ this.$router.push({ path: toPath })
},
- {
- name: "瑙嗛宸℃煡", icon: "video", index: "/home/video",
+ },
+
+ methods: {
+ handleSelect(path) {
+ this.isActive = path
},
- {
- name: "娌圭儫淇℃伅鏌ヨ", icon: "intelligence", index: "/home/lampblack",
+ loadMenu() {
+ const userName = sessionStorage.getItem('name');
+ users.getMenu({ name: userName })
+ .then(res => {
+ this.menuList = res.menus;
+ sessionStorage.setItem('user', JSON.stringify(res));
+ })
+ .catch(err => this.$message.error(err))
},
- {
- name: "鎵ф硶绠$悊", icon: "intelligence", index: "/home/law",
- },
- {
- name: "鏅鸿兘宸℃煡", icon: "intelligence", index: "/home/intellect",
- },
- {
- name: "骞冲彴鍩烘湰淇℃伅", icon: "intelligence", index: "/home/info",
+ toHome() {
+ router.push("/home")
}
- ],
- }
- },
- methods:{
- Jump(url){
- this.$router.push(url);
- }
- }
+ },
};
</script>
<style lang="scss" scpoed>
.icon-padding {
- padding-right: 10px;
+ padding-right: 10px;
+ .icon-title {
+ width: 36px;
+ height: 36px;
+ }
}
-.menu {
- background: #07162e;
- color: #e9eef3;
- text-align: center;
- box-sizing: border-box;
- position: relative;
- // 鍥哄畾鏍囬
- .siderbar-title {
- position: fixed;
+.smoke {
+ padding: 5px;
+}
+.el-aside {
+ background: #313350;
+ color: #e9eef3;
text-align: center;
- margin: 0;
- font-size: 26px;
- width: 200px;
- line-height: 66px;
- top: 0;
- left: 0;
- z-index: 999;
- background-color: #08162f;
- }
-
- .MenuScroll {
- height: calc(100vh - 66px);
box-sizing: border-box;
- margin-top: 66px;
- .el-menu {
- background: linear-gradient(#07162e, #0f2b56);
- border: 0;
-
- .firstMenu {
- background: #07162e;
- text-align: left;
- &:hover .fisrtSpan {
- color: #fff;
- }
-
- span {
- color: #e9eef3;
- }
-
- .el-menu-item {
- color: #c3c3c4;
- background-color: #07162e;
- &:hover {
- color: #fff;
- background-color: #0c2c4c;
- }
- }
-
- .is-active {
- background-color: #07162e;
- color: #22d3eb;
- }
- }
-
- .is-active {
- background-color: #07162e;
- }
+ position: relative;
+ // 鍥哄畾鏍囬
+ .siderbar-title {
+ position: fixed;
+ text-align: center;
+ margin: 0;
+ font-size: 26px;
+ width: 200px;
+ line-height: 66px;
+ top: 0;
+ left: 0;
+ z-index: 999;
+ cursor: pointer;
}
+ .el-scrollbar {
+ height: calc(100vh - 66px);
+ margin-top: 66px;
+ box-sizing: border-box;
+ .el-menu {
+ background: linear-gradient(#313350, #0f2b56);
+ border: 0;
+ font-size: 16px;
+ .is-opened {
+ .fisrtSpan {
+ color: #22d3eb;
+ }
+ }
+ .firstMenu {
+ background: #313350;
+ text-align: left;
+ //border-bottom:1px solid #ccc ;
+ &:hover > .el-submenu__title {
+ background-color: #092c4a;
+ }
+ &:hover .fisrtSpan {
+ color: #22d3eb;
+ }
+ span,
+ span {
+ color: #e9eef3;
+ font-size: 16px;
+ }
+ .el-menu {
+ .is-active {
+ background-color: #409eff;
+ color: #fff;
+ }
+ .is-Active {
+ background-color: #092c4a;
+ color: #fff;
+ }
+ }
+ .el-menu-item {
+ color: #e9eef3;
+ background-color: #313350;
+ font-size: 16px;
+ // border-bottom: 0.5px solid #7c7979;
+ }
+ .el-menu-item:hover {
+ background-color: #409eff;
+ color: #22d3eb;
+ }
+ .is-opened {
+ .secondSpan {
+ color: #22d3eb;
+ }
+ }
+ .secondMenu {
+ //border-bottom:1px solid #ccc ;
+ .is-active {
+ background-color: #409eff;
+ color: #22d3eb;
+ }
+ }
+ }
+ .secondMenu {
+ &:hover > .el-submenu__title {
+ background-color: #092c4a;
+ }
+ .secondSpan {
+ }
+ &:hover .secondSpan {
+ color: #22d3eb;
+ }
+ .is-opened {
+ .el-submenu__title {
+ background-color: #fff;
+ }
+ }
+ .is-active {
+ background-color: #409eff;
+ color: #fff;
+ }
+ }
+ .thirdMenu {
+ &:hover > .el-submenu__title {
+ background-color: #092c4a;
+ }
- .el-scrollbar__wrap {
- overflow-x: hidden;
+ &:hover .thirdSpan {
+ color: #22d3eb;
+ }
+ }
+
+ .is-active {
+ background-color: #092c4a;
+ }
+ }
+ .el-scrollbar__wrap {
+ overflow-x: hidden;
+ }
}
- }
}
-</style>
\ No newline at end of file
+</style>
--
Gitblit v1.8.0