HomeSide.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <el-aside width="200px" v-if="menuList.length > 0">
  3. <div
  4. style="height: 50px; margin-top: 20px; margin-left: 20px; font-size: 20px"
  5. >
  6. <i class="el-icon-location"></i> <span>{{ group.name }}</span>
  7. </div>
  8. <el-menu
  9. class="el-menu-vertical-demo"
  10. background-color="#545c64"
  11. text-color="#fff"
  12. active-text-color="#ffd04b"
  13. >
  14. <el-submenu
  15. v-for="menu1 in menuList1"
  16. :key="menu1.id"
  17. :index="menu1.nodeCode"
  18. >
  19. <template slot="title">
  20. <router-link v-if="menu1.ext5" :to="{ path: menu1.ext5 }">
  21. <i class="fa fa-circle-o"></i> {{ menu1.name }}
  22. </router-link>
  23. <span v-else>{{ menu1.name }}</span>
  24. </template>
  25. <el-menu-item-group>
  26. <el-menu-item
  27. v-for="menu2 in menuList2(menu1)"
  28. :index="menu2.nodeCode"
  29. :key="menu2.id"
  30. >
  31. <router-link :to="{ path: menu2.ext5 }">
  32. <i class="fa fa-circle-o"></i> {{ menu2.name }}
  33. </router-link>
  34. </el-menu-item>
  35. </el-menu-item-group>
  36. </el-submenu>
  37. </el-menu>
  38. </el-aside>
  39. </template>
  40. <script>
  41. import { mapState } from "vuex";
  42. import { CORE_API } from "@/constants/constants";
  43. const routesToMenu = [
  44. {
  45. path: "/basic",
  46. name: "基础信息",
  47. groupCode: "BASIC_MENUS"
  48. },
  49. {
  50. path: "/examwork",
  51. name: "考务管理",
  52. groupCode: "EXAM_WORK_MENUS"
  53. },
  54. {
  55. path: "/questions",
  56. name: "题库",
  57. groupCode: "QUESTIONS_WORK_MENUS"
  58. },
  59. {
  60. path: "/oe",
  61. name: "网考",
  62. groupCode: "NETEXAM_WORK_MENUS"
  63. },
  64. {
  65. path: "/marking",
  66. name: "阅卷",
  67. groupCode: "MARK_WORK_MENUS"
  68. },
  69. {
  70. path: "/portal",
  71. groupCode: "PORTAL_MENUS"
  72. },
  73. {
  74. path: "/print",
  75. name: "印刷管理",
  76. groupCode: "PRINT_MENUS"
  77. }
  78. ];
  79. import { mapMutations } from "vuex";
  80. import { UPDATE_CURRENT_PATHS } from "../../store/currentPaths";
  81. export default {
  82. name: "HomeSide",
  83. data() {
  84. return {
  85. group: null,
  86. menuList: []
  87. };
  88. },
  89. computed: {
  90. ...mapState({ user: state => state.user }),
  91. menuList1() {
  92. return this.menuList.filter(
  93. m => m.parentId === null && m.ext1 === "menu"
  94. );
  95. }
  96. },
  97. methods: {
  98. ...mapMutations([UPDATE_CURRENT_PATHS]),
  99. async getUserPrivileges(groupCode) {
  100. var url = CORE_API + "/rolePrivilege/getUserPrivileges";
  101. const params = new URLSearchParams();
  102. params.append("groupCode", groupCode);
  103. params.append("full", false);
  104. const res = await this.$httpWithMsg.post(url, params, {
  105. headers: { "content-type": "application/x-www-form-urlencoded" }
  106. });
  107. return res.data;
  108. },
  109. menuList2(menu1) {
  110. return this.menuList.filter(
  111. m => m.parentId === menu1.id && m.ext1 === "menu"
  112. );
  113. },
  114. updatePath() {
  115. let currentPaths = [];
  116. let part = this.menuList.find(v => v.ext5 === this.$route.path);
  117. if (!part) {
  118. this.UPDATE_CURRENT_PATHS([]);
  119. return;
  120. }
  121. currentPaths.unshift(part.name);
  122. while (this.menuList.find(v => v.id === part.parentId)) {
  123. part = this.menuList.find(v => v.id === part.parentId);
  124. currentPaths.unshift(part.name);
  125. }
  126. console.log(currentPaths);
  127. this.UPDATE_CURRENT_PATHS(currentPaths);
  128. }
  129. },
  130. async created() {
  131. this.group = routesToMenu.find(v => this.$route.path.startsWith(v.path));
  132. const groupCode = this.group && this.group.groupCode;
  133. if (groupCode) {
  134. this.menuList = await this.getUserPrivileges(groupCode);
  135. this.updatePath();
  136. }
  137. },
  138. watch: {
  139. $route() {
  140. this.updatePath();
  141. }
  142. }
  143. };
  144. </script>
  145. <style scoped>
  146. .el-menu-vertical-demo {
  147. height: calc(100vh - 60px - 70px);
  148. }
  149. .el-aside {
  150. background-color: #545c64;
  151. color: #fff;
  152. }
  153. </style>