Переглянути джерело

improvement: 跳转逻辑完善

ChenYangfan 6 роки тому
батько
коміт
43c90dad07

+ 9 - 7
src/App.vue

@@ -17,7 +17,7 @@ import GlobalMessage from '@/components/Basic/GlobalMessage'
 import SlideUpTransition from '@/animations/SlideUpTransition'
 import { mapState } from 'vuex'
 import userType, { userTypeNaming } from '@/enums/user-type'
-// import { jumpToLogin } from '@/server/auth'
+import { jumpToLogin } from '@/server/auth'
 import { SET_TOKEN, SET_USER_INFO } from '@/store/types/main-types'
 import { getUserInfo } from '@/server/user'
 
@@ -47,7 +47,7 @@ export default {
     }, (error) => {
       if (error.response.status === 401 && this.$route.matched.some(record => record.meta.roles)) {
         // this.$router.push({ name: 'login' })
-        // jumpToLogin()
+        jumpToLogin()
       }
       return Promise.reject(error)
     })
@@ -86,16 +86,18 @@ export default {
   },
   methods: {
     fetchUserInfo () {
-      setTimeout(() => {
-        getUserInfo().then(res => {
-          this.$store.commit(SET_USER_INFO, { userInfo: res })
+      getUserInfo().then(res => {
+        this.$store.commit(SET_USER_INFO, { userInfo: res })
+        if (this.$route.path === '/') {
           if (res.role === userType.student) {
             this.$router.push({ name: 'student-explore' })
           } else {
             this.$router.push({ name: 'teacher-explore' })
           }
-        }).catch(err => this.$setErrorMessage(err.response.data.msg))
-      }, 5000)
+        } else {
+          this.$router.push({ name: this.$route.name })
+        }
+      }).catch(err => this.$setErrorMessage(err.response.data.msg))
     }
   }
 }

+ 2 - 0
src/config/server-info.js

@@ -77,3 +77,5 @@ export {
   useSlideServer,
   useUserServer
 }
+
+export const portal = 'http://p.seecoder.cn'

+ 1 - 5
src/router/main.js

@@ -16,8 +16,4 @@
 //   component: () => import(/* webpackChunkName: "main" */ '@/views/forget-password/ForgetPassword.vue')
 // }]
 
-export default [{
-  path: '/role',
-  name: 'role',
-  component: () => import(/* webpackChunkName: "main" */ '@/views/login/ToRoleHomePage.vue')
-}]
+export default []

+ 2 - 3
src/server/auth.js

@@ -1,13 +1,12 @@
 /**
  * 统一认证登录相关接口
  */
-
-const portal = 'http://p.seecoder.cn'
+import { portal } from '@/config/server-info'
 
 export const getLoginUrl = () => {
   const location = window.location
   return `${portal}/api/interaction?client_id=seec-helper&redirect_uri=${encodeURIComponent(
-    location.origin + '/'
+    location.href
   )}&scope=openid`
 }
 

+ 0 - 38
src/views/login/ToRoleHomePage.vue

@@ -1,38 +0,0 @@
-<template>
-  <div class="no-content-warning">
-    正在跳转...
-  </div>
-</template>
-
-<script>
-import { mapState } from 'vuex'
-import userType from '@/enums/user-type'
-
-export default {
-  computed: {
-    ...mapState({
-      userInfo: state => state.main.userInfo
-    })
-  },
-  watch: {
-    userInfo: {
-      handler() {
-        if (this.userInfo.role === userType.student) {
-          this.$router.push({ name: 'student-explore' })
-        } else {
-          this.$router.push({ name: 'teacher-explore' })
-        }
-      }
-    }
-  }
-}
-</script>
-
-<style lang="scss" scoped>
-.no-content-warning {
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  height: 100vh;
-}
-</style>