guhongwei 4 年之前
父節點
當前提交
bf758b6687
共有 1 個文件被更改,包括 14 次插入1 次删除
  1. 14 1
      src/router/index.js

+ 14 - 1
src/router/index.js

@@ -502,7 +502,7 @@ const router = new VueRouter({
 });
 
 router.beforeEach(async (to, form, next) => {
-  if (to.name == 'account_user' || to.name == 'viewTwo_account') {
+  if (to.name == 'account_user') {
     let res = await store.dispatch('login/toGetUser');
     if (res && res.uid) {
       next();
@@ -514,6 +514,19 @@ router.beforeEach(async (to, form, next) => {
         next();
       } else {
         next({ name: 'login' });
+      }
+    }
+  } else if (to.name == 'viewTwo_account') {
+    let res = await store.dispatch('login/toGetUser');
+    if (res && res.uid) {
+      next();
+    } else {
+      let key = sessionStorage.getItem('token');
+      let user = jwt.decode(key);
+      if (user && user.uid) {
+        store.commit('setUser', user, { root: true });
+        next();
+      } else {
         next({ name: 'twoLogin' });
       }
     }