2213980799@qq.com 1 год назад
Родитель
Сommit
91dce5e6bf
4 измененных файлов с 40 добавлено и 34 удалено
  1. 17 10
      src/layout/components/header-tools.vue
  2. 15 19
      src/router/index.js
  3. 2 1
      src/store/modules/user.js
  4. 6 4
      src/views/login/index.vue

+ 17 - 10
src/layout/components/header-tools.vue

@@ -106,12 +106,17 @@ export default {
       // 是否显示主题设置抽屉
       settingVisible: false,
       groupId: '',
-      roleId: ''
+      roleId: '',
+      currentUser: {
+        currentGroupId: '',
+        currentRoleId: ''
+      }
     };
   },
   created() {
-    this.groupId = this.$store.state.user?.info.currentGroupId;
-    this.roleId = this.$store.state.user?.info.currentRoleId;
+    this.currentUser = JSON.parse(sessionStorage['currentUser']);
+    this.groupId = this.currentUser.currentGroupId;
+    this.roleId = this.currentUser.currentRoleId;
   },
 
   computed: {
@@ -135,14 +140,16 @@ export default {
       this.roleChange(this.loginChangeRoleVOList[0].roleId);
     },
     roleChange(val) {
+    
       this.roleId = val;
-      let userInfo=this.$store.state.user?.info
-      userInfo.currentGroupId=this.groupId
-      userInfo.currentRoleId=val
-      this.$store.dispatch('user/fetchUserInfo').then(({ menus, homePath, authoritiesRouter })=>{
-        router.roleChange({ menus, homePath, authoritiesRouter })
-      });
-      
+      this.currentUser.currentGroupId = this.groupId;
+      this.currentUser.currentRoleId = val;
+      sessionStorage['currentUser'] = JSON.stringify(this.currentUser);
+      this.$store
+        .dispatch('user/fetchUserInfo')
+        .then(({ menus, homePath, authoritiesRouter }) => {
+          router.roleChange({ menus, homePath, authoritiesRouter });
+        });
     },
     /* 用户信息下拉点击事件 */
     onUserDropClick(command) {

+ 15 - 19
src/router/index.js

@@ -83,32 +83,28 @@ router.afterEach((to) => {
     }, 200);
   }
 });
-router.roleChange = ({ menus, homePath, authoritiesRouter }) => {
+router.roleChange = async ({ menus, homePath, authoritiesRouter }) => {
+  const currentUser = JSON.parse(sessionStorage['currentUser']);
+
   if (menus && menus.length > 0) {
     router.addRoute(
       getMenuRoutes([...menus, ...authoritiesRouter], homePath)
     );
-    if (router.currentRoute.path == (menus[0].redirect || menus[0].path)) {
-      changeRole({ groupId: store.state.user.info.currentGroupId, roleId: store.state.user.info.currentRoleId }).then(res => {
-        setToken(res)
-        setTimeout(() => {
-          window.location.reload()
-        }, 100);
-      })
-    } else {
-      router.replace({
+    if (router.currentRoute.path != (menus[0].redirect || menus[0].path)) {
+      await router.replace({
         path: menus[0].redirect || menus[0].path,
-      }).then(res => {
-        changeRole({ groupId: store.state.user.info.currentGroupId, roleId: store.state.user.info.currentRoleId }).then(res => {
-          setToken(res)
-          setTimeout(() => {
-            window.location.reload()
-          }, 100);
-        })
-
       })
     }
-
+   
+    const newToken = await changeRole({ groupId: currentUser.currentGroupId, roleId: currentUser.currentRoleId })
+    setToken(newToken)
+    setTimeout(() => {
+      ['vuex-eos','vuex-wt','vuex-aps','vuex-mes','vuex-eam','vuex-pro','vuex-fm','vuex-main-data','vuex-wms'].forEach((key) => {
+        sessionStorage.removeItem(key);
+      });
+      window.location.reload()
+     
+    }, 100);
   }
 
   // next({ ...to, replace: true });

+ 2 - 1
src/store/modules/user.js

@@ -128,7 +128,8 @@ export default {
     // },
     //动态路由
     async fetchUserInfo({ commit, state }) {
-      const result = await getResourcesTree({ groupId: state.info.currentGroupId, roleId: state.info.currentRoleId }).catch(() => { });
+      let currentUser = JSON.parse(sessionStorage['currentUser'])
+      const result = await getResourcesTree({ groupId: currentUser.currentGroupId, roleId: currentUser.currentRoleId }).catch(() => { });
       if (!result) {
         return {};
       }

+ 6 - 4
src/views/login/index.vue

@@ -197,10 +197,12 @@ export default {
             localStorage.setItem('userId', res.data.userId);
             // 用户信息
             if (res.data?.loginChangeGroupVOList.length > 0) {
-              res.data['currentGroupId'] =
-                res.data.loginChangeGroupVOList[0].groupId;
-              res.data['currentRoleId'] =
-                res.data.loginChangeGroupVOList[0].loginChangeRoleVOList[0].roleId;
+              sessionStorage['currentUser'] = JSON.stringify({
+                currentGroupId: res.data.loginChangeGroupVOList[0].groupId,
+                currentRoleId:
+                  res.data.loginChangeGroupVOList[0].loginChangeRoleVOList[0]
+                    .roleId
+              });
             }
             const filePath = await getPathAddress();
             res.data.avatarAddress =