HomeSide.vue 4.8 KB

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