瀏覽代碼

登录通知逻辑

yangc 7 年之前
父節點
當前提交
45a0c1a67b
共有 1 個文件被更改,包括 33 次插入10 次删除
  1. 33 10
      components/login/Login.vue

+ 33 - 10
components/login/Login.vue

@@ -330,19 +330,20 @@
                   for (let n in param) {
                     a += (n + '=' + param[n] + '&')
                   }
-                  let countLink = 0
+                  const crossAfter = this.crossAfter
+                  let promises = []
                   for (let i in response.data.content.loginUrls) {
-                    this.$jsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1), function (err, data) {
-                      if ((++countLink) === response.data.content.loginUrls.length) {
-                        window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
-                      }
-                      console.log(err)
-                    })
+                    promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
                   }
+                  Promise.all(promises).then(() => {
+                    crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
+                  }).catch(() => {
+                    crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
+                  })
                   this.isShowLoading = true
-                  setTimeout(function () {
-                    window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
-                  }, 3000)
+//                  setTimeout(function () {
+//                    window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
+//                  }, 3000)
                 }
               } else {
                 this.$message.error(response.data)
@@ -378,6 +379,28 @@
         this.login.spaceUU = spaceUU
         this.dialogVisible = false
         this.isLogin(flag)
+      },
+      getJsonp: function (url) {
+        return new Promise((resolve, reject) => {
+          this.$jsonp(url, {
+            name: 'successCallback',
+            timeout: 200
+          }, function (err, data) {
+            if (err) {
+              reject(err)
+              throw err
+            } else {
+              resolve(data)
+            }
+          })
+        })
+      },
+      crossAfter (url) {
+        try {
+          window.location.href = url
+        } catch (err) {
+          console.log(err)
+        }
       }
     }
   }