yusheng 1 rok pred
rodič
commit
9ca0464130

+ 4 - 2
src/layout/components/header-tools.vue

@@ -97,6 +97,8 @@ import { logout } from '@/utils/page-tab-util';
 import { userLogout } from '@/api/system/user';
 import { userLogout } from '@/api/system/user';
 import xyy from '@/assets/xyy.jpg';
 import xyy from '@/assets/xyy.jpg';
 import router from '@/router/index';
 import router from '@/router/index';
+import { getCurrentUser,setCurrentUser } from '@/utils/token-util';
+
 export default {
 export default {
   components: { HeaderNotice, PasswordModal, SettingDrawer, I18nIcon },
   components: { HeaderNotice, PasswordModal, SettingDrawer, I18nIcon },
   props: {
   props: {
@@ -119,7 +121,7 @@ export default {
     };
     };
   },
   },
   created() {
   created() {
-    this.currentUser = JSON.parse(sessionStorage['currentUser']);
+    this.currentUser = getCurrentUser()
     this.groupId =  this.currentUser.currentGroupId;
     this.groupId =  this.currentUser.currentGroupId;
     this.roleId =  this.currentUser.currentRoleId;
     this.roleId =  this.currentUser.currentRoleId;
   },
   },
@@ -147,7 +149,7 @@ export default {
       this.roleId = val;
       this.roleId = val;
       this.currentUser.currentGroupId = this.groupId;
       this.currentUser.currentGroupId = this.groupId;
       this.currentUser.currentRoleId = val;
       this.currentUser.currentRoleId = val;
-      sessionStorage['currentUser']=JSON.stringify(this.currentUser)
+      setCurrentUser(this.currentUser)
       this.$store
       this.$store
         .dispatch('user/fetchUserInfo')
         .dispatch('user/fetchUserInfo')
         .then(({ menus, homePath, authoritiesRouter }) => {
         .then(({ menus, homePath, authoritiesRouter }) => {

+ 2 - 3
src/router/index.js

@@ -8,7 +8,7 @@ import { WHITE_LIST, REDIRECT_PATH, LAYOUT_PATH } from '@/config/setting';
 import store from '@/store';
 import store from '@/store';
 import { statistics } from '@/api/bpm/components/inspectionManage';
 import { statistics } from '@/api/bpm/components/inspectionManage';
 import { getTodoTaskPage } from '@/api/bpm/task';
 import { getTodoTaskPage } from '@/api/bpm/task';
-import { getToken, setToken } from '@/utils/token-util';
+import { getToken, setToken, getCurrentUser  } from '@/utils/token-util';
 import { routes, getMenuRoutes } from './routes';
 import { routes, getMenuRoutes } from './routes';
 import { SYSTEM_NAME } from '@/config/setting';
 import { SYSTEM_NAME } from '@/config/setting';
 import { getLoginUser } from '@/api/login';
 import { getLoginUser } from '@/api/login';
@@ -106,8 +106,7 @@ router.afterEach((to) => {
   }
   }
 });
 });
 router.roleChange = async ({ menus, homePath, authoritiesRouter }) => {
 router.roleChange = async ({ menus, homePath, authoritiesRouter }) => {
-  const currentUser = JSON.parse(sessionStorage['currentUser']);
-
+  const currentUser = getCurrentUser()
   if (menus && menus.length > 0) {
   if (menus && menus.length > 0) {
     router.addRoute(
     router.addRoute(
       getMenuRoutes([...menus, ...authoritiesRouter], homePath)
       getMenuRoutes([...menus, ...authoritiesRouter], homePath)

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

@@ -6,6 +6,7 @@ import { USER_MENUS } from '@/config/setting';
 import { getResourcesTree } from '@/api/layout';
 import { getResourcesTree } from '@/api/layout';
 import { SYSTEM_NAME } from '@/config/setting';
 import { SYSTEM_NAME } from '@/config/setting';
 import Vue from 'vue';
 import Vue from 'vue';
+import { getCurrentUser,setCurrentUser } from '@/utils/token-util';
 
 
 const formatRouter = (list) => {
 const formatRouter = (list) => {
   let menuList = []; // menuType
   let menuList = []; // menuType
@@ -111,7 +112,7 @@ export default {
     //   return { menus, homePath };
     //   return { menus, homePath };
     // },
     // },
     async fetchUserInfo({ commit}) {
     async fetchUserInfo({ commit}) {
-      let currentUser=JSON.parse(sessionStorage['currentUser'])
+      let currentUser = getCurrentUser()
       const result = await getResourcesTree({groupId:currentUser.currentGroupId,roleId:currentUser.currentRoleId}).catch(() => {});
       const result = await getResourcesTree({groupId:currentUser.currentGroupId,roleId:currentUser.currentRoleId}).catch(() => {});
       const list = result?.filter((i) => i.path === '/page-wt');
       const list = result?.filter((i) => i.path === '/page-wt');
       if (!list?.length) {
       if (!list?.length) {

+ 2 - 1
src/utils/page-tab-util.js

@@ -4,7 +4,7 @@
 import store from '@/store';
 import store from '@/store';
 import router from '@/router';
 import router from '@/router';
 import { Message } from 'element-ui';
 import { Message } from 'element-ui';
-import { removeToken } from '@/utils/token-util';
+import { removeToken,removeCurrentUser } from '@/utils/token-util';
 import { setDocumentTitle } from '@/utils/document-title-util';
 import { setDocumentTitle } from '@/utils/document-title-util';
 import {
 import {
   HOME_PATH,
   HOME_PATH,
@@ -239,6 +239,7 @@ export function goHomeRoute(from) {
  */
  */
 export function logout(route, from) {
 export function logout(route, from) {
   removeToken();
   removeToken();
+  removeCurrentUser();
   if (route) {
   if (route) {
     router.push({
     router.push({
       path: '/login',
       path: '/login',

+ 33 - 0
src/utils/token-util.js

@@ -30,6 +30,32 @@ export function setToken(token, remember) {
   }
   }
 }
 }
 
 
+/**
+ * 获取缓存的 当前登陆角色
+ */
+export function getCurrentUser() {
+  let currentUser = sessionStorage.getItem('currentUser');
+  if (!currentUser) {
+    currentUser = localStorage.getItem('currentUser');
+  }
+  return JSON.parse(currentUser);
+}
+
+/**
+ * 缓存 当前登陆角色
+ * @param token token
+ * @param remember 是否永久存储
+ */
+export function setCurrentUser(currentUser, remember) {
+  removeCurrentUser()
+  if (currentUser) {
+    if (remember) {
+      localStorage.setItem('currentUser', JSON.stringify(currentUser));
+    } else {
+      sessionStorage.setItem('currentUser', JSON.stringify(currentUser));
+    }
+  }
+}
 /**
 /**
  * 移除 token
  * 移除 token
  */
  */
@@ -37,3 +63,10 @@ export function removeToken() {
   localStorage.removeItem(TOKEN_STORE_NAME);
   localStorage.removeItem(TOKEN_STORE_NAME);
   sessionStorage.removeItem(TOKEN_STORE_NAME);
   sessionStorage.removeItem(TOKEN_STORE_NAME);
 }
 }
+/**
+ * 移除 currentUser
+ */
+export function removeCurrentUser() {
+  localStorage.removeItem('currentUser');
+  sessionStorage.removeItem('currentUser');
+}

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

@@ -111,6 +111,7 @@ import I18nIcon from '@/layout/components/i18n-icon.vue';
 import { getToken } from '@/utils/token-util';
 import { getToken } from '@/utils/token-util';
 import { login, getCaptcha, sub } from '@/api/login';
 import { login, getCaptcha, sub } from '@/api/login';
 import { getPathAddress } from '@/api/system/file';
 import { getPathAddress } from '@/api/system/file';
+import { setCurrentUser } from '@/utils/token-util';
 import xyy from '@/assets/xyy.jpg';
 import xyy from '@/assets/xyy.jpg';
 export default {
 export default {
   // eslint-disable-next-line vue/multi-word-component-names
   // eslint-disable-next-line vue/multi-word-component-names
@@ -185,12 +186,15 @@ export default {
             localStorage.setItem('userId', res.data.userId);
             localStorage.setItem('userId', res.data.userId);
             // 用户信息
             // 用户信息
             if (res.data?.loginChangeGroupVOList.length > 0) {
             if (res.data?.loginChangeGroupVOList.length > 0) {
-              sessionStorage['currentUser'] = JSON.stringify({
-                currentGroupId: res.data.loginChangeGroupVOList[0].groupId,
-                currentRoleId:
-                  res.data.loginChangeGroupVOList[0].loginChangeRoleVOList[0]
-                    .roleId
-              });
+              setCurrentUser(
+                  {
+                    currentGroupId: res.data.loginChangeGroupVOList[0].groupId,
+                    currentRoleId:
+                      res.data.loginChangeGroupVOList[0]
+                        .loginChangeRoleVOList[0].roleId
+                  },
+                  this.form.remember
+                );
             }
             }
             const filePath = await getPathAddress();
             const filePath = await getPathAddress();
             res.data.avatarAddress =
             res.data.avatarAddress =