guhongwei 4 lat temu
rodzic
commit
f620084930

+ 2 - 2
src/store/index.js

@@ -29,8 +29,8 @@ import notice from '@frame/store/notice';
 import task from '@frame/store/task';
 import groupscore from '@frame/store/groupscore';
 import personalscore from '@frame/store/personalscore';
-import * as ustate from '@frame/store/user/state';
-import * as umutations from '@frame/store/user/mutations';
+import * as ustate from './user/state';
+import * as umutations from './user/mutations';
 import * as dostate from '@frame/store/setting/state';
 import * as domutations from '@frame/store/setting/mutations';
 Vue.use(Vuex);

+ 21 - 0
src/store/user/mutations.js

@@ -0,0 +1,21 @@
+export const setUser = (state, payload) => {
+  let res = true;
+  //登陆时
+  if (payload) state.user = payload;
+  else {
+    //已经登陆,切换路由时取出用户信息放在总store中
+    let user = sessionStorage.getItem('user');
+    if (user) state.user = JSON.parse(user);
+    else {
+      res = false;
+      state.user = undefined;
+      console.warn('用户未登录');
+    }
+  }
+  return res;
+};
+
+export const deleteUser = (state, payload) => {
+  state.user = {};
+  sessionStorage.removeItem('user');
+};

+ 1 - 0
src/store/user/state.js

@@ -0,0 +1 @@
+export const user = {};

+ 1 - 1
src/views/index.vue

@@ -105,7 +105,7 @@ export default {
       let token = this.$route.query.token;
       let user = jwt.decode(token);
       this.$set(this, 'userinfo', user);
-      localStorage.setItem('user', JSON.stringify(user));
+      sessionStorage.setItem('user', JSON.stringify(user));
     },
   },
   computed: {

+ 1 - 1
src/views/login.vue

@@ -22,7 +22,7 @@ export default {
     });
     let token = this.$route.query.token;
     let user = jwt.decode(token);
-    localStorage.setItem('user', JSON.stringify(user));
+    sessionStorage.setItem('user', JSON.stringify(user));
     this.$toast.clear();
     if (!this.is_dev) this.toIndex();
   },