Sidebar.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div :class="{'has-logo':showLogo}" class="sidebar-wrapper">
  3. <div class="logo">
  4. <div class="logo-title">代理端管理系统</div>
  5. </div>
  6. <el-scrollbar wrap-class="scrollbar-wrapper">
  7. <el-menu
  8. :default-active="activeMenu"
  9. :router="true"
  10. mode="vertical"
  11. :show-timeout="200"
  12. class="sidebar-el-menu"
  13. >
  14. <template v-for="item in permission_routes">
  15. <el-submenu v-if="item.children&&item.children.length>0" :index="item.path" :key="item.path">
  16. <template slot="title">
  17. <i :class="item.meta&&item.meta.icon||'el-icon-menu'" />
  18. <span>{{item.meta&&item.meta.title||''}}</span>
  19. </template>
  20. <template v-for="child in item.children">
  21. <el-menu-item :index="resolvePath(item.path, child.path)" :key="child.path">
  22. <span>{{child.meta&&child.meta.title||''}}</span>
  23. </el-menu-item>
  24. </template>
  25. </el-submenu>
  26. <el-menu-item v-else :index="item.path" :key="item.path">
  27. <i :class="item.meta&&item.meta.icon||'el-icon-menu'" />
  28. <span>{{item.meta&&item.meta.title||''}}</span>
  29. </el-menu-item>
  30. </template>
  31. </el-menu>
  32. </el-scrollbar>
  33. </div>
  34. </template>
  35. <script>
  36. import { mapGetters } from 'vuex'
  37. import { constantRoutes } from '@/router'
  38. export default {
  39. name: 'Sidebar',
  40. computed: {
  41. ...mapGetters([
  42. 'sidebar'
  43. ]),
  44. permission_routes() {
  45. return constantRoutes.filter(item => !item.hidden)
  46. },
  47. activeMenu() {
  48. const route = this.$route
  49. const { meta, path } = route
  50. if (meta.activeMenu) {
  51. return meta.activeMenu
  52. }
  53. return path
  54. },
  55. showLogo() {
  56. return this.sidebar.opened
  57. }
  58. },
  59. methods: {
  60. resolvePath(parentPath, childPath) {
  61. if (childPath.startsWith('/')) {
  62. return childPath
  63. }
  64. return parentPath + '/' + childPath
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .sidebar-wrapper {
  71. position: fixed;
  72. left: 0;
  73. top: 0;
  74. bottom: 0;
  75. width: 210px;
  76. background: #001529;
  77. z-index: 100;
  78. transition: width 0.28s;
  79. &.collapsed {
  80. width: 54px;
  81. }
  82. }
  83. .logo {
  84. height: 60px;
  85. line-height: 60px;
  86. text-align: center;
  87. background: #002140;
  88. .logo-title {
  89. color: #fff;
  90. font-size: 16px;
  91. font-weight: bold;
  92. }
  93. }
  94. .sidebar-el-menu {
  95. border-right: none;
  96. height: calc(100% - 60px);
  97. .el-menu-item,
  98. .el-submenu__title {
  99. color: rgba(255, 255, 255, 0.7);
  100. height: 46px;
  101. line-height: 46px;
  102. margin: 0 4px;
  103. border-radius: 4px;
  104. &:hover {
  105. background: rgba(255, 255, 255, 0.1);
  106. color: #fff;
  107. }
  108. &.is-active {
  109. background: #1890ff;
  110. color: #fff;
  111. }
  112. }
  113. }
  114. </style>