codeLogin_frm.html 9.28 KB
<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <title>验证码登录</title>
      <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/login/codeLogin.css"/>
      <style>
          html,
          body{
            background-color: #F4F6F9;
          }
      </style>
  </head>
  <body>
    <div class="form-panel">
      <div class="aui-list" style="border-radius:8px;">
        <div class="aui-list-item" style="border-bottom: none;background-size: 100% 0px;margin-top:-0.5rem;">
            <div class="aui-list-item-left">
              <img src="../../image/login_icon_pohone.png" style="height:24px;width:24px;margin-top:-0.1rem;"/>
            </div>
            <div class="aui-list-item-center">
              <input id="login_phone" class="aui-input input-style-normal" type="tel" placeholder="+86 | 请输入手机号" style="height:3.3rem;border-bottom:1px solid #F0F5FF;margin-right:15px;">
            </div>
        </div>
        <div class="aui-list-item" style="margin-top:-1rem;margin-bottom:-1rem;">
            <div class="aui-list-item-left">
              <img src="../../image/login_icon_captcha.png" style="height:24px;width:24px;margin-top:-0.1rem;"/>
            </div>
            <div class="aui-list-item-center">
                <input id="login_code" class="aui-input input-style-normal" type="text" placeholder="手机验证码" style="height:3.3rem;border-bottom:1px solid #F0F5FF;">
            </div>
            <div class="aui-list-item-right" style="margin-right:0.4rem;">
              <div class="aui-btn send-code-btn code-btn-disable" tapmode onclick="sendCode();"><span id='sms-text'>获取验证码</span></div>
            </div>
        </div>
      </div>
    </div>

    <div style="margin-left:15px;margin-right:15px;margin-top:15px;" ontouchstart="">
      <span onclick="login();" id="loginBtn" class="login-btn">登录</span>
    </div>
    <!-- <div style="margin-left:15px;margin-right:15px;margin-top:20px;text-align:center;">
      <span  style="font-size:14px;color:#37394E;font-family:PingFang SC;font-weight:500;">使用其它登录方式</span>
    </div> -->
  </body>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script type="text/javascript" src="../../script/common.js"></script>
  <script type="text/javascript" src="../../script/jquery-3.3.1.min.js"></script>
  <script type="text/javascript">
    var cooldown = 0;
    var cid;
    apiready = function(){
      api.parseTapmode();

    };

    function sendCode() {
      var login_phone_dom = $api.byId("login_phone");
      login_phone_dom.blur();
      var login_phone = $api.trim($api.val($api.byId("login_phone")));
      if (!checkPhone(login_phone)) {
        api.toast({
            msg: "请输入正确的手机号"
        });
        return;
      }
      console.log(111);
      $.ajax({
            url: HOST+'/iot_api/v1/app/send_sms_need_phone_exist',
            type: 'POST',
            dataType: 'json',
            headers:{
                'Content-Type':'application/json;charset=utf-8',
                'imei':api.deviceId
            },
            data: JSON.stringify({
                phone: login_phone
            }),
            complete: function() {
                api.hideProgress();
            },
            success: function(ret) {
              console.log(JSON.stringify(ret));
                if (ret) {
                    if (ret.code == 0) {
                        api.toast({
                            msg: '验证码发送成功!',
                            duration: 2000,
                            location: 'bottom'
                        });
                        cid = ret.data.cid;
                        cooldown = 60;
                        Cooldown();
                    } else {
                      api.toast({
                          msg: "发送失败," + ajaxCodeCheck(ret.code, ret.msg,"")
                      });
                    }
                } else {
                  api.toast({
                      msg: "发送失败,请稍候再试"
                  });
                }
            },
            error: function() {
                api.toast({
                    msg: "登陆失败,请稍候再试"
                });
            }
        });
    }

    function Cooldown() {
      var obj = $api.byId("sms-text");
      $api.html(obj, cooldown+'s后重发');
      if (cooldown <=0) {
        $api.html(obj, '发送验证码');
      }else {
        cooldown = cooldown-1;
        window.setTimeout('Cooldown()',1000);
      }
    }

    function login() {
      var phone_input = $api.byId('login_phone');
      var code_input = $api.byId('login_code');
      phone_input.blur();
      code_input.blur();
      var login_phone = $api.trim($api.val($api.byId("login_phone")));
      var login_code = $api.trim($api.val($api.byId("login_code")));
      if (!checkPhone(login_phone)) {
        api.toast({
            msg: "请输入正确的手机号"
        });
        return;
      }
      api.showProgress({
          style: 'default',
          animationType: 'zoom',
          modal: true
      });
      $.ajax({
        url: HOST+'/iot_api/v1/app/sms_login',
        type: 'POST',
        dataType: 'json',
        headers:{
            'Content-Type':'application/json;charset=utf-8',
            'imei': api.deviceId
        },
        data: JSON.stringify({
            phone: login_phone,
            cid: cid,
            code: login_code
        }),
        complete: function() {
          api.hideProgress();
        },
        success: function(ret) {
          console.log(JSON.stringify(ret));
            if (ret.code == 0) {
              $api.clearStorage();
              api.toast({
                  msg: '登陆成功',
                  duration: 2000,
                  location: 'bottom'
              });
              var now = new Date();
              $api.setStorage('login_time', now.getTime());
              $api.setStorage('userToken', ret.data.token);
              $.ajax({
                  url: HOST + '/iot_api/v1/app/user',
                  type: 'GET',
                  dataType: 'json',
                  headers: {
                      'Content-Type': 'application/json;charset=utf-8',
                      'token': ret.data.token
                  },
                  success: function(rett) {
                    if (rett) {
                      if (rett.code == 0 && rett.data.user) {
                        var user = rett.data.user;
                        $api.setStorage('userName', user.name);
                        $api.setStorage('userPhone', user.user);
                        $api.setStorage('userID', user.id);

                        api.sendEvent({
                            name: 'cleanLoginPage',
                        });
                      }
                    }
                  }
              });
            } else {
              api.toast({
                  msg: "登陆失败," + ajaxCodeCheck(ret.code, ret.msg, '请稍后再试')
              });
            }
        },
        error: function() {
          api.toast({
              msg: "登陆失败," + ajaxCodeCheck(ret.code, ret.msg, '请稍后再试')
          });
        }
    });

      // api.ajax({
      //     url: HOST+'/iot_api/v1/app/sms_login',
      //     method: 'post',
      //     headers: {
      //       'Content-Type': 'application/json;charset=utf-8',
      //       'imei': api.deviceId
      //     },
      //     data: {
      //       body: {
      //         phone: login_phone,
      //         cid: cid,
      //         code: login_code
      //       }
      //     }
      // }, function(ret, err) {
      //   api.hideProgress();
      //   if (ret.code == 0) {
      //     $api.clearStorage();
      //     api.toast({
      //         msg: '登陆成功',
      //         duration: 2000,
      //         location: 'bottom'
      //     });
      //     var now = new Date();
      //     $api.setStorage('login_time', now.getTime());
      //     $api.setStorage('userToken', ret.data.token);
      //     api.ajax({
      //       url: HOST + '/iot_api/v1/app/user',
      //       method: 'get',
      //       headers: {
      //         'Content-Type': 'application/json;charset=utf-8',
      //         'token': ret.data.token
      //       },
      //     }, function(rett, err) {
      //       if (rett) {
      //         if (rett.code == 0 && rett.data.user) {
      //           var user = rett.data.user;
      //           $api.setStorage('userName', user.name);
      //           $api.setStorage('userPhone', user.user);
      //           $api.setStorage('userID', user.id);
      //
      //           api.sendEvent({
      //               name: 'cleanLoginPage',
      //           });
      //         }
      //       }
      //     });
      //   }else {
      //     api.toast({
      //         msg: "登陆失败," + ajaxCodeCheck(ret.code, ret.msg, '请稍后再试')
      //     });
      //   }
      //
      // });
    }
  </script>
  </html>