HomeSide.vue 4.5 KB

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