Pārlūkot izejas kodu

feat: 超管权限调整

zhangjie 9 mēneši atpakaļ
vecāks
revīzija
d4d4bf271d

+ 3 - 3
src/assets/styles/home.scss

@@ -602,6 +602,7 @@
         }
 
         &.is-link {
+          cursor: pointer;
           &::after {
             display: block;
           }
@@ -609,7 +610,6 @@
 
         &.is-link:hover {
           color: $--color-primary;
-          cursor: pointer;
 
           &::after {
             color: $--color-primary;
@@ -617,10 +617,10 @@
         }
 
         &.is-disabled {
-          color: #8c8c8c;
+          color: #8c8c8c !important;
           cursor: not-allowed;
           &::after {
-            color: #8c8c8c;
+            color: #8c8c8c !important;
           }
         }
       }

+ 5 - 44
src/modules/admin/views/Admin.vue

@@ -88,7 +88,7 @@
 </template>
 
 <script>
-import localNavs from "@/constants/adminNavs";
+import { mapState } from "vuex";
 import { SYS_ADMIN_NAME } from "@/constants/enumerate";
 import { logout } from "@/modules/login/api";
 import ResetPwd from "../../base/components/ResetPwd";
@@ -101,8 +101,6 @@ export default {
     const user = this.$ls.get("user", { id: "", realName: "", roleList: [] });
 
     return {
-      menus: [],
-      privileges: [],
       curRouteName: "",
       curSubMenuNames: [],
       breadcrumbs: [],
@@ -114,6 +112,9 @@ export default {
       },
     };
   },
+  computed: {
+    ...mapState("app", ["menus", "privileges"]),
+  },
   watch: {
     $route(val) {
       if (val.name === "Admin") return;
@@ -137,52 +138,12 @@ export default {
   },
   methods: {
     initData() {
-      this.privileges = localNavs;
-      this.menus = this.getMenu();
       this.curSubMenuNames = this.menus.map((item) => item.url);
-
-      if (this.$route.name === "Admin") {
-        const firstRouteName = this.getFirstRouter();
-        this.$router.replace({
-          name: firstRouteName,
-        });
-        return;
-      }
-
       this.actCurNav();
     },
-    getFirstRouter() {
-      let childNavs = this.privileges;
-      let firstRouteName = "";
-      while (childNavs.length) {
-        firstRouteName = childNavs[0].url;
-        childNavs = this.privileges.filter(
-          (item) => item.parentId === childNavs[0].id
-        );
-      }
-
-      return firstRouteName;
-    },
-    getMenu() {
-      let menus = this.privileges.filter((item) => item.parentId === "-1");
-      const toTree = (menus) => {
-        menus.forEach((menu) => {
-          const children = this.privileges.filter(
-            (item) => item.parentId === menu.id
-          );
-          if (children.length) {
-            menu.children = children;
-            toTree(menu.children);
-          }
-        });
-      };
-      toTree(menus);
-
-      return menus;
-    },
     actCurNav() {
       this.curRouteName = this.$route.name;
-      let breadcrumbs = [];
+      const breadcrumbs = [];
       let curBreadcrumb = this.privileges.find(
         (item) => item.url === this.curRouteName
       );

+ 32 - 4
src/router.js

@@ -1,6 +1,7 @@
 import Vue from "vue";
 import Router from "vue-router";
 import store from "./store";
+import { SYS_ADMIN_NAME } from "@/constants/enumerate";
 
 import Home from "./views/Home.vue";
 import HomePage from "./views/home-page/HomePage.vue";
@@ -81,7 +82,7 @@ const router = new Router({
     ...tool,
     {
       path: "*",
-      name: "404",
+      name: "NotFound",
       component: NotFound,
       meta: {
         noRequire: true,
@@ -99,6 +100,13 @@ const router = new Router({
   ],
 });
 
+function getRouteType(routeMatched) {
+  const typeData = routeMatched.find(
+    (item) => item.name === "Home" || item.name === "Admin"
+  );
+  return typeData ? typeData.name : null;
+}
+
 // route interceptor
 router.beforeEach(async (to, from, next) => {
   const token = Vue.ls.get("token");
@@ -128,12 +136,32 @@ router.beforeEach(async (to, from, next) => {
     return;
   }
 
-  if (!store.state.app.privileges.length) {
-    await store.dispatch("app/updatePrivilegeMap");
+  const fromType = getRouteType(from.matched);
+  const toType = getRouteType(to.matched);
+  // 只有超管才可访问Admin
+  const isSuperAdmin =
+    Vue.ls.get("user", { loginName: "" }).loginName === SYS_ADMIN_NAME;
+  if (toType === "Admin" && !isSuperAdmin) {
+    next({ name: "NotFound" });
+    return;
   }
 
+  if (!store.state.app.privileges.length || fromType !== toType) {
+    if (toType === "Home") {
+      await store.dispatch("app/updatePrivilegeMap", isSuperAdmin);
+    } else if (toType === "Admin") {
+      store.dispatch("app/updateAdminPrivilegeMap");
+    } else {
+      store.commit("app/initStore");
+    }
+  }
+
+  // console.log(fromType, toType);
+  // console.log(store.state.app.validRoutes);
+  // console.log(to.name);
+
   if (!store.state.app.validRoutes.includes(to.name)) {
-    next({ name: "404" });
+    next({ name: "NotFound" });
     return;
   }
 

+ 14 - 4
src/store/app.js

@@ -1,6 +1,7 @@
 import { sysMenu } from "../modules/login/api";
 import staticMenu from "../constants/staticMenu";
 // import localMenus from "../constants/menus-data";
+import adminNavs from "../constants/adminNavs";
 
 const state = {
   privilegeMap: {},
@@ -60,7 +61,7 @@ function getMenu(privileges) {
   };
 
   const menus = getChildren("-1");
-  const validRoutes = ["Home"];
+  const validRoutes = [];
   const toTree = (menus) => {
     menus.forEach((menu) => {
       const children = getChildren(menu.id);
@@ -78,15 +79,24 @@ function getMenu(privileges) {
 }
 
 const actions = {
-  async updatePrivilegeMap({ state, dispatch }) {
+  async updatePrivilegeMap({ state }, isSuperAdmin) {
     const data = await sysMenu();
     // const data = { privileges: localMenus };
-    const privileges = [...staticMenu, ...data.privileges];
+    // 超管进入学校页面不显示首页
+    const privileges = isSuperAdmin
+      ? data.privileges
+      : [...staticMenu, ...data.privileges];
     state.privilegeMap = getPrivilegeMap(privileges);
     state.privileges = transformMenu(privileges);
     const { validRoutes, menus } = getMenu(state.privileges);
     state.menus = menus;
-    state.validRoutes = validRoutes;
+    state.validRoutes = [...validRoutes, "Home"];
+  },
+  updateAdminPrivilegeMap({ state }) {
+    state.privileges = adminNavs;
+    const { validRoutes, menus } = getMenu(state.privileges);
+    state.menus = menus;
+    state.validRoutes = [...validRoutes, "Admin"];
   },
 };
 

+ 24 - 24
src/views/home-page/HomeGuide.vue

@@ -7,7 +7,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('createQuestion'),
+              'is-disabled': !guideAuthentic('createQuestion'),
               'is-link': checkIsLink('createQuestion'),
             }"
             @click="guideLink('createQuestion')"
@@ -16,7 +16,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('createPaper'),
+              'is-disabled': !guideAuthentic('createPaper'),
               'is-link': checkIsLink('createPaper'),
             }"
             @click="guideLink('createPaper')"
@@ -25,7 +25,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('buildPaper'),
+              'is-disabled': !guideAuthentic('buildPaper'),
               'is-link': checkIsLink('buildPaper'),
             }"
             @click="guideLink('buildPaper')"
@@ -43,7 +43,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('uploadPaper'),
+              'is-disabled': !guideAuthentic('uploadPaper'),
               'is-link': checkIsLink('uploadPaper'),
             }"
             @click="guideLink('uploadPaper')"
@@ -52,7 +52,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('createCard'),
+              'is-disabled': !guideAuthentic('createCard'),
               'is-link': checkIsLink('createCard'),
             }"
             @click="guideLink('createCard')"
@@ -61,7 +61,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('selectApproveUser'),
+              'is-disabled': !guideAuthentic('selectApproveUser'),
               'is-link': checkIsLink('selectApproveUser'),
             }"
             @click="guideLink('selectApproveUser')"
@@ -78,7 +78,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('print'),
+              'is-disabled': !guideAuthentic('print'),
               'is-link': checkIsLink('print'),
             }"
           >
@@ -86,7 +86,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('cardScan'),
+              'is-disabled': !guideAuthentic('cardScan'),
               'is-link': checkIsLink('cardScan'),
             }"
           >
@@ -103,7 +103,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('markSetting'),
+              'is-disabled': !guideAuthentic('markSetting'),
               'is-link': checkIsLink('markSetting'),
             }"
             @click="guideLink('markSetting')"
@@ -115,7 +115,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('markProgress'),
+              'is-disabled': !guideAuthentic('markProgress'),
               'is-link': checkIsLink('markProgress'),
             }"
             @click="guideLink('markProgress')"
@@ -124,7 +124,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('markTaskDetail'),
+              'is-disabled': !guideAuthentic('markTaskDetail'),
               'is-link': checkIsLink('markTaskDetail'),
             }"
             @click="guideLink('markTaskDetail')"
@@ -136,7 +136,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('scoreCheck'),
+              'is-disabled': !guideAuthentic('scoreCheck'),
               'is-link': checkIsLink('scoreCheck'),
             }"
             @click="guideLink('scoreCheck')"
@@ -148,7 +148,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('markResultCheck'),
+              'is-disabled': !guideAuthentic('markResultCheck'),
               'is-link': checkIsLink('markResultCheck'),
             }"
           >
@@ -156,7 +156,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('overMark'),
+              'is-disabled': !guideAuthentic('overMark'),
               'is-link': checkIsLink('overMark'),
             }"
             @click="guideLink('overMark')"
@@ -174,7 +174,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('scoreView'),
+              'is-disabled': !guideAuthentic('scoreView'),
               'is-link': checkIsLink('scoreView'),
             }"
             @click="guideLink('scoreView')"
@@ -183,7 +183,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('reportView'),
+              'is-disabled': !guideAuthentic('reportView'),
               'is-link': checkIsLink('reportView'),
             }"
             @click="guideLink('reportView')"
@@ -192,7 +192,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('exportScore'),
+              'is-disabled': !guideAuthentic('exportScore'),
               'is-link': checkIsLink('exportScore'),
             }"
             @click="guideLink('exportScore')"
