admin-menu.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div id="admin-menu" style="background-color: rgb(0, 20, 42);">
  3. <el-row>
  4. <el-col :span="24">
  5. <div class="logo">
  6. <img src="https://img.alicdn.com/tfs/TB13UQpnYGYBuNjy0FoXXciBFXa-242-134.png" width="40" />
  7. <span class="site-name">ADMIN LITE</span>
  8. </div>
  9. </el-col>
  10. <el-col :span="24">
  11. <template>
  12. <el-menu
  13. mode="vertical"
  14. :show-timeout="200"
  15. background-color="#00142a"
  16. text-color="hsla(0, 0%, 100%, .65)"
  17. active-text-color="#409EFF"
  18. :unique-opened="true"
  19. :default-active="defualtActive"
  20. >
  21. <scroll-bar>
  22. <menu-item :menus="menu"></menu-item>
  23. </scroll-bar>
  24. </el-menu>
  25. </template>
  26. </el-col>
  27. </el-row>
  28. </div>
  29. </template>
  30. <script>
  31. import menuItem from './menu/menu-item.vue';
  32. import * as menus from '@frame/config/menu-config';
  33. import scrollBar from './scrollBar.vue';
  34. import _ from 'lodash';
  35. export default {
  36. name: 'admin-menu',
  37. props: {},
  38. components: {
  39. scrollBar,
  40. menuItem,
  41. },
  42. data: () => ({
  43. menu: [],
  44. }),
  45. created() {},
  46. computed: {
  47. project_modules() {
  48. return process.env.VUE_APP_MODULE;
  49. },
  50. defualtActive() {
  51. return this.$route.path;
  52. },
  53. },
  54. mounted() {
  55. let arr = _.get(menus, this.project_modules, []);
  56. let r = this.filterMenu(_.cloneDeep(arr), this.project_modules);
  57. this.$set(this, `menu`, r);
  58. },
  59. methods: {
  60. selectMenu(path, modules) {
  61. if (this.project_modules === modules) this.$router.push({ path: path });
  62. },
  63. filterMenu(menus, umod) {
  64. let nm = menus.map(menu => {
  65. //mod 不存在:检查下面每一子项是否有限制
  66. //mod 存在:检查是否符合要求,符合,检查子项;不符合,略过
  67. let mod = _.get(menu, 'module');
  68. if ((mod && mod.includes(umod)) || !mod) {
  69. let children = _.get(menu, 'children');
  70. if (children) {
  71. menu.children = this.filterMenu(children, umod);
  72. }
  73. return menu;
  74. }
  75. });
  76. return _.compact(nm);
  77. },
  78. },
  79. };
  80. </script>
  81. <style lang="less" scoped>
  82. .logo {
  83. display: flex;
  84. justify-content: center;
  85. align-items: center;
  86. height: 4rem;
  87. line-height: 4rem;
  88. background: #002140;
  89. color: #fff;
  90. text-align: center;
  91. font-size: 1.1rem;
  92. font-weight: 600;
  93. overflow: hidden;
  94. }
  95. .site-name {
  96. margin-left: 0.325rem;
  97. }
  98. .sidebar-container {
  99. box-shadow: 0.125rem 0 0.375rem rgba(0, 21, 41, 0.35);
  100. transition: width 0.28s;
  101. width: 12rem !important;
  102. height: 100%;
  103. position: fixed;
  104. top: 0;
  105. bottom: 0;
  106. left: 0;
  107. z-index: 1001;
  108. overflow: hidden;
  109. a {
  110. display: inline-block;
  111. width: 100%;
  112. }
  113. .el-menu {
  114. padding-top: 1rem;
  115. width: 100% !important;
  116. border: none;
  117. }
  118. }
  119. </style>