浏览代码

第三方登录处理06201619

shiyu 3 年之前
父节点
当前提交
aef37a44f9
共有 4 个文件被更改,包括 26 次插入12 次删除
  1. 3 1
      src/api/common.js
  2. 4 1
      src/views/index.vue
  3. 8 0
      src/views/mainPage.vue
  4. 11 10
      src/views/page/pageMenu.vue

+ 3 - 1
src/api/common.js

@@ -31,4 +31,6 @@ export default {
 }
 
 //10.15.12.74:7001/simulation/oauth/client/sign/single?code=1001&ticket=1001
-//10.12.10.74:7001/simulation/oauth/client/sign/single?code=1001&ticket=1001
+//10.12.10.70/simulation/oauth/client/sign/single?code=1002&ticket=1002
+//http://10.12.10.70/simulation/oauth/client/sign/entry?code=1002&ticket=1002
+//1002

+ 4 - 1
src/views/index.vue

@@ -40,8 +40,11 @@ export default {
                 if (res.code == 200 && !!res.info.access_token) {
                     localStorage.setItem(
                         "Authorization",
-                        "Bearer " + res.info.access_token
+                        res.info.token_type + ' ' + res.info.access_token
                     );
+                    localStorage.setItem("refreshToken", res.info.refresh_token);
+                    localStorage.setItem("expiresTime", res.info.expires_time);
+
                     this.$nextTick(() => {
                         this.$refs.curRouter.init &&
                             this.$refs.curRouter.init();

+ 8 - 0
src/views/mainPage.vue

@@ -373,6 +373,14 @@ export default {
     mounted() {
         if (localStorage.getItem("Authorization")) {
             this.init();
+        }else{  //如果没有Authorization
+            /*this.$alert('用户信息过期,请重新登陆','提示',{
+                confirmButtonText:'确定',
+                callback: action => {
+                    let loginUrl = window.location.origin + '/login'
+                    window.location.href = loginUrl
+                }
+            })*/
         }
     },
 };

+ 11 - 10
src/views/page/pageMenu.vue

@@ -181,16 +181,17 @@ export default {
         //设置一个定时器,定时在距离过期前5min,这个定时器会发送refreshToken请求
         
         this.expiresTime = localStorage.getItem('expiresTime')
-        this.toExpiresTime = new Date(this.expiresTime).getTime() - new Date().getTime();
-        
-        let that = this;
-        if(this.toExpiresTime < 5*60*1000){
-            this.refreshToken()
-        }else{
-            if(this.toExpiresTime < 24*60*60*1000){   //当过期时间小于一天时才会定时执行,否则会因为过期时间过大无法执行
-                this.tokenTimer = setTimeout(function(){
-                    that.refreshToken()
-                }, this.toExpiresTime - 5*60*1000)
+        if(this.expiresTime){
+            this.toExpiresTime = new Date(this.expiresTime).getTime() - new Date().getTime();
+            let that = this;
+            if(this.toExpiresTime < 5*60*1000){
+                this.refreshToken()
+            }else{
+                if(this.toExpiresTime < 24*60*60*1000){   //当过期时间小于一天时才会定时执行,否则会因为过期时间过大无法执行
+                    this.tokenTimer = setTimeout(function(){
+                        that.refreshToken()
+                    }, this.toExpiresTime - 5*60*1000)
+                }
             }
         }
     },