quwangxin 3 лет назад
Родитель
Сommit
8e6dc39edd
2 измененных файлов с 14 добавлено и 12 удалено
  1. 5 5
      src/store/index.js
  2. 9 7
      src/views/login/index.vue

+ 5 - 5
src/store/index.js

@@ -7,7 +7,7 @@ import getters from './getters';
 import dict from './modules/dict';
 import user from './modules/user';
 import theme from './modules/theme';
-// import createPersistedState from 'vuex-persistedstate';
+import createPersistedState from 'vuex-persistedstate';
 
 Vue.use(Vuex);
 
@@ -22,9 +22,9 @@ export default new Vuex.Store({
   },
   getters,
   plugins: [
-    // createPersistedState({
-    //   storage: window.sessionStorage,
-    //   paths: ['']
-    // })
+    createPersistedState({
+      storage: window.sessionStorage,
+      paths: ['user']
+    })
   ] //会自动保存创建的状态。刷新还在
 });

+ 9 - 7
src/views/login/index.vue

@@ -115,7 +115,7 @@
     // eslint-disable-next-line vue/multi-word-component-names
     name: 'Login',
     components: { I18nIcon },
-    data() {
+    data () {
       return {
         // 登录框方向, 0居中, 1居右, 2居左
         direction: 0,
@@ -135,7 +135,7 @@
     },
     computed: {
       // 表单验证规则
-      rules() {
+      rules () {
         return {
           loginName: [
             {
@@ -156,14 +156,17 @@
         };
       }
     },
-    created() {
+    created () {
       if (getToken()) {
         this.goHome();
+      } else {
+        // 重置菜单权限
+        this.$store.commit('user/setMenus', []);
       }
     },
     methods: {
       /* 提交 */
-      submit() {
+      submit () {
         this.$refs.form.validate((valid) => {
           if (!valid) {
             return false;
@@ -172,7 +175,6 @@
           login(this.form)
             .then((res) => {
               localStorage.setItem('userId', res.data.userId);
-
               // 用户信息
               this.$store.commit('user/setUserInfo', res.data);
               this.loading = false;
@@ -186,11 +188,11 @@
         });
       },
       /* 跳转到首页 */
-      goHome() {
+      goHome () {
         this.$router.push(this.$route?.query?.from ?? '/').catch(() => {});
       },
       /* 更换图形验证码 */
-      changeCaptcha() {
+      changeCaptcha () {
         // 这里演示的验证码是后端返回base64格式的形式, 如果后端地址直接是图片请参考忘记密码页面
         getCaptcha()
           .then((data) => {