Browse Source

Merge branch 'jump' into dev

# Conflicts:
#	src/views/exam/ExamPane.vue
ChengYuXuan 5 years ago
parent
commit
34c4bdf276
3 changed files with 41 additions and 27 deletions
  1. 11 4
      src/router/index.ts
  2. 13 16
      src/views/Home.vue
  3. 17 7
      src/views/exam/ExamPane.vue

+ 11 - 4
src/router/index.ts

@@ -5,6 +5,7 @@ import exam from '@/router/exam'
 import teacher from '@/router/teacher'
 import store from '@/store/index'
 import { jumpToLogin } from '@/api/axios.config'
+import { getUserInfo } from '@/api/user'
 Vue.use(VueRouter)
 
 const routes: Array<RouteConfig> = [
@@ -28,11 +29,17 @@ router.beforeEach((to, from, next) => {
   const { id_token } = to.query
   if (id_token) {
     store.commit('setToken', id_token)
+    getUserInfo().then(({ data }) => {
+      store.commit('setUser', data.result)
+      next()
+    })
+  } else {
+    if (!store.getters.isLogin) {
+      jumpToLogin()
+    } else {
+      next()
+    }
   }
-  if (!store.getters.isLogin) {
-    jumpToLogin()
-  }
-  next()
 })
 
 export default router

+ 13 - 16
src/views/Home.vue

@@ -13,7 +13,7 @@ export default Vue.extend({
     return {}
   },
   computed: {
-    ...mapGetters(['isStudent', 'isTeacher'])
+    ...mapGetters(['isStudent', 'isTeacher', 'isLogin'])
   },
   methods: {
     ...mapMutations(['setToken', 'setUser'])
@@ -27,23 +27,20 @@ export default Vue.extend({
   //   next()
   // },
   mounted() {
-    getUserInfo()
-      .then(({ data }) => {
-        this.setUser(data.result)
-        if (this.isStudent) {
-          this.$router.push({
-            name: 'student'
-          })
-        }
-        if (this.isTeacher) {
-          this.$router.push({
-            name: 'teacher'
-          })
-        }
+    if (!this.isLogin) {
+      jumpToLogin()
+    }
+
+    if (this.isStudent) {
+      this.$router.push({
+        name: 'student'
       })
-      .catch(() => {
-        jumpToLogin()
+    }
+    if (this.isTeacher) {
+      this.$router.push({
+        name: 'teacher'
       })
+    }
   }
 })
 </script>

+ 17 - 7
src/views/exam/ExamPane.vue

@@ -335,7 +335,12 @@ export default Vue.extend({
     leaveExam() {
       // 离开考试暂时不清除本地存储
       this.exitDialog = false
-      this.$router.push({ name: 'Home' })
+      let redirect_uri = this.$route.query.redirect_uri ?? ''
+      if (redirect_uri) {
+        window.location.href = decodeURI(redirect_uri as string)
+      } else {
+        this.$router.push({ name: 'Home' })
+      }
     },
     submitAnswer() {
       this.submitDialog = false
@@ -346,12 +351,17 @@ export default Vue.extend({
           // 交卷后清除本地存储
           this.clearLocalStorage()
           setTimeout(() => {
-            this.$router.push({
-              name: 'result',
-              params: {
-                examId: this.examId.toString()
-              }
-            })
+            let redirect_uri = this.$route.query.redirect_uri ?? ''
+            if (redirect_uri) {
+              window.location.href = decodeURIComponent(redirect_uri as string)
+            } else {
+              this.$router.push({
+                name: 'result',
+                params: {
+                  examId: this.examId.toString()
+                }
+              })
+            }
           }, 1000)
         })
         .catch(() => {