Browse Source

释放注释

guo00guo 5 years ago
parent
commit
509792de94
2 changed files with 63 additions and 63 deletions
  1. 62 62
      src/main.js
  2. 1 1
      src/pages/Homepage/Homepage.vue

+ 62 - 62
src/main.js

@@ -78,68 +78,68 @@ function getCurrentUserSuccess(res){
 //   var s = document.getElementsByTagName("script")[0];
 //   s.parentNode.insertBefore(hm, s);
 // })();
-// router.beforeEach((to, from, next) => {
-//   // if (_hmt) {
-//   //   if (to.path) {
-//   //     _hmt.push(['_trackPageview', '/#' + to.fullPath]);
-//   //   }
-//   // }
-//   const urls = getAuthUrls()
-//   if (storageGet('user') == null) {
-//     getCurrentUser().then((res) => {
-//       storageSave('user', res)
-//       storageSave('rolesPermissions', getRolesPermissions(res.roleList))
-//       if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
-//         if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
-//           next()
-//         } else {
-//           next({
-//             path: '/',
-//             query: {
-//               redirect: to.fullPath
-//             } // 将跳转的路由path作为参数,登录成功后跳转到该路由
-//           })
-//         }
-//       } else {
-//         next()
-//       }
-//     }).catch((error) => {
-//       // notify('warning', '请登录')
-//       if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
-//         if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
-//           next()
-//         } else {
-//           next({
-//             path: '/',
-//             query: {
-//               redirect: to.fullPath
-//             } // 将跳转的路由path作为参数,登录成功后跳转到该路由
-//           })
-//         }
-//       } else {
-//         next()
-//       }
-//     })
-//   } else {
-//     if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
-//       if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
-//         next()
-//       } else {
-//         next({
-//           path: '/',
-//           query: {
-//             redirect: to.fullPath
-//           } // 将跳转的路由path作为参数,登录成功后跳转到该路由
-//         })
-//       }
-//     } else {
-//       next()
-//     }
-//   }
-//   //console.log(to.matched[0].path)
-//   //console.log(urls.includes(to.matched[0].path))
-//
-// })
+router.beforeEach((to, from, next) => {
+  // if (_hmt) {
+  //   if (to.path) {
+  //     _hmt.push(['_trackPageview', '/#' + to.fullPath]);
+  //   }
+  // }
+  const urls = getAuthUrls()
+  if (storageGet('user') == null) {
+    getCurrentUser().then((res) => {
+      storageSave('user', res)
+      storageSave('rolesPermissions', getRolesPermissions(res.roleList))
+      if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
+        if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
+          next()
+        } else {
+          next({
+            path: '/',
+            query: {
+              redirect: to.fullPath
+            } // 将跳转的路由path作为参数,登录成功后跳转到该路由
+          })
+        }
+      } else {
+        next()
+      }
+    }).catch((error) => {
+      // notify('warning', '请登录')
+      if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
+        if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
+          next()
+        } else {
+          next({
+            path: '/',
+            query: {
+              redirect: to.fullPath
+            } // 将跳转的路由path作为参数,登录成功后跳转到该路由
+          })
+        }
+      } else {
+        next()
+      }
+    })
+  } else {
+    if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
+      if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
+        next()
+      } else {
+        next({
+          path: '/',
+          query: {
+            redirect: to.fullPath
+          } // 将跳转的路由path作为参数,登录成功后跳转到该路由
+        })
+      }
+    } else {
+      next()
+    }
+  }
+  //console.log(to.matched[0].path)
+  //console.log(urls.includes(to.matched[0].path))
+
+})
 
 // require('./mock.js')
 Vue.use(Carousel)

+ 1 - 1
src/pages/Homepage/Homepage.vue

@@ -54,7 +54,7 @@
           </el-row>
         </el-col>
         <el-col :span="5" class="homepage-right-modules">
-<!--          <LoginCard/>-->
+          <LoginCard/>
           <HotCrowd :applicationTypeRank="homeDataNoCache.applicationTypeRank"/>
           <HotAgency :agencyRank="homeDataNoCache.agencyRank"/>
           <HotUser :userRank="homeDataNoCache.userRank"/>