Kaynağa Gözat

添加权限处理

Michael Wang 6 yıl önce
ebeveyn
işleme
6b0a939313

+ 7 - 8
src/modules/basic/routes/routes.js

@@ -14,7 +14,6 @@ import role_privilege_settings from "../view/role_privilege_settings.vue";
 export default [
   {
     path: "/basic", //基础信息
-    meta: { auth: false },
     component: Home,
     children: [
       {
@@ -23,32 +22,32 @@ export default [
       },
       {
         path: "course", //课程管理
-        meta: { pageName: "课程管理" },
+        meta: { privilegeCodes: "index_course" },
         component: course
       },
       {
         path: "specially", //专业管理
-        meta: { pageName: "专业管理" },
+        meta: { privilegeCodes: "index_specially" },
         component: specially
       },
       {
         path: "school", //学校管理
-        meta: { pageName: "学校管理" },
+        meta: { privilegeCodes: "index_school" },
         component: school
       },
       {
         path: "campus", //学习中心管理
-        meta: { pageName: "学习中心管理" },
+        meta: { privilegeCodes: "index_campus" },
         component: campus
       },
       {
         path: "examSite/:orgId", //考点管理
-        meta: { pageName: "考点管理" },
+        meta: { privilegeCodes: "index_campus" },
         component: examSite
       },
       {
         path: "user", //用户管理
-        meta: { pageName: "用户管理" },
+        meta: { privilegeCodes: "index_user" },
         component: user
       },
       {
@@ -68,7 +67,7 @@ export default [
       },
       {
         path: "role_privilege_settings", //角色权限设置
-        meta: { pageName: "角色权限设置" },
+        meta: { privilegeCodes: "index_role_privilege_settings" },
         component: role_privilege_settings
       }
     ]

+ 0 - 1
src/modules/portal/views/home/HomeSide.vue

@@ -26,7 +26,6 @@
       background-color="#222c32"
       text-color="#fff"
       active-text-color="#409eff"
-      router
       :default-active="$route.path"
       :collapse="isCollapse"
     >

+ 21 - 15
src/router.js

@@ -7,6 +7,7 @@ import MarklRoutes from "./modules/marking/routes/routes";
 import QuestionsRoutes from "./modules/questions/routes/routes";
 import OeRoutes from "./modules/oe/routes/routes";
 import PrintRoutes from "./modules/print/routes/routes";
+import { CORE_API } from "@/constants/constants.js";
 
 Vue.use(Router);
 
@@ -24,20 +25,25 @@ let router = new Router({
   ]
 });
 
-// router.beforeEach((to, from, next) => {
-//   const loginPath = "/login/" + localStorage.getItem("domain");
-//   if (to.path.match(/^\/login\/.+$/)) {
-//     next();
-//   } else {
-//     if (!window.sessionStorage.getItem("token")) {
-//       if (!localStorage.getItem("domain")) {
-//         alert("地址出错,找不到机构!");
-//       }
-//       next({ path: loginPath });
-//     } else {
-//       next();
-//     }
-//   }
-// });
+router.beforeEach((to, from, next) => {
+  if (!to.meta.privilegeCodes) {
+    next();
+  } else {
+    Vue.prototype.$httpWithMsg
+      .post(
+        CORE_API +
+          "/rolePrivilege/checkPrivileges?" +
+          new URLSearchParams({ privilegeCodes: to.meta.privilegeCodes })
+      )
+      .then(response => {
+        if (Object.values(response.data).includes(true)) {
+          next();
+        } else {
+          Vue.prototype.$alert("没有权限访问!", "提示");
+          next(false);
+        }
+      });
+  }
+});
 
 export default router;