Ver Fonte

修改权限

zhaoke há 2 anos atrás
pai
commit
458f66a37c

+ 2 - 8
src/permission.js

@@ -26,19 +26,13 @@ router.beforeEach(async (to, from, next) => {
       next({ path: '/' })
       NProgress.done()
     } else {
-      const hasGetUserInfo = store.getters.name
-      if (hasGetUserInfo) {
+      const hasRoles = store.getters.roles && store.getters.roles.length > 0
+      if (hasRoles) {
         next()
       } else {
         try {
           const { roles } = await store.dispatch('user/getInfo')
           const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
-          // if (roles && roles.length) {
-          //   router.addRoutes(accessRoutes)
-          // } else {
-          //   const noRoutes = [accessRoutes[0]]
-          //   router.addRoutes(noRoutes)
-          // }
           router.addRoutes(accessRoutes)
           next({ ...to, replace: true })
         } catch (error) {

+ 1 - 1
src/router/routes/routes-file-five.js

@@ -41,7 +41,7 @@ const departureRoutes = {
             },
             {
               path: '/departure/flightView',
-              name: 'DepartureTwo',
+              name: 'DepartureParentSem',
               component: () => import('@/views/baggageManagement'),
               meta: { title: '航班视图', keepAlive: true },
               children: [

+ 5 - 5
src/router/routes/routes-file-one.js

@@ -138,7 +138,7 @@ const BasicsDataRoutes = {
 
 const departureRoutesC = {
   path: '/departureC',
-  name: 'departureC',
+  name: 'departureCParent',
   component: Layout,
   meta: { roles: ['departure_menu_tmp'] },
   children: [
@@ -153,7 +153,7 @@ const departureRoutesC = {
       children: [
         {
           path: '/departureC',
-          name: 'DepartureOne',
+          name: 'DepartureParent',
           component: () => import('@/views/baggageManagement'),
           meta: {
             title: '离港视图',
@@ -164,7 +164,7 @@ const departureRoutesC = {
           children: [
             {
               path: '/departureC',
-              name: 'DepartureTerminalView',
+              name: 'departureC',
               component: () => import('@/views/baggageManagement/components/departureC'),
               meta: { keepAlive: true }
             },
@@ -176,13 +176,13 @@ const departureRoutesC = {
               children: [
                 {
                   path: '/departureC/flightView',
-                  name: 'DepartureFlightView',
+                  name: 'departureCFlightView',
                   component: () => import('@/views/baggageManagement/components/departureC/flight'),
                   meta: { keepAlive: true }
                 },
                 {
                   path: '/departureC/baggageView',
-                  name: 'DepartureBaggageView',
+                  name: 'departureCBaggageView',
                   component: () => import('@/views/baggageManagement/components/departureC/baggage'),
                   meta: { title: '行李视图', keepAlive: true }
                 }

+ 63 - 17
src/store/modules/user.js

@@ -1,7 +1,7 @@
 import { login, loginUp } from '@/api/newLogin'
 import { getToken, setToken, removeToken, setUserId, TokenKey } from '@/utils/auth'
 import { resetRouter } from '@/router'
-
+import { Query } from '@/api/dataIntegration'
 const getDefaultState = () => {
   return {
     token: getToken(),
@@ -58,9 +58,10 @@ const actions = {
         commit('SET_TOKEN', token)
         commit('SET_UserType', 1)
         commit('SET_UserId', userid)
-        sessionStorage.setItem("userName", userInfo.username);
+        setToken("userName", userInfo.username);
         setToken(TokenKey, token)
         setUserId(userid)
+        setToken('userid', userid)
         // let nowDate = new Date();
         // let oldDate = new Date(date);
         // let diffTime = oldDate - nowDate;
@@ -77,21 +78,65 @@ const actions = {
   // get user info
   getInfo ({ commit, state }) {
     return new Promise((resolve, reject) => {
-
-      let data = {
-        roles: state.userPoewrList,
-        introduction: '',
-        avatar: '',
-        name: sessionStorage.getItem("userName"),
-        token: state.token
-      }
-
-      const { name, avatar, roles } = data
-
-      commit('SET_NAME', name)
-      commit('SET_AVATAR', avatar)
-      commit('SET_ROLES', roles ? roles : ['admin'])
-      resolve(data)
+      Query({
+        id: DATACONTENT_ID.loginId,
+        dataContent: [getToken('userid')]
+      }).then(res => {
+        if (res.code == 0) {
+          const { listValues } = res.returnData
+          const datas = listValues
+          if (datas && datas.length) {
+            const arrs = [];
+            for (const item of datas) {
+              if (item.ident) {
+                arrs.push(item.ident);
+              }
+            }
+            // arrs.push('transit');
+            sessionStorage.setItem('userAuthList', JSON.stringify(arrs));
+            setTimeout(() => {
+              const data = {
+                roles: arrs,
+                introduction: '',
+                avatar: '',
+                name: getToken("userName"),
+                token: state.token
+              }
+
+              const { name, avatar, roles } = data
+
+              commit('SET_NAME', name)
+              commit('SET_AVATAR', avatar)
+              commit('SET_ROLES', roles ? roles : ['admin'])
+              commit('SET_UserPoewrList', roles ? roles : ['admin'])
+              resolve(data)
+            }, 100);
+          } else {
+            sessionStorage.setItem('userAuthList', []);
+            setTimeout(() => {
+              const data = {
+                roles: state.userPoewrList,
+                introduction: '',
+                avatar: '',
+                name: getToken("userName"),
+                token: state.token
+              }
+
+              const { name, avatar, roles } = data
+
+              commit('SET_NAME', name)
+              commit('SET_AVATAR', avatar)
+              commit('SET_ROLES', roles ? roles : ['admin'])
+              commit('SET_UserPoewrList', roles ? roles : ['admin'])
+              resolve(data)
+            }, 100);
+          }
+        } else {
+          reject(res.returnData)
+        }
+      }).catch(err => {
+        reject(err)
+      })
     })
   },
 
@@ -106,6 +151,7 @@ const actions = {
         removeToken(); // must remove  token  first
         removeToken('codeToken');
         removeToken('systemSet');
+        removeToken('userid');
         resetRouter();
         commit('RESET_STATE');
         commit('SET_ROLES', [])

+ 50 - 38
src/views/login/index.vue

@@ -179,46 +179,58 @@ export default {
           };
           this.$store
             .dispatch("user/login", params)
-            .then(() => {
+            .then(async () => {
               this.$store.dispatch("app/toggleOutcheck", false);
               sessionStorage.setItem("userName", params.username);
-              setTimeout(() => {
-                const UserId = this.$store.getters.UserId;
-                // const UserType = this.$store.getters.UserType;
-                Query({
-                  id: DATACONTENT_ID.loginId,
-                  dataContent: [UserId]
-                }).then(res => {
-                  if (res.code == 0) {
-                    //res.returnData.push('account_menu');
-                    const { listValues } = res.returnData
-                    const datas = listValues
-                    if (datas && datas.length) {
-                      const arrs = [];
-                      for (const item of datas) {
-                        if (item.ident) {
-                          arrs.push(item.ident);
-                        }
-                      }
-                      // arrs.push('transit');
-                      sessionStorage.setItem('userAuthList', JSON.stringify(arrs));
-                      this.$store.dispatch('user/setPowerList', arrs);
-                    } else {
-                      sessionStorage.setItem('userAuthList', []);
-                      this.$store.dispatch('user/setPowerList', []);
-                    }
-                    this.$router.push({ path: this.redirect || "/" });
-                  } else {
-                    this.loading = false;
-                    this.$store.dispatch("user/logout");
-                    this.$message.error('当前用户获取权限失败,请联系管理员');
-                  }
-                }).catch(err => {
-                  this.loading = false;
-                  this.$store.dispatch("user/logout");
-                  this.$message.error('当前用户获取权限失败,请联系管理员');
-                })
-              }, 100);
+              this.$router.push({ path: this.redirect || "/" });
+              // try {
+              //   const { roles } = await this.$store.dispatch('user/getInfo')
+              //   if (roles && roles.length) {
+              //     this.$router.push({ path: this.redirect || "/" });
+              //   } else {
+              //     this.$store.dispatch("user/logout");
+              //     this.$message.error('当前用户获取权限失败,请联系管理员');
+              //   }
+              // } catch (error) {
+              //   this.$store.dispatch("user/logout");
+              //   this.$message.error('当前用户获取权限失败,请联系管理员');
+              // }
+              // setTimeout(async () => {
+              // const UserType = this.$store.getters.UserType;
+              // Query({
+              //   id: DATACONTENT_ID.loginId,
+              //   dataContent: [UserId]
+              // }).then(res => {
+              //   if (res.code == 0) {
+              //     //res.returnData.push('account_menu');
+              //     const { listValues } = res.returnData
+              //     const datas = listValues
+              //     if (datas && datas.length) {
+              //       const arrs = [];
+              //       for (const item of datas) {
+              //         if (item.ident) {
+              //           arrs.push(item.ident);
+              //         }
+              //       }
+              //       // arrs.push('transit');
+              //       sessionStorage.setItem('userAuthList', JSON.stringify(arrs));
+              //       this.$store.dispatch('user/setPowerList', arrs);
+              //     } else {
+              //       sessionStorage.setItem('userAuthList', []);
+              //       this.$store.dispatch('user/setPowerList', []);
+              //     }
+              //     this.$router.push({ path: this.redirect || "/" });
+              //   } else {
+              //     this.loading = false;
+              //     this.$store.dispatch("user/logout");
+              //     this.$message.error('当前用户获取权限失败,请联系管理员');
+              //   }
+              // }).catch(err => {
+              //   this.loading = false;
+              //   this.$store.dispatch("user/logout");
+              //   this.$message.error('当前用户获取权限失败,请联系管理员');
+              // })
+              // }, 100);
               this.loading = false;
             })
             .catch(() => {