@@ -212,7 +212,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('setAnalysisBlue'),
+              'is-disabled': !guideAuthentic('setAnalysisBlue'),
               'is-link': checkIsLink('setAnalysisBlue'),
             }"
             @click="guideLink('setAnalysisBlue')"
@@ -221,7 +221,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('analysisReport'),
+              'is-disabled': !guideAuthentic('analysisReport'),
               'is-link': checkIsLink('analysisReport'),
             }"
             @click="guideLink('analysisReport')"
@@ -236,7 +236,7 @@
         <ul class="guide-menus">
           <li
             :class="{
-              'is-diabled': !guideAuthentic('trainingPlan'),
+              'is-disabled': !guideAuthentic('trainingPlan'),
               'is-link': checkIsLink('trainingPlan'),
             }"
             @click="guideLink('trainingPlan')"
@@ -245,7 +245,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('courseTarget'),
+              'is-disabled': !guideAuthentic('courseTarget'),
               'is-link': checkIsLink('courseTarget'),
             }"
             @click="guideLink('courseTarget')"
@@ -254,7 +254,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('evaluationMode'),
+              'is-disabled': !guideAuthentic('evaluationMode'),
               'is-link': checkIsLink('evaluationMode'),
             }"
             @click="guideLink('evaluationMode')"
@@ -263,7 +263,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('targetScore'),
+              'is-disabled': !guideAuthentic('targetScore'),
               'is-link': checkIsLink('targetScore'),
             }"
             @click="guideLink('targetScore')"
@@ -272,7 +272,7 @@
           </li>
           <li
             :class="{
-              'is-diabled': !guideAuthentic('targetStatistics'),
+              'is-disabled': !guideAuthentic('targetStatistics'),
               'is-link': checkIsLink('targetStatistics'),
             }"
             @click="guideLink('targetStatistics')"