Selaa lähdekoodia

Merge branch 'dev' of licailing/wenlvju into master

licailing 5 vuotta sitten
vanhempi
commit
b97d5f5f72
2 muutettua tiedostoa jossa 17 lisäystä ja 16 poistoa
  1. 11 9
      src/main/h5/src/router/index.js
  2. 6 7
      src/main/h5/src/store/index.js

+ 11 - 9
src/main/h5/src/router/index.js

@@ -92,15 +92,20 @@ const router = new VueRouter({
 });
 });
 
 
 router.beforeEach((to, from, next) => {
 router.beforeEach((to, from, next) => {
+  let exports = ["ROLE_EXPERT", "ROLE_DISTRICT_STAFF"];
+  let exportsInfo = store.state.roles.find(item => {
+    return exports.includes(item);
+  });
+  let inspectors = ["ROLE_SUPERVISOR"];
+  let inspectorsInfo = store.state.roles.find(item => {
+    return inspectors.includes(item);
+  });
   if (!store.state.userInfo && to.path !== "/login" && to.meta.checkLogin) {
   if (!store.state.userInfo && to.path !== "/login" && to.meta.checkLogin) {
     store
     store
       .dispatch("getUserInfo")
       .dispatch("getUserInfo")
       .then(() => {
       .then(() => {
         if (to.name === "inspectorList") {
         if (to.name === "inspectorList") {
-          if (
-            store.state.role === "ROLE_EXPERT" ||
-            store.state.role === "ROLE_DISTRICT_STAFF"
-          ) {
+          if (exportsInfo) {
             next("/expertList");
             next("/expertList");
           } else {
           } else {
             next();
             next();
@@ -114,12 +119,9 @@ router.beforeEach((to, from, next) => {
         next("/login");
         next("/login");
       });
       });
   } else if (store.state.userInfo && to.name === "inspectorList") {
   } else if (store.state.userInfo && to.name === "inspectorList") {
-    if (store.state.role === "ROLE_SUPERVISOR") {
+    if (inspectorsInfo) {
       next();
       next();
-    } else if (
-      store.state.role === "ROLE_EXPERT" ||
-      store.state.role === "ROLE_DISTRICT_STAFF"
-    ) {
+    } else if (exportsInfo) {
       next("/expertList");
       next("/expertList");
     }
     }
   } else if (!to.matched.length) {
   } else if (!to.matched.length) {

+ 6 - 7
src/main/h5/src/store/index.js

@@ -7,14 +7,14 @@ Vue.use(Vuex);
 export default new Vuex.Store({
 export default new Vuex.Store({
   state: {
   state: {
     userInfo: null,
     userInfo: null,
-    role: "ROLE_USER"
+    roles: ["ROLE_USER"]
   },
   },
   mutations: {
   mutations: {
     updateUserInfo(state, userInfo) {
     updateUserInfo(state, userInfo) {
       state.userInfo = userInfo;
       state.userInfo = userInfo;
     },
     },
-    updateRole(state, role) {
-      state.role = role;
+    updateRoles(state, roles) {
+      state.roles = roles;
     }
     }
   },
   },
   actions: {
   actions: {
@@ -22,11 +22,10 @@ export default new Vuex.Store({
       return http.axios
       return http.axios
         .get("/user/my")
         .get("/user/my")
         .then(res => {
         .then(res => {
-          res.data.authorities.forEach(item => {
-            if (item.name !== "ROLE_USER") {
-              content.commit("updateRole", item.name);
-            }
+          let roles = res.data.authorities.map(item => {
+            return item.name;
           });
           });
+          content.commit("updateRoles", roles);
 
 
           content.commit("updateUserInfo", res.data);
           content.commit("updateUserInfo", res.data);
           return Promise.resolve();
           return Promise.resolve();