Эх сурвалжийг харах

登录localStorage储存info

huang_an 2 жил өмнө
parent
commit
2ffc3c6fd3
1 өөрчлөгдсөн 11 нэмэгдсэн , 10 устгасан
  1. 11 10
      src/store/modules/user.js

+ 11 - 10
src/store/modules/user.js

@@ -57,25 +57,26 @@ export default {
   },
   mutations: {
     // 设置登录用户的信息
-    setUserInfo (state, info) {
+    setUserInfo(state, info) {
+      localStorage.setItem('info', JSON.stringify(info));
       state.info = info;
     },
     // 设置登录用户的菜单
-    setMenus (state, menus) {
+    setMenus(state, menus) {
       state.menus = menus;
     },
     // 设置登录用户的权限
-    setAuthorities (state, authorities) {
+    setAuthorities(state, authorities) {
       // console.log(authorities,'authorities')
-      state.authorities = authorities
+      state.authorities = authorities;
       // sessionStorage['authorities']=JSON.stringify(authorities.map(item=>item.permissionCode))
     },
     // 设置登录用户的权限路由
-    setAuthoritiesRouter (state, authoritiesRouter) {
+    setAuthoritiesRouter(state, authoritiesRouter) {
       state.authoritiesRouter = authoritiesRouter;
     },
     // 设置登录用户的角色
-    setRoles (state, roles) {
+    setRoles(state, roles) {
       state.roles = roles;
     }
   },
@@ -113,7 +114,7 @@ export default {
     //   return { menus, homePath };
     // },
     //动态路由
-    async fetchUserInfo ({ commit }) {
+    async fetchUserInfo({ commit }) {
       const result = await getResourcesTree().catch(() => {});
       if (!result) {
         return {};
@@ -164,19 +165,19 @@ export default {
     /**
      * 更新用户信息
      */
-    setInfo ({ commit }, value) {
+    setInfo({ commit }, value) {
       commit('setUserInfo', value);
     },
     /**
      * 更新菜单数据
      */
-    setMenus ({ commit }, value) {
+    setMenus({ commit }, value) {
       commit('setMenus', value);
     },
     /**
      * 更新菜单的badge
      */
-    setMenuBadge ({ commit, state }, { path, value, color }) {
+    setMenuBadge({ commit, state }, { path, value, color }) {
       const menus = formatTreeData(state.menus, (m) => {
         if (path === m.path) {
           return {