记录vue菜单:
<!-- 路由配置router.js-->
import Vue from "vue"; import VueRouter from "vue-router"; import Home from '@/views/home'; Vue.use(VueRouter); const routes = [ { path: "/login", name: "login", component: () => import ("../views/login.vue"), }, { path: "/user", name: "user", component: Home, hidden: true, children: [ { path: '/user/center', name: 'center', meta: { title: '个人中心', navTitle:"个人中心", icon: 'menu-monitor.svg', affix: true, noCache: true }, component: (resolve) => require(['@/views/resetPass'], resolve) } ] }, { path: '/', component: Home, hidden: true, redirect: '/monitor/index', children: [ { path: '/monitor/index', name: 'index', meta: { title: '监控大厅', navTitle:"风机生产应用生态系统与基建设施监控仪表盘", icon: 'menu-monitor.svg', affix: true, noCache: true }, component: (resolve) => require(['@/views/index'], resolve) } ] }, { path: '/monitor', name: "监控", meta: {title: "监控", navTitle:"监控", icon: "menu-monitor.svg", noCache: true}, hidden: false, redirect: "noredirect", component: Home, children: [ { path: "/monitor/index", name: "index", meta: {title: "监控大厅", navTitle:"风机生产应用生态系统与基建设施监控仪表盘", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/index'], resolve) }, { path: "detail", name: "detail", meta: {title: "详细", navTitle:"监控详情", icon: "", noCache: true}, hidden: true, component: (resolve) => require(['@/views/details2'], resolve) }, { path: "/processList", name: "processList", meta: {title: "", navTitle:"", icon: "", noCache: true}, hidden: true, component: (resolve) => require(['@/views/processList'], resolve) } ] }, { path: '/warning', name: "告警", meta: {title: "告警", navTitle:"告警", icon: "menu-warning.svg", noCache: true}, hidden: false, redirect: "noredirect", component: Home, children: [ { path: "/warning/history", name: "history", meta: {title: "告警历史", navTitle:"告警历史", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/history'], resolve) } ] }, { path: '/endpoint', name: "设备库", meta: {title: "设备库", navTitle:"设备库", icon: "menu-endpoint.svg", noCache: true}, hidden: false, redirect: "noredirect", component: Home, children: [ { path: "/endpoint/siteTree", name: "siteTree", meta: {title: "站点设备库", navTitle:"站点设备库", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/siteTree/siteTree'], resolve) }, { path: "/endpoint/worldMap", name: "worldMap", meta: {title: "网络链路负载", navTitle:"网络链路负载", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/worldMap/worldMap'], resolve) } ] }, { path: '/analysis', name: "分析", meta: {title: "分析", navTitle:"分析", icon: "menu-analysis.svg", noCache: true}, hidden: false, redirect: "noredirect", component: Home, children: [ { path: "/analysis/report", name: "report", meta: {title: "报表", navTitle:"报表", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/report'], resolve) }, { path: "/analysis/monthReport", name: "monthReport", meta: {title: "月报", navTitle:"月报", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/reportPdf'], resolve) } ] }, { path: '/manage', name: "管理", meta: {title: "管理", navTitle:"管理", icon: "menu-manage.svg", noCache: true}, hidden: false, redirect: "noredirect", component: Home, children: [ { path: "/manage/userManage", name: "userManage", meta: {title: "用户管理", navTitle:"用户管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/userManage'], resolve) }, { path: "/manage/userGroupManage", name: "userGroupManage", meta: {title: "用户组管理", navTitle:"用户组管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/userGroupManage'], resolve) }, { path: "/manage/templateManage", name: "templateManage", meta: {title: "配置管理", navTitle:"配置管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/templateManage/templateManage'], resolve) }, { path: "/manage/schedule", name: "schedule", meta: {title: "值班日历", navTitle:"值班日历", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/schedule'], resolve) }, { path: "/manage/shiftManage", name: "shiftMange", meta: {title: "值班时间管理", navTitle:"值班时间管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/shiftManage'], resolve) }, // { // path: "/manage/monitor", // name: "monitor", // meta: {title: "监控对象管理", navTitle:"监控对象管理", icon: "", noCache: true}, // hidden: false, // component: (resolve) => require(['@/views/manage/monitor'], resolve) // }, { path: "/manage/integrate", name: "integrate", meta: {title: "报表设定管理", navTitle:"报表设定管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/integrate'], resolve) }, { path: "/manage/availability", name: "availability", meta: {title: "利用率分析阈值管理", navTitle:"利用率分析阈值管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/availability'], resolve) }, { path: "/manage/apiAlive", name: "apiAlive", meta: {title: "API探活管理", navTitle:"API探活管理", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/apiAlive'], resolve) }, { path: "/manage/warringmanage", name: "warringmanage", meta: {title: "语音通知设定", navTitle:"语音通知设定", icon: "", noCache: true}, hidden: false, component: (resolve) => require(['@/views/manage/warringmanage'], resolve) } ] }, { path: "/historyProcess", name: "historyProcess", meta: {title: "", navTitle:"", icon: "menu-manage.svg", noCache: true}, hidden: true, component: () => import ("../views/historyProcess.vue"), } ]; const router = new VueRouter({ mode: "history", base: process.env.BASE_URL, routes, }); router.beforeEach((to, from, next) => { if (to.path !== "/login") { let login = localStorage.getItem("login") || false; if (login) { next(); } else { next({ path: "/login" }); } } else { next(); } }); export default router;
<!--store-->
import Cookies from 'js-cookie'; const state = { sidebar: { opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, withoutAnimation: false }, monitor: { viewId: "", editor: false } } const mutations = { TOGGLE_SIDEBAR: state => { state.sidebar.opened = !state.sidebar.opened state.sidebar.withoutAnimation = false if (state.sidebar.opened) { Cookies.set('sidebarStatus', 1) } else { Cookies.set('sidebarStatus', 0) } }, CLOSE_SIDEBAR: (state, withoutAnimation) => { Cookies.set('sidebarStatus', 0) state.sidebar.opened = false state.sidebar.withoutAnimation = withoutAnimation }, SELECT_VIEW: (state, viewId) => { state.monitor.viewId = viewId; }, TOGGLE_INDEX_EDIT: (state, editor) => { state.monitor.editor = editor; } } const actions = { toggleSideBar({ commit }) { commit('TOGGLE_SIDEBAR') }, closeSideBar({ commit }, { withoutAnimation }) { commit('CLOSE_SIDEBAR', withoutAnimation) }, selectView({ commit }, viewId) { commit('SELECT_VIEW', viewId) }, toggleIndexEdit({ commit }, editor) { commit('TOGGLE_INDEX_EDIT', editor) }, } export default { namespaced: true, state, mutations, actions }
<!-- 菜单-->
<template> <el-container> <div class="controlPanel-sidebar" width="205px"> <div class="main-title" v-if="!isCollapse"><div class="title">监控云平台</div></div> <div class="title-icon" v-if="isCollapse" style="width:60px;">></div> <el-scrollbar wrap-class="scrollbar-wrapper"> <el-menu class="el-menu-vertical-demo" :default-active="$route.path" @open="handleOpen" @close="handleClose" :collapse="isCollapse" :router=true :unique-opened=true background-color="rgb(32,34,42)" text-color="rgba(255, 255, 255, 0.8)" active-text-color="#fff"> <el-submenu v-for="(item, index) in menuData" :key="index" :index="index+''"> <template slot="title"> <img class="menu-icon" :src="require(`../assets/img/${item.meta.icon}`)"/> <span slot="title">{{item.meta.title}}</span> </template> <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path"> <span style="display: inline-block;margin-left: 2vmin;">{{child.meta.title}}</span> </el-menu-item> </el-submenu> </el-menu> </el-scrollbar> </div> <el-container class="controlPanel-mainbar"> <el-header> <Navbar></Navbar> </el-header> <el-main> <el-scrollbar style="height:100%"> <keep-alive> <router-view :key="key" v-if="!$route.meta.noCache"></router-view> </keep-alive> <router-view v-if="$route.meta.noCache"></router-view> </el-scrollbar> </el-main> </el-container> </el-container> </template> <script> import {mapGetters} from 'vuex' // import Item from '@/components/layout/Item' import Navbar from '@/components/layout/Navbar' export default { name: 'home', components: { // Item, Navbar }, data() { return { menuData: [] }; }, computed: { ...mapGetters(['sidebar']), isCollapse() { return !this.sidebar.opened }, key() { return this.$route.path; } }, mounted() { this.initMenu(); }, methods: { initMenu() { for (let i in this.$router.options.routes) { let root = this.$router.options.routes[i] if (root.hidden) continue let children = [] for (let j in root.children) { let item = root.children[j] if (item.hidden) continue children.push(item) } if (children.length < 1) continue this.menuData.push(root) root.children = children } }, menuChange(index, indexPath) { console.log(index, indexPath) this.$router.push({ path: index }) }, handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); } } } </script> <style lang="scss"> .controlPanel-sidebar { height: 100vh; background: #0B1433; font-family: "Microsoft YaHei"; .main-title { width: 100%; height: 8vmin; line-height: 8vmin; background: #2041B5; .title { text-align: center; font-weight: 300; font-size: 20px; color: white; } } .title-icon { background: #2041B5; width: 219px; height: 8vmin; display: block; text-align: center; font-size: 44px; font-weight: bold; color: #43E5FF; } .el-scrollbar{ height: calc(100% - 8vmin); .el-scrollbar__wrap { overflow-x: hidden; } } .el-menu { border-right: none; .menu-icon { display: inline-block; width: 20px; height:20px; margin-right: 2vmin; } } .el-menu-vertical-demo { // width: 205px; min-height: 100%; height: 100%; .barstyle { width: 4px; background: #409EFF; height: 50px; float: left; margin-left: -40px; display: none; } .el-menu-item:hover { background: #202B50 !important; color: #fff !important; i { color: #fff !important; } .barstyle { display: block; } } .el-menu-item.is-active { background: #202B50 !important; .barstyle { display: block; } } .el-submenu i, span { color: rgba(255, 255, 255, 0.8) !important; } .el-menu-item, .el-submenu__title { background: #0B1433 !important; } .el-submenu .el-submenu__title:hover { color: #fff; background: #202B50 !important; } .el-submenu .el-submenu__title.is-active { background: #202B50; } } .el-menu-vertical-demo:not(.el-menu--collapse) { width: 205px; } .el-menu--collapse { width: 60px; } } .el-menu--vertical { left: 60px !important; .el-menu--popup { background: #202B50 !important; } .el-menu-item:focus, .el-menu-item:hover { background: #202B50 !important; color: #00B1FF !important; } .el-menu-item { background: #202B50 !important; } .el-menu--popup { padding: 0 !important; } .el-menu--popup-right-start { margin-left: 0 !important; } } .controlPanel-mainbar { padding: 0px; height: 100vh; .el-header { background: #17203D; height: 8vmin; line-height: 8vmin; } .el-main { background: #121B39; /*padding: 0;*/ .el-scrollbar__wrap { overflow-x: hidden; } } } </style>