Browse Source

处理登录token30分钟失效问题

liurongli 1 month ago
parent
commit
b5000cfcca
1 changed files with 10 additions and 9 deletions
  1. 10 9
      src/views/login/login.vue

+ 10 - 9
src/views/login/login.vue

@@ -67,17 +67,18 @@ export default {
         if (event.origin !== window.location.origin) {
           return
         }
-        if(getToken() && schoolType){
-          const currentPath = sessionStorage.getItem('student_currentPath');//获取当前进入的路由
-          const directUrl = currentPath?currentPath:'/jointStudentAnalysisReport/list';
-          this.$router.push({ path: directUrl })
-          return
-        }
         if (event.data.type === 'STU_TOKEN') {
-          const userInfo = event.data.userInfo
-          // console.log('打印用户信息', userInfo)
+          const userInfo = event.data.userInfo;
+          const tokenValue = userInfo.tokenValue;
+          const oldToken = getToken(); 
+          if(oldToken && oldToken === tokenValue && schoolType){
+            const currentPath = sessionStorage.getItem('student_currentPath');//获取当前进入的路由
+            const directUrl = currentPath?currentPath:'/jointStudentAnalysisReport/list';
+            this.$router.push({ path: directUrl })
+            return
+          }
           this.$store.dispatch('user/CLEAR_LOCAL_STORAGE') //清空本地存储
-          setToken(userInfo.tokenValue)
+          setToken(tokenValue)
           sessionStorage.setItem('schoolType', schoolType || 2) //1:单校 2:联校// 暂时写死单校   线上还是单校的
           this.$store.dispatch('user/SET_TOKEN', userInfo.tokenValue)
           this.$store.dispatch('user/SET_SCHOOL_LOGO', userInfo.schoolLogoUrl) //设置学校logo