Browse Source

闭合登录

huangb 7 years ago
parent
commit
6a0e31753d
2 changed files with 201 additions and 208 deletions
  1. 17 17
      app.html
  2. 184 191
      components/mobile/loginMobile.vue

+ 17 - 17
app.html

@@ -6,11 +6,11 @@
   <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
   <link rel="stylesheet" href="https://unpkg.com/mint-ui/lib/style.css">
   <link rel="stylesheet" type="text/css" href="https://at.alicdn.com/t/font_0d1jjt5tukcblnmi.css"/>
-  <!--<script src="https://wechatfe.github.io/vconsole/lib/vconsole.min.js?v=3.2.0"></script>-->
+  <script src="https://wechatfe.github.io/vconsole/lib/vconsole.min.js?v=3.2.0"></script>
   <!--<script src="https://biheopen.bgycc.com/cordova-android.js"></script>-->
   {{ HEAD }}
   <script>
-    // var vConsole = new VConsole()
+    var vConsole = new VConsole()
     var _hmt = _hmt || [];
     (function (w, d) {
       // var heads = document.
@@ -73,27 +73,27 @@
     <a class="close-tip" onclick="resultClose()">&times;</a>
   </div>
   <!--碧合-->
-  <!--<div id="ao2"></div>-->
+  <div id="ao2"></div>
 {{ APP }}
 <script>
   // 碧合
-  // if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
-  //   console.log('iOS')
-  //   var script=document.createElement("script");
-  //   script.setAttribute("src", "https://biheopen.bgycc.com/cordova-ios.js");
-  //   var heads = document.getElementById("ao2");
-  //   heads.appendChild(script);
-  // } else if (/Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone/.test(navigator.userAgent)) {
-  //   console.log('android')
-  //   var script=document.createElement("script");
-  //   script.setAttribute("src", "https://biheopen.bgycc.com/cordova-android.js");
-  //   var heads = document.getElementById("ao2");
-  //   heads.appendChild(script);
-  // }
+  if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
+    console.log('iOS')
+    var script=document.createElement("script");
+    script.setAttribute("src", "https://biheopen.bgycc.com/cordova-ios.js");
+    var heads = document.getElementById("ao2");
+    heads.appendChild(script);
+  } else if (/Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone/.test(navigator.userAgent)) {
+    console.log('android')
+    var script=document.createElement("script");
+    script.setAttribute("src", "https://biheopen.bgycc.com/cordova-android.js");
+    var heads = document.getElementById("ao2");
+    heads.appendChild(script);
+  }
 </script>
 </body>
 <!--闭合-->
-<!--<script src="https://dfs.ubtob.com/group1/M00/B6/72/CgpkyFtP4L6ABNMFAAAfPEFQbFI5116.js"></script>-->
+<script src="https://dfs.ubtob.com/group1/M00/B6/72/CgpkyFtP4L6ABNMFAAAfPEFQbFI5116.js"></script>
 <script>
   if(navigator.appName == "Microsoft Internet Explorer"&&parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE",""))<10){
     var el = document.getElementById('result')

+ 184 - 191
components/mobile/loginMobile.vue

@@ -7,8 +7,7 @@
         <header-mobile/>
       </template>
       <div class="login">
-      <!--<div v-if="loginWay === 0">-->
-      <div>
+      <div v-if="loginWay === 0">
         <div class="login-way" v-if="activeTab === 0">
           <div class="page-part">
             <mt-field auto-complete="off" placeholder="手机号/邮箱" v-model="login.username" @blur.native.capture="codeCount"></mt-field>
@@ -61,25 +60,25 @@
           <mt-button size="large" plain type="primary" @click="jump">立即注册</mt-button>
         </div>
       </div>
-      <!--<div v-if="loginWay === 1">-->
-      <!--<div class="user-info">-->
-      <!--<div class="img"><img :src="bhImg || '/images/all/icon_mall_index.png'" alt=""></div>-->
-      <!--<div class="user-name">{{bhName}}</div>-->
-      <!--</div>-->
-      <!--<div class="page-part">-->
-      <!--<mt-field auto-complete="off" placeholder="请输入账号" v-model="bhLogin.username"></mt-field>-->
-      <!--</div>-->
-      <!--<div class="page-part">-->
-      <!--<mt-field placeholder="请输入密码" v-model="bhLogin.password" type="password"></mt-field>-->
-      <!--</div>-->
-      <!--<div class="page-part">-->
-      <!--<mt-button size="large" type="primary" @click="bhBind">确&nbsp;&nbsp;&nbsp;定</mt-button>-->
-      <!--</div>-->
-      <!--<div class="login-btn">-->
-      <!--<p>还没有优软云账号?</p>-->
-      <!--<mt-button size="large" plain type="primary"><a :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}&tk=${bhToken}`" class="go">创建新账号</a></mt-button>-->
-      <!--</div>-->
-      <!--</div>-->
+      <div v-if="loginWay === 1">
+        <div class="user-info">
+          <div class="img"><img :src="bhImg || '/images/all/icon_mall_index.png'" alt=""></div>
+          <div class="user-name">{{bhName}}</div>
+        </div>
+        <div class="page-part">
+          <mt-field auto-complete="off" placeholder="请输入账号" v-model="bhLogin.username"></mt-field>
+        </div>
+        <div class="page-part">
+          <mt-field placeholder="请输入密码" v-model="bhLogin.password" type="password"></mt-field>
+        </div>
+        <div class="page-part">
+          <mt-button size="large" type="primary" @click="bhBind">确&nbsp;&nbsp;&nbsp;定</mt-button>
+        </div>
+        <div class="login-btn">
+          <p>还没有优软云账号?</p>
+          <mt-button size="large" plain type="primary"><a :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}&tk=${bhToken}`" class="go">创建新账号</a></mt-button>
+        </div>
+      </div>
       <mt-popup v-model="popupVisible" position="right" class="mint-popup" :modal="false">
         <ul style="height:100vh;overflow-y:auto">
           <li class="listitem itemgreen">选择您要登录的公司:</li>
@@ -92,22 +91,22 @@
 </template>
 
 <script>
-  // function getCodeD (appId) {
-  //   let paramse = {
-  //     appId: appId
-  //   }
-  //   return new Promise((resolve, reject) => {
-  //     if (window.cordova) {
-  //       window.MrJsBridge.call((returnValue) => {
-  //         resolve(returnValue)
-  //       }, (error) => {
-  //         console.log(error)
-  //         reject(error)
-  //       }, 'getCode', paramse)
-  //     }
-  //   })
-  // }
-  import HeaderMobile from '~components/mobile/HeaderMobile.vue'
+  function getCodeD (appId) {
+    let paramse = {
+      appId: appId
+    }
+    return new Promise((resolve, reject) => {
+      if (window.cordova) {
+        window.MrJsBridge.call((returnValue) => {
+          resolve(returnValue)
+        }, (error) => {
+          console.log(error)
+          reject(error)
+        }, 'getCode', paramse)
+      }
+    })
+  }
+  import HeaderMobile from '~components/mobile/headerMobile.vue'
   export default {
     name: 'loginMobile',
     components: {
@@ -125,10 +124,10 @@
           spaceUU: '',
           captcha: ''
         },
-        // bhLogin: {
-        //   username: '',
-        //   password: ''
-        // },
+        bhLogin: {
+          username: '',
+          password: ''
+        },
         fastLogin: {
           mobile: '',
           code: ''
@@ -146,7 +145,7 @@
         tokenCode: '',
         tokenTime: 60,
         tokenText: '获取验证码',
-        // loginWay: 0,
+        loginWay: 0,
         activeTab: 0
       }
     },
@@ -154,19 +153,19 @@
       this.$nextTick(() => {
         this.getUrl()
         // 碧合应用授权认证
-        // window.document.addEventListener('deviceready', function () {
-        //   window.addEventListener('js_bridge_called', function () {
-        //   })
-        // })
-        // let appId = 'a9f624cbbdb947049f5638880b0ecbb2'
-        // getCodeD(appId).then((data) => {
-        //   // 成功回调 code
-        //   alert(data)
-        //   this.bhCode = data
-        //   this.bhToLogin()
-        // }).catch((error) => {
-        //   console.log(error)
-        // })
+        window.document.addEventListener('deviceready', function () {
+          window.addEventListener('js_bridge_called', function () {
+          })
+        })
+        let appId = 'a9f624cbbdb947049f5638880b0ecbb2'
+        getCodeD(appId).then((data) => {
+          // 成功回调 code
+          alert(data)
+          this.bhCode = data
+          this.bhToLogin()
+        }).catch((error) => {
+          console.log(error)
+        })
       })
     },
     computed: {
@@ -181,21 +180,15 @@
       selectEnterprise (flag, type) {
         this.login.spaceUU = type
         this.popupVisible = flag
-        // if (this.$route.query.type) {
-        //   this.bhToLogin()
-        // } else {
-        //   if (this.activeTab === 0) {
-        //     this.toLogin(flag)
-        //   }
-        //   if (this.activeTab === 1) {
-        //     this.fastToLogin(flag)
-        //   }
-        // }
-        if (this.activeTab === 0) {
-          this.toLogin(flag)
-        }
-        if (this.activeTab === 1) {
-          this.fastToLogin(flag)
+        if (this.$route.query.type) {
+          this.bhToLogin()
+        } else {
+          if (this.activeTab === 0) {
+            this.toLogin(flag)
+          }
+          if (this.activeTab === 1) {
+            this.fastToLogin(flag)
+          }
         }
       },
       // 弹窗处理
@@ -375,128 +368,128 @@
         })
       },
       // 碧合绑定账号
