Bladeren bron

微信登录

hangb 7 jaren geleden
bovenliggende
commit
a05c7bbfba

+ 11 - 1
app.html

@@ -47,7 +47,17 @@
       }
     })(window, document)
   </script>
-  <script type="text/javascript">
+  <script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
+  <script>
+    // var obj = new WxLogin({
+    //   id: 'login_container',
+    //   appid: this.$route.query.appId,
+    //   scope: 'snsapi_login',
+    //   redirect_uri: `www.ubtob.com?appId={this.$route.query.appId}&returnURL={this.$route.query.returnURL}`,
+    //   state: '',
+    //   style: '',
+    //   href: ''
+    // })
   </script>
 </head>
 <body {{ BODY_ATTRS }}>

+ 10 - 0
assets/scss/common.scss

@@ -891,3 +891,13 @@ form .questions .el-form-item__content span.question {
 .clear-float {
   clear: both;
 }
+
+//微信扫码登录
+.bind-body {
+  .login-form {
+    margin-top: 15px;
+    .el-input__inner{
+      padding-left: 15px !important;
+    }
+  }
+}

+ 446 - 30
components/login/Login.vue

@@ -43,8 +43,8 @@
         </div>
       </div>
       <div class="x-login-wrap">
-        <div class="x-login">
-          <!-- user & pwd login wrap -->
+        <!--用户名短息登录-->
+        <div class="x-login" v-if="loginWay === 0">
           <div id="form-wrap" class="x-login-form">
             <!--账号密码登录-->
             <div v-show="activeTab === 0">
@@ -115,21 +115,68 @@
               <a id="register" @click="goRegister" class="second">
                 <i class="fa fa-arrow-circle-o-right"></i>免费注册</a>
             </div>
-          </div>
-          <!-- qrcode login wrap -->
-          <div id="qrcode-wrap" class="x-login-qrcode">
-            <div class="x-qrcode-help">
-              <span>打开手机客户端,扫描下面的二维码</span>
+            <!--微信-->
+            <div class="scavenging">
+              <div @click="getScan"><img src="/images/logo/weixin.png" alt=""/>微信</div>
             </div>
-            <div class="x-qrcode-img">
-              <img src="/images/all/qrcode.jpg">
+          </div>
+        </div>
+        <!--微信扫码登录-->
+        <div>
+        <!--<div class="x-login scan-login" v-if="loginWay === 1">-->
+          <!--<div class="x-login-form">-->
+            <!--<div class="scan-header">-->
+              <!--<span>微信登录</span>-->
+              <!--<img src="images/logo/saoma.png" alt="" @click="loginWay = 0"/>-->
+            <!--</div>-->
+            <!--<div class="scan-body">-->
+              <!--<div class="img">-->
+                <!--<img src="/images/logo/sao.png" alt=""/>-->
+              <!--</div>-->
+              <!--<div class="content">-->
+                <!--<img src="/images/logo/saosao.png" alt="">-->
+                <!--<div>-->
+                  <!--<span>打开 <b>微信</b></span>-->
+                  <!--<div>扫一扫登录</div>-->
+                <!--</div>-->
+              <!--</div>-->
+            <!--</div>-->
+          <!--</div>-->
+        <!--</div>-->
+        </div>
+        <!--绑定账号-->
+        <div class="x-login bind-login" v-if="loginWay === 2">
+          <div class="x-login-form">
+            <div class="bind-header">
+              <span>绑定已有账号</span>
+              <span @click="loginWay = 0">返回</span>
             </div>
-            <div class="x-qrcode-ex">
-              <ul class="list-unstyled list-inline">
-                <li><i class="iconfont icon-left icon-input"></i><span>免输入</span></li>
-                <li><i class="iconfont icon-left icon-fast"></i><span>更快捷</span></li>
-                <li><i class="iconfont icon-left icon-safe"></i><span>更安全</span></li>
-              </ul>
+            <div class="bind-body">
+              <div class="img"><img :src="wxImg" alt=""/><span>{{wxName}}</span></div>
+              <div>
+                <el-form :model="bindAccount" :rules="rules4" ref="bindAccount" class="demo-ruleForm login-form">
+                  <el-form-item prop="username">
+                    <el-input type="text"
+                              v-model="bindAccount.username"
+                              auto-complete="off"
+                              placeholder="请输入用户名、手机号或邮箱"></el-input>
+                  </el-form-item>
+                  <el-form-item prop="password">
+                    <input autocomplete="new-password"
+                           type="password" style="display: none;width:0;height:0;">
+                    <el-input type="password"
+                              v-model="bindAccount.password"
+                              auto-complete="new-password"
+                              placeholder="密码"
+                              @keyup.enter.native="wxBind"></el-input>
+                  </el-form-item>
+                  <el-form-item>
+                    <a class="btn login"
+                       @click="wxBind">确定绑定已有账号</a>
+                  </el-form-item>
+                </el-form>
+              </div>
+              <div class="set">还没有优软账号,直接 <a :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}&tk=${wxToken}`">创建新账号</a></div>
             </div>
           </div>
         </div>
@@ -166,6 +213,7 @@
       Loading
     },
     data () {
+      // 用户名密码登录
       var validateUsername = (rule, value, callback) => {
         if (value === '') {
           this.checkUsername = false
@@ -205,8 +253,7 @@
                 }
               }).catch(err => {
                 this.isShowLoading = false
-                console.log(err)
-                // this.$message.error(err.errMsg)
+                this.$message.error(err.errMsg)
               })
           }
           callback()
@@ -241,6 +288,27 @@
           callback()
         }
       }
+      // 微信扫码登录
+      var validateWeiUsername = (rule, value, callback) => {
+        if (value === '') {
+          this.checkWeiUsername = false
+        } else {
+          if (this.bindAccount.username !== '') {
+            this.checkWeiUsername = true
+          }
+          callback()
+        }
+      }
+      var validateWeiPassword = (rule, value, callback) => {
+        if (value === '') {
+          this.checkWeiPassword = false
+        } else {
+          if (this.bindAccount.password !== '') {
+            this.checkWeiPassword = true
+          }
+          callback()
+        }
+      }
       return {
         login: {
           username: '',
@@ -252,7 +320,12 @@
           mobile: '',
           code: ''
         },
+        bindAccount: {
+          username: '',
+          password: ''
+        },
         activeTab: 0,
+        loginWay: 0,
         checked: false,
         isShowLoading: false,
         checkUsername: false,
@@ -267,6 +340,13 @@
         login_time: 0,
         token: '',
         checkCode: false,
+        checkWeiUsername: false,
+        checkWeiPassword: false,
+        wxToken: '',
+        wxImg: '',
+        wxName: '',
+        wxUrl: '',
+        // 用户名密码登录
         rules2: {
           username: [
             {validator: validateUsername, trigger: 'blur'}
@@ -275,6 +355,7 @@
             {validator: validatePassword, trigger: 'blur'}
           ]
         },
+        // 短信快捷登录
         rules3: {
           mobile: [
             {validator: validateMobile, trigger: 'blur'}
@@ -282,6 +363,15 @@
           code: [
             {validator: validateCode, trigger: 'blur'}
           ]
+        },
+        // 微信扫码登录
+        rules4: {
+          username: [
+            {validator: validateWeiUsername, trigger: 'blur'}
+          ],
+          password: [
+            {validator: validateWeiPassword, trigger: 'blur'}
+          ]
         }
       }
     },
@@ -292,6 +382,9 @@
           this.getCookie()
         }
         this.validUserName()
+        if (this.$route.query.code) {
+          this.bindOrEnterprise()
+        }
       })
     },
     computed: {
@@ -348,6 +441,20 @@
       },
 //      获取url参数
       getUrl () {
+        console.log(this.$route, '111')
+        let wxUrl = ''
+        if (this.$route.query) {
+          for (var key in this.$route.query) {
+            if (key !== 'code' && key !== 'state') {
+              wxUrl += `${key}=${this.$route.query[key]}&`
+            }
+          }
+        }
+        if (this.$route.query === '') {
+          this.wxUrl = `${window.location.origin}?${wxUrl.substr(0, wxUrl.length - 1)}`
+        } else {
+          this.wxUrl = `${window.location.origin}`
+        }
         var url = window.location.search
         var request = {}
         if (url.indexOf('?' !== -1)) {
@@ -389,10 +496,10 @@
           param.append('username', this.login.username)
           param.append('password', this.login.password)
           param.append('captcha', this.login.captcha)
-          param.append('spaceUU', this.login.spaceUU)
-          param.append('appId', this.appId)
-          param.append('returnUrl', this.returnUrl)
-          param.append('baseUrl', this.baseUrl)
+          param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
+          param.append('appId', this.appId ? this.appId : '')
+          param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
+          param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
           let config = {
             headers: {'Content-Type': 'multipart/form-data'}
           }
@@ -460,13 +567,19 @@
             })
         }
       },
+      // 选择账套
       chooseOneEnterprise (flag, spaceUU) {
         this.login.spaceUU = spaceUU
         this.dialogVisible = false
-        if (this.activeTab === 0) {
-          this.isLogin(flag)
-        } else if (this.activeTab === 1) {
-          this.fastToLogin(flag)
+        if (this.$route.query.code) {
+          this.wxEnterprise(flag)
+        } else {
+          if (this.activeTab === 0) {
+            this.isLogin(flag)
+          }
+          if (this.activeTab === 1) {
+            this.fastToLogin(flag)
+          }
         }
         if (this.appId === 'mall' || this.appId === 'home') {
           if (this.checked) {
@@ -488,9 +601,9 @@
           param.append('code', this.fastLogin.code)
           param.append('appId', this.appId)
           param.append('token', this.token)
-          param.append('spaceUU', this.login.spaceUU)
-          param.append('returnUrl', this.returnUrl)
-          param.append('baseUrl', this.baseUrl)
+          param.append('spaceUU', this.login.spaceUU ? this.login.spaceUU : '')
+          param.append('returnUrl', this.returnUrl ? this.returnUrl : '')
+          param.append('baseUrl', this.baseUrl ? this.baseUrl : '')
           let config = {
             headers: {'Content-Type': 'multipart/form-data'}
           }
@@ -646,6 +759,158 @@
             this.isShowLoading = false
           }
         }
+      },
+      // 微信判断企业账套
+      wxEnterprise () {
+        let param = new FormData()
+        param.append('code', this.$route.query.code ? this.$route.query.code : '')
+        param.append('state', this.$route.query.state ? this.$route.query.state : '')
+        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/wxqrLogin', param, config)
+          .then(response => {
+            this.isShowLoading = false
+            if (response.data.success) {
+              if (response.data.content.spaces) {
+//                   弹框让用户选择企业
+                this.$store.commit('login/chooseRegisterEnterprise/GET_ENTERPRISE_SUCCESS', response.data.content.spaces)
+                this.dialogVisible = true
+              } 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.isShowLoading = true
+                if (response.data.content.currentUrl) {
+                  this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
+                    name: 'successCallback',
+                    timeout: 3000
+                  }, (err, data) => {
+                    if (err) {
+                      this.$message.error('登录超时,请重试')
+                      this.isShowLoading = false
+                      throw err
+                    } else {
+                      this.loginOther(response, params)
+                    }
+                  })
+                } else {
+                  this.loginOther(response, params, 3000)
+                }
+              }
+            } else {
+              this.$message.error(response.data)
+              return Promise.reject(response.data)
+            }
+          }).catch(err => {
+            this.isShowLoading = false
+            let _this = this
+            setTimeout(function () {
+              _this.getCode()
+            }, 100)
+            this.$message.error(err.errMsg)
+          })
+      },
+      // 微信扫码登录
+      getScan () {
+        // this.loginWay = 1
+        this.isShowLoading = true
+        this.$http.get('/weChat/getQrUrl', {params: {appId: this.$route.query.appId, url: this.wxUrl}})
+          .then(response => {
+            this.isShowLoading = false
+            if (response.data.success) {
+              window.location.href = response.data.content
+            } else {
+              return Promise.reject(response.data)
+            }
+          }).catch(err => {
+            this.isShowLoading = false
+            this.$message.error(err.errMsg)
+          })
+      },
+      // 判断是否绑定企业
+      bindOrEnterprise () {
+        this.isShowLoading = true
+        if (this.$route.query.code) {
+          let param = new FormData()
+          param.append('code', this.$route.query.code ? this.$route.query.code : '')
+          param.append('state', this.$route.query.state ? this.$route.query.state : '')
+          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/wxqrLogin', param, config)
+            .then(response => {
+              this.isShowLoading = false
+              if (response.data.success) {
+                if (!response.data.content.hasRegister && response.data.content.token) {
+                  this.loginWay = 2
+                  this.wxToken = response.data.content.token
+                  this.$http.get(`/weChat/userInfo/${this.wxToken}`, {params: {token: this.wxToken}})
+                    .then(response => {
+                      if (response.data.success) {
+                        this.wxImg = response.data.content.headimgurl
+                        this.wxName = response.data.content.nickname
+                        console.log(response.data, '333')
+                      } else {
+                        return Promise.reject(response.data)
+                      }
+                    }).catch(err => {
+                      this.$message.error(err.errMsg)
+                    })
+                } else {
+                  this.wxEnterprise()
+                }
+              } else {
+                return Promise.reject(response.data)
+              }
+            }).catch(err => {
+              this.isShowLoading = false
+              this.$message.error(err.errMsg)
+            })
+        }
+      },
+      // 绑定企业
+      wxBind () {
+        this.isShowLoading = true
+        if (!this.bindAccount.username) {
+          this.isShowLoading = false
+          this.$message.error('请填写账号')
+        } else if (!this.bindAccount.password) {
+          this.isShowLoading = false
+          this.$message.error('请填写密码')
+        } else {
+          let param = new FormData()
+          param.append('t', this.wxToken)
+          param.append('username', this.bindAccount.username)
+          param.append('password', this.bindAccount.password)
+          let config = {
+            headers: {'Content-Type': 'multipart/form-data'}
+          }
+          this.$http.post('/weChat/addAccount', param, config)
+            .then(response => {
+              this.isShowLoading = false
+              if (response.data.success) {
+                this.wxEnterprise()
+              } else {
+                return Promise.reject(response.data)
+              }
+            }).catch(err => {
+              this.isShowLoading = false
+              this.$message.error(err.errMsg)
+            })
+        }
       }
     }
   }
@@ -725,6 +990,18 @@
         font-size: 12px;
       }
     }
+    /*微信登录*/
+    .scavenging {
+      margin-top:22px;
+      div{
+        font-size: 12px;
+        color: #666;
+        cursor: pointer;
+        img{
+          margin-right: 10px;
+        }
+      }
+    }
     /*登录弹出框*/
     .x-floating {
       position: fixed;
@@ -893,8 +1170,147 @@
             }
           }
         }
-        .x-login-qrcode{
-          display: none;
+      }
+      .scan-login {
+        box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
+        border-radius: 6px;
+        .x-login-form{
+          padding: 0;
+          .scan-header {
+            position: relative;
+            height: 50px;
+            line-height: 50px;
+            font-size: 18px;
+            font-weight: bold;
+            color: #666;
+            border: solid 1px #e5e5e5;
+            span{
+              position: absolute;
+              top: -3px;
+              padding-left: 10px;
+              display: inline-block;
+              width: 90px;
+              border-bottom: 2px solid #0076ff;
+            }
+            img{
+              position: absolute;
+              top: -3px;
+              right: -1px;
+              height: 50px;
+              cursor: pointer;
+            }
+          }
+          .scan-body {
+            margin: 22px auto 0;
+            padding-bottom: 38px;
+            text-align: center ;
+            div.img{
+              margin: 0 auto;
+              width: 180px;
+              height: 182px;
+              line-height: 182px;
+              text-align: center;
+              border: 1px solid #dcdcdc;
+              img{
+                width: 162px;
+                height: 165px;
+              }
+            }
+            div.content {
+              width: 138px;
+              margin: 58px auto 0;
+              text-align: center;
+              overflow: hidden;
+              img{
+                float: left;
+                margin-right: 25px;
+                width: 32px;
+                height: 27px;
+              }
+              div{
+                float: left;
+                width: 80px;
+                text-align: left;
+                span{
+                  font-size: 14px;
+                  color: #999;
+                  b{
+                    color: #0076ff;
+                  }
+                }
+                div{
+                  font-size: 14px;
+                  color: #999;
+                }
+              }
+            }
+          }
+        }
+      }
+      .bind-login {
+        box-shadow: -2px 1px 6px 0px rgba(0, 0, 0, 0.06);
+        border-radius: 6px;
+        .x-login-form{
+          padding: 0;
+          .bind-header {
+           overflow: hidden;
+            padding: 0 20px;
+            height: 50px;
+            line-height: 50px;
+            font-size: 18px;
+            font-weight: bold;
+            color: #666;
+            border: solid 1px #e5e5e5;
+            span {
+              &:first-child {
+                float: left;
+                border-bottom: 2px solid #5078cb;
+              }
+              &:last-child{
+                float: right;
+                font-size: 14px;
+                color: #5078cb;
+                font-weight: normal;
+                cursor: pointer;
+              }
+            }
+          }
+          .bind-body {
+            margin: 22px auto 0;
+            padding-bottom: 20px;
+            text-align: center ;
+            .img{
+              margin: 0 auto;
+              width: 60px;
+              text-align: center;
+              img{
+                margin-bottom: 10px;
+                width: 100%;
+                height: 60px;
+                border-radius: 50%;
+              }
+              span{
+                font-size: 14px;
+                color: #999;
+              }
+            }
+            .set{
+              margin-top: 40px;
+              font-size: 12px;
+              color: #999;
+              a{
+                display: inline-block;
+                width: 90px;
+                line-height: 23px;
+                height: 24px;
+                text-align: center;
+                font-size: 14px;
+                color: #5078cb;
+                border-radius: 13px;
+                border: solid 1px #5078cb;
+              }
+            }
+          }
         }
       }
     }

+ 1 - 0
components/register/EnterpriseRegistration.vue

@@ -756,6 +756,7 @@
         param.append('inviteSpaceUU', this.$store.state.option.inviteSpaceUU)
         param.append('inviteUserUU', this.$store.state.option.inviteUserUU)
         param.append('invitationTime', this.$store.state.option.invitationTime)
+        param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
         let config = {
           headers: {'Content-Type': 'multipart/form-data'}
         }

+ 1 - 0
components/register/PersonalRegistration.vue

@@ -408,6 +408,7 @@
             param.append('appId', this.appId)
             param.append('code', this.item.code)
             param.append('token', this.token)
+            param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
             let config = {
               headers: {'Content-Type': 'multipart/form-data'}
             }

+ 1 - 1
nuxt.config.js

@@ -105,5 +105,5 @@ module.exports = {
     ssr: true
   }],
   /* TODO 暂时代理到商城测试版,之后再做出调整 */
-  proxyTable: ['/api/**', '/login/**', '/user**', '/logout**', '/sso/**', '/appeal/**', '/update/user/**', '/valid/**', '/im/**']
+  proxyTable: ['/api/**', '/login/**', '/user**', '/logout**', '/sso/**', '/appeal/**', '/update/user/**', '/valid/**', '/im/**', '/weChat/**']
 }

+ 1 - 1
pages/bindEnterPrise/_uuid.vue

@@ -40,7 +40,7 @@
             </div>
           </div>
           <template v-if="hasRegister && !searchInfo">
-            <a name="register" href="/register/enterpriseRegistration">立即注册</a>
+            <a name="register" :href="`/register/enterpriseRegistration${this.$store.state.option.fullPath}`">立即注册</a>
           </template>
           <template v-if="hasRegister && searchInfo && searchInfo.admin">
             <a href="javascript:void(0)" @click="bingEnterPrise()">申请绑定</a>

BIN
static/images/logo/saoma.png


BIN
static/images/logo/saosao.png


BIN
static/images/logo/weixin.png