Browse Source

登录兼容优软云和b2b

yangc 7 years ago
parent
commit
ee5731e0ac
3 changed files with 98 additions and 85 deletions
  1. 29 22
      components/login/Login.vue
  2. 33 26
      components/mobile/loginMobile.vue
  3. 36 37
      pages/agency/index.vue

+ 29 - 22
components/login/Login.vue

@@ -331,27 +331,22 @@
                     a += (n + '=' + param[n] + '&')
                   }
                   this.isShowLoading = true
-                  this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
-                    name: 'successCallback',
-                    timeout: 3000
-                  }, (err, data) => {
-                    if (err) {
-                      this.$message.error('登录超时,请重试')
-                      this.isShowLoading = false
-                      throw err
-                    } else {
-                      const crossAfter = this.crossAfter
-                      let promises = []
-                      for (let i in response.data.content.loginUrls) {
-                        promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
+                  if (response.data.content.currentUrl) {
+                    this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
+                      name: 'successCallback',
+                      timeout: 3000
+                    }, (err, data) => {
+                      if (err) {
+                        this.$message.error('登录超时,请重试')
+                        this.isShowLoading = false
+                        throw err
+                      } else {
+                        this.loginOther(response, a)
                       }
-                      Promise.all(promises).then(() => {
-                        crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                      }).catch(() => {
-                        crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                      })
-                    }
-                  })
+                    })
+                  } else {
+                    this.loginOther(response, a, 3000)
+                  }
                 }
               } else {
                 this.$message.error(response.data)
@@ -388,11 +383,11 @@
         this.dialogVisible = false
         this.isLogin(flag)
       },
-      getJsonp: function (url) {
+      getJsonp: function (url, timeout = 500) {
         return new Promise((resolve, reject) => {
           this.$jsonp(url, {
             name: 'successCallback',
-            timeout: 500
+            timeout: timeout
           }, function (err, data) {
             if (err) {
               reject(err)
@@ -409,6 +404,18 @@
         } catch (err) {
           console.log(err)
         }
+      },
+      loginOther (response, a, timeout) {
+        const crossAfter = this.crossAfter
+        let promises = []
+        for (let i in response.data.content.loginUrls) {
+          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', timeout)
+        }).catch(() => {
+          crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
+        })
       }
     }
   }

+ 33 - 26
components/mobile/loginMobile.vue

@@ -156,31 +156,26 @@
                   a += (n + '=' + param[n] + '&')
                 }
                 this.$indicator.open('跳转中...')
-                this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
-                  name: 'successCallback',
-                  timeout: 5000
-                }, (err, data) => {
-                  if (err) {
-                    this.$indicator.close()
-                    this.$toast({
-                      message: '登录超时,请重试',
-                      iconClass: 'el-icon-error'
-                    })
-                    this.login.spaceUU = ''
-                    throw err
-                  } else {
-                    const crossAfter = this.crossAfter
-                    let promises = []
-                    for (let i in response.data.content.loginUrls) {
-                      promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
+                if (response.data.content.currentUrl) {
+                  this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
+                    name: 'successCallback',
+                    timeout: 5000
+                  }, (err, data) => {
+                    if (err) {
+                      this.$indicator.close()
+                      this.$toast({
+                        message: '登录超时,请重试',
+                        iconClass: 'el-icon-error'
+                      })
+                      this.login.spaceUU = ''
+                      throw err
+                    } else {
+                      this.loginOther(response, a)
                     }
-                    Promise.all(promises).then(() => {
-                      crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                    }).catch(() => {
-                      crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                    })
-                  }
-                })
+                  })
+                } else {
+                  this.loginOther(response, a, 3000)
+                }
               }
             } else {
               this.login.password = ''
@@ -209,11 +204,11 @@
             })
           })
       },
-      getJsonp: function (url) {
+      getJsonp: function (url, timeout = 500) {
         return new Promise((resolve, reject) => {
           this.$jsonp(url, {
             name: 'successCallback',
-            timeout: 500
+            timeout: timeout
           }, function (err, data) {
             if (err) {
               reject(err)
@@ -230,6 +225,18 @@
         } catch (err) {
           console.log(err)
         }
+      },
+      loginOther (response, a, timeout) {
+        const crossAfter = this.crossAfter
+        let promises = []
+        for (let i in response.data.content.loginUrls) {
+          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', timeout)
+        }).catch(() => {
+          crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
+        })
       }
     }
   }

+ 36 - 37
pages/agency/index.vue

@@ -75,42 +75,29 @@
                 for (let n in param) {
                   a += (n + '=' + param[n] + '&')
                 }
-                this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
-                  name: 'successCallback',
-                  timeout: 5000
-                }, (err, data) => {
-                  const crossAfter = this.crossAfter
-                  if (err) {
-                    this.$indicator.close()
-                    this.$toast({
-                      message: '登录超时,即将跳转...',
-                      iconClass: 'el-icon-error'
-                    })
-                    setTimeout(() => {
-                      crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                    }, 1000)
-                    throw err
-                  } else {
-                    let promises = []
-                    for (let i in response.data.content.loginUrls) {
-                      promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?` + a.substr(0, a.length - 1)))
+                if (response.data.content.currentUrl) {
+                  this.$jsonp(`${response.data.content.currentUrl}?${a.substr(0, a.length - 1)}`, {
+                    name: 'successCallback',
+                    timeout: 5000
+                  }, (err, data) => {
+                    const crossAfter = this.crossAfter
+                    if (err) {
+                      this.$indicator.close()
+                      this.$toast({
+                        message: '登录超时,即将跳转...',
+                        iconClass: 'el-icon-error'
+                      })
+                      setTimeout(() => {
+                        crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
+                      }, 1000)
+                      throw err
+                    } else {
+                      this.loginOther(response, a)
                     }
-                    Promise.all(promises).then(() => {
-                      crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                    }).catch(() => {
-                      crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com')
-                    })
-                  }
-                })
-                // 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 (err) throw err
-                //     console.log(data)
-                //   })
-                // }
-                // setTimeout(function () {
-                //   window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
-                // }, 3000)
+                  })
+                } else {
+                  this.loginOther(response, a, 3000)
+                }
               } else {
                 window.location.href = response.data.content.returnUrl || 'http://www.ubtob.com'
               }
@@ -121,11 +108,11 @@
             this.$message.error(err.errMsg)
           })
       },
-      getJsonp: function (url) {
+      getJsonp: function (url, timeout = 500) {
         return new Promise((resolve, reject) => {
           this.$jsonp(url, {
             name: 'successCallback',
-            timeout: 500
+            timeout: timeout
           }, function (err, data) {
             if (err) {
               reject(err)
@@ -142,6 +129,18 @@
         } catch (err) {
           console.log(err)
         }
+      },
+      loginOther (response, a, timeout) {
+        const crossAfter = this.crossAfter
+        let promises = []
+        for (let i in response.data.content.loginUrls) {
+          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', timeout)
+        }).catch(() => {
+          crossAfter(response.data.content.returnUrl || 'http://www.ubtob.com', timeout)
+        })
       }
     }
   }