-      // bhBind () {
-      //   this.$indicator.open('绑定中请稍后...')
-      //   if (!this.bhLogin.username) {
-      //     this.$indicator.close()
-      //     this.downToast('请填写账号')
-      //   } else if (!this.bhLogin.password) {
-      //     this.$indicator.close()
-      //     this.downToast('请填写密码')
-      //   } else {
-      //     let param = new FormData()
-      //     param.append('_operate', 'account')
-      //     param.append('t', this.bhToken)
-      //     param.append('username', this.bhLogin.username)
-      //     param.append('password', this.bhLogin.password)
-      //     let config = {
-      //       headers: {'Content-Type': 'multipart/form-data'}
-      //     }
-      //     this.$http.post('/foreign/addAccount', param, config)
-      //       .then(response => {
-      //         this.$indicator.close()
-      //         if (response.data.success) {
-      //           this.bhToLogin()
-      //         } else {
-      //           return Promise.reject(response.data)
-      //         }
-      //       }).catch(err => {
-      //         this.$indicator.close()
-      //         this.$toast({
-      //           message: err.errMsg,
-      //           iconClass: 'el-icon-error'
-      //         })
-      //       })
-      //   }
-      // },
+      bhBind () {
+        this.$indicator.open('绑定中请稍后...')
+        if (!this.bhLogin.username) {
+          this.$indicator.close()
+          this.downToast('请填写账号')
+        } else if (!this.bhLogin.password) {
+          this.$indicator.close()
+          this.downToast('请填写密码')
+        } else {
+          let param = new FormData()
+          param.append('_operate', 'account')
+          param.append('t', this.bhToken)
+          param.append('username', this.bhLogin.username)
+          param.append('password', this.bhLogin.password)
+          let config = {
+            headers: {'Content-Type': 'multipart/form-data'}
+          }
+          this.$http.post('/foreign/addAccount', param, config)
+            .then(response => {
+              this.$indicator.close()
+              if (response.data.success) {
+                this.bhToLogin()
+              } else {
+                return Promise.reject(response.data)
+              }
+            }).catch(err => {
+              this.$indicator.close()
+              this.$toast({
+                message: err.errMsg,
+                iconClass: 'el-icon-error'
+              })
+            })
+        }
+      },
       // 判断是否绑定、选择账套
-//       bhToLogin () {
-//         this.$indicator.open('加载中...')
-//         if (this.$route.query.type) {
-//           let param = new FormData()
-//           param.append('code', this.bhCode || '')
-//           param.append('type', 'bh')
-//           param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
-//           param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
-//           param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
-//           param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
-//           let config = {
-//             headers: {'Content-Type': 'multipart/form-data'}
-//           }
-//           this.$http.post('/sso/login/foreignLogin', param, config)
-//             .then(response => {
-//               this.$indicator.close()
-//               if (response.data.success) {
-//                 if (!response.data.content.hasRegister && response.data.content.token) {
-//                   this.loginWay = 1
-//                   this.bhToken = response.data.content.token
-//                   this.$http.get(`/foreign/userInfo/${this.bhToken}`, {params: {token: this.bhToken}})
-//                     .then(response => {
-//                       if (response.data.success) {
-//                         this.bhImg = response.data.content.foreignUserImg
-//                         this.bhName = response.data.content.foreignUserName
-//                       } else {
-//                         return Promise.reject(response.data)
-//                       }
-//                     }).catch(err => {
-//                       this.$toast({
-//                         message: err.errMsg,
-//                         iconClass: 'el-icon-error'
-//                       })
-//                     })
-//                 } else if (response.data.content.spaces) {
-// //                   弹框让用户选择企业
-//                   this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
-//                   this.popupVisible = true
-//                   this.$indicator.open('跳转中...')
-//                 } else if (response.data.content.loginUrls) {
-// //                  遍历登录url循环让各应用登录(需要跨域)
-//                   let param = response.data.content.data
-//                   let a = ''
-//                   for (let n in param) {
-//                     a += (n + '=' + encodeURIComponent(param[n]) + '&')
-//                   }
-//                   let params = a.substr(0, a.length - 1)
-//                   this.$indicator.open('加载中...')
-//                   if (response.data.content.currentUrl) {
-//                     this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
-//                       name: 'successCallback',
-//                       timeout: 3000
-//                     }, (err, data) => {
-//                       if (err) {
-//                         this.$toast({
-//                           message: '登录超时,请重试',
-//                           iconClass: 'el-icon-error'
-//                         })
-//                         this.$indicator.close()
-//                         throw err
-//                       } else {
-//                         this.loginOther(response, params)
-//                       }
-//                     })
-//                   } else {
-//                     this.loginOther(response, params, 3000)
-//                   }
-//                 }
-//               } else {
-//                 this.$toast({
-//                   message: response.data,
-//                   iconClass: 'el-icon-error'
-//                 })
-//               }
-//             }).catch(err => {
-//               this.$indicator.close()
-//               let _this = this
-//               setTimeout(function () {
-//                 _this.getCode()
-//               }, 100)
-//               this.$toast({
-//                 message: err.errMsg,
-//                 iconClass: 'el-icon-error'
-//               })
-//             })
-//         }
-//       },
+      bhToLogin () {
+        this.$indicator.open('加载中...')
+        if (this.$route.query.type) {
+          let param = new FormData()
+          param.append('code', this.bhCode || '')
+          param.append('type', 'bh')
+          param.append('appId', this.$route.query.appId ? this.$route.query.appId : '')
+          param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
+          param.append('baseUrl', this.$route.query.baseUrl ? this.$route.query.baseUrl : '')
+          param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
+          let config = {
+            headers: {'Content-Type': 'multipart/form-data'}
+          }
+          this.$http.post('/sso/login/foreignLogin', param, config)
+            .then(response => {
+              this.$indicator.close()
+              if (response.data.success) {
+                if (!response.data.content.hasRegister && response.data.content.token) {
+                  this.loginWay = 1
+                  this.bhToken = response.data.content.token
+                  this.$http.get(`/foreign/userInfo/${this.bhToken}`, {params: {token: this.bhToken}})
+                    .then(response => {
+                      if (response.data.success) {
+                        this.bhImg = response.data.content.foreignUserImg
+                        this.bhName = response.data.content.foreignUserName
+                      } else {
+                        return Promise.reject(response.data)
+                      }
+                    }).catch(err => {
+                      this.$toast({
+                        message: err.errMsg,
+                        iconClass: 'el-icon-error'
+                      })
+                    })
+                } else if (response.data.content.spaces) {
+//                   弹框让用户选择企业
+                  this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
+                  this.popupVisible = true
+                  this.$indicator.open('跳转中...')
+                } else if (response.data.content.loginUrls) {
+//                  遍历登录url循环让各应用登录(需要跨域)
+                  let param = response.data.content.data
+                  let a = ''
+                  for (let n in param) {
+                    a += (n + '=' + encodeURIComponent(param[n]) + '&')
+                  }
+                  let params = a.substr(0, a.length - 1)
+                  this.$indicator.open('加载中...')
+                  if (response.data.content.currentUrl) {
+                    this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
+                      name: 'successCallback',
+                      timeout: 3000
+                    }, (err, data) => {
+                      if (err) {
+                        this.$toast({
+                          message: '登录超时,请重试',
+                          iconClass: 'el-icon-error'
+                        })
+                        this.$indicator.close()
+                        throw err
+                      } else {
+                        this.loginOther(response, params)
+                      }
+                    })
+                  } else {
+                    this.loginOther(response, params, 3000)
+                  }
+                }
+              } else {
+                this.$toast({
+                  message: response.data,
+                  iconClass: 'el-icon-error'
+                })
+              }
+            }).catch(err => {
+              this.$indicator.close()
+              let _this = this
+              setTimeout(function () {
+                _this.getCode()
+              }, 100)
+              this.$toast({
+                message: err.errMsg,
+                iconClass: 'el-icon-error'
+              })
+            })
+        }
+      },
       // 验证手机号
       validateMobile () {
         let reg = /^1[0-9]{10}$/