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