admin-menu.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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">双困生培训系统</span>
  8. </div>
  9. </el-col>
  10. <el-col :span="24">
  11. <el-scrollbar style="height:100vh; overflow-x: hidden;">
  12. <el-menu mode="vertical" :show-timeout="200" background-color="#00142a" text-color="hsla(0, 0%, 100%, .65)"
  13. active-text-color="#409EFF" :unique-opened="true" :default-active="defualtActive">
  14. <menu-item :menus="menu" :level="0"></menu-item>
  15. </el-menu>
  16. </el-scrollbar>
  17. </el-col>
  18. </el-row>
  19. </div>
  20. </template>
  21. <script>
  22. import menuItem from './menu/menu-item.vue';
  23. import * as menus from '@frame/config/menu-config';
  24. import scrollBar from './scrollBar.vue';
  25. import _ from 'lodash';
  26. import { mapState, createNamespacedHelpers } from 'vuex';
  27. const { mapActions: userMenu } = createNamespacedHelpers('userMenu');
  28. export default {
  29. name: 'admin-menu',
  30. props: {},
  31. components: {
  32. // scrollBar,
  33. menuItem,
  34. },
  35. data: () => ({
  36. menu: [],
  37. project: 'center',
  38. }),
  39. created() { },
  40. computed: {
  41. ...mapState(['user', 'defaultOption']),
  42. project_modules() {
  43. return process.env.VUE_APP_MODULE;
  44. },
  45. defualtActive() {
  46. return this.$route.path;
  47. },
  48. },
  49. mounted() {
  50. let arr = _.get(menus, 'menu', []); //this.project_modules
  51. // let r = this.filterMenu(_.cloneDeep(arr), this.project_modules);
  52. // this.$set(this, `menu`, r);
  53. },
  54. methods: {
  55. ...userMenu(['getMenu']),
  56. selectMenu(path, modules) {
  57. if (this.project_modules === modules) this.$router.push({ path: path });
  58. },
  59. filterMenu(menus, umod) {
  60. let nm = menus.map(menu => {
  61. //mod 不存在:检查下面每一子项是否有限制
  62. //mod 存在:检查是否符合要求,符合,检查子项;不符合,略过
  63. let mod = _.get(menu, 'module');
  64. if ((mod && mod.includes(umod)) || !mod) {
  65. let children = _.get(menu, 'children');
  66. if (children) {
  67. menu.children = this.filterMenu(children, umod);
  68. }
  69. return menu;
  70. }
  71. });
  72. return _.compact(nm);
  73. },
  74. async getUserMenu() {
  75. this.requestMenu();
  76. // const sessionMenu = sessionStorage.getItem('userMenu');
  77. // if (sessionMenu) {
  78. // this.$set(this, `menu`, JSON.parse(sessionMenu));
  79. // } else {
  80. // this.requestMenu();
  81. // }
  82. },
  83. async requestMenu() {
  84. const { type, id: userid } = this.user;
  85. const condition = { project: 'center', type, userid };
  86. const res = await this.getMenu(condition);
  87. if (this.$checkRes(res)) {
  88. this.$set(this, `menu`, res.data);
  89. sessionStorage.setItem('userMenu', JSON.stringify(res.data));
  90. }
  91. },
  92. },
  93. watch: {
  94. user: {
  95. deep: true,
  96. immediate: true,
  97. handler(val) {
  98. if (this.menu.length > 0) return;
  99. if (val) {
  100. const { type, id } = val;
  101. if (type && id) this.getUserMenu();
  102. }
  103. },
  104. },
  105. },
  106. };
  107. </script>
  108. <style lang="less" scoped>
  109. .logo {
  110. display: flex;
  111. justify-content: center;
  112. align-items: center;
  113. height: 4rem;
  114. line-height: 4rem;
  115. background: #002140;
  116. color: #fff;
  117. text-align: center;
  118. font-size: 1.1rem;
  119. font-weight: 600;
  120. overflow: hidden;
  121. }
  122. .site-name {
  123. margin-left: 0.325rem;
  124. }
  125. .sidebar-container {
  126. box-shadow: 0.125rem 0 0.375rem rgba(0, 21, 41, 0.35);
  127. transition: width 0.28s;
  128. width: 12rem !important;
  129. height: 100%;
  130. position: fixed;
  131. top: 0;
  132. bottom: 0;
  133. left: 0;
  134. z-index: 1001;
  135. overflow: hidden;
  136. a {
  137. display: inline-block;
  138. width: 100%;
  139. }
  140. .el-menu {
  141. padding-top: 1rem;
  142. width: 100% !important;
  143. border: none;
  144. }
  145. }
  146. /deep/ .el-scrollbar__wrap {
  147. overflow-x: hidden;
  148. }
  149. </style>