sunjh 6 éve
szülő
commit
21b385118a
5 módosított fájl, 75 hozzáadás és 31 törlés
  1. 5 5
      src/components/Home.vue
  2. 1 1
      src/components/Mine.vue
  3. 15 7
      src/components/commons/Header.vue
  4. 1 0
      src/js/index.js
  5. 53 18
      src/main.js

+ 5 - 5
src/components/Home.vue

@@ -88,11 +88,11 @@ export default {
       //   notify('error','用户信息获取失败')
       // })
       this.setUserInfo()
-      if (this.rolesPermissions == null) {
-        let NewPage = '_empty' + '?time=' + new Date().getTime() / 500
-        this.$router.push(NewPage)
-        this.$router.go(-1)
-      }
+      // if (this.rolesPermissions == null) {
+      //   let NewPage = '_empty' + '?time=' + new Date().getTime() / 500
+      //   this.$router.push(NewPage)
+      //   this.$router.go(-1)
+      // }
       this.loadData()
     },
     //加载数据

+ 1 - 1
src/components/Mine.vue

@@ -13,7 +13,7 @@
           <div class="user-banner">
             <p class="head">
               <a href="javascript:;" class="login-link">
-                <img :src="user == null || user.userVO.photo == null?defaultValue.image:user.userVO.photo" class="user-img">
+                <img :src="user == null || user.userVO.photoUrl == null?defaultValue.image:user.userVO.photoUrl" class="user-img">
                 <span class="vertify hide"></span>
               </a>
             </p>

+ 15 - 7
src/components/commons/Header.vue

@@ -75,7 +75,7 @@ export default {
   name: 'header-container',
   data () {
     return {
-      fullScreenLoading: false,
+      fullScreenLoading: true,
       //loading: true,
       openNavBar: false,
       userIdentity: '',
@@ -139,11 +139,11 @@ export default {
         }).catch(error => {
           console.log('用户信息加载失败')
           this.fullScreenLoading = false
-          if (error.status == 401) {
-            notify('warning', error.data)
-          } else {
-            notify('error', error.data)
-          }
+          // if (error.status == 401) {
+          //   notify('warning', error.data)
+          // } else {
+          //   notify('error', error.data)
+          // }
         })
       } else {
         this.fullScreenLoading = false
@@ -151,14 +151,22 @@ export default {
       }
     },
     userLogout () {
-      logout()
       this.isLogin = false
+      logout().then((res) => {
+        this.$router.push({
+          name: 'Index',
+        })
+      })
+
     },
   },
   created () {
   },
   beforeMount () {
     this.setUserInfo()
+    // if (storageGet('user' != null)){
+    //   this.isLogin = true
+    // }
     console.log(this.isLogin)
   }
 }

+ 1 - 0
src/js/index.js

@@ -87,6 +87,7 @@ export const getRolesPermissions = (roleList) => {
 
 export const logout = () => {
   sessionStorage.removeItem('user')
+  sessionStorage.removeItem('rolesPermission')
   return Http.get(Apis.USER.LOGOUT)
 }
 

+ 53 - 18
src/main.js

@@ -5,7 +5,8 @@ import App from './App'
 import router from './router'
 import 'font-awesome/css/font-awesome.css'
 import './style/main.scss'
-import {getAuthUrls} from '@/js/index'
+import {getAuthUrls, getCurrentUser, getRolesPermissions, storageGet, storageSave} from '@/js/index'
+import {notify} from '@/constants/index'
 import {
   Avatar,
   Button,
@@ -54,26 +55,60 @@ import {
 
 router.beforeEach((to, from, next) => {
   const urls = getAuthUrls()
-  //console.log(to.matched[0].path)
-  //console.log(urls.includes(to.matched[0].path))
-  if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
-    //console.log('需要登录')
-    if (sessionStorage.userName === '2' && urls.includes(to.matched[0].path)) { // 判断缓存里面是否有 userName  //在登录的时候设置它的值
-      //console.log('未拦截')
-      next()
+  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 {
-      //console.log('拦截')
-      next({
-        path: '/',
-        query: {
-          redirect: to.fullPath
-        } // 将跳转的路由path作为参数,登录成功后跳转到该路由
-      })
+      next()
     }
-  } else {
-    //console.log('不需要登录')
-    next()
   }
+  //console.log(to.matched[0].path)
+  //console.log(urls.includes(to.matched[0].path))
+
 })
 
 // require('./mock.js')