123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- var userAgent = window.localStorage.getItem('wlyyAgentForDoc')
- var $eyeIcon = $('.psw-eye'),
- $mobile1 = $('#mobile1'),
- $password = $('#password'),
- $mobile2 = $('#mobile2'),
- $captcha = $('#captcha'),
- $mobile = $('input[mobile]'),
- $tabs = $('.nav-tabs'),
- $getCaptcha = $('#getCaptcha'),
- $submit = $('button[type="submit"]');
- var timer = null;
- $(function() {
- bindEvent()
- function bindEvent(){
- //密码隐藏
- $eyeIcon.click(function() {
- $el = $(this);
- if($el.hasClass('fa-eye')) {
- $el.removeClass('fa-eye').addClass('fa-eye-slash');
- $password.attr('type','password')
- } else {
- $el.removeClass('fa-eye-slash').addClass('fa-eye');
- $password.attr('type','text')
- }
- })
- //验证码定时
- function setTimer() {
- $getCaptcha.addClass('disabled');
- var seconds = 59;
- timer = setInterval(function() {
- if(seconds == 0) {
- clearInterval(timer);
- timer = null;
- seconds = 59;
- $getCaptcha.text("获取验证码");
- $getCaptcha.removeClass('disabled');
- return ;
- }
- $getCaptcha.text((seconds--)+"s后重新获取");
- }, 1000)
- }
- //表单验证
- var validator1 = $("#form1").validate({
- onsubmit: false,
- onfocusout: function(ele) {
- validator1.element(ele)
- },
- rules: {
- mobile1: {
- required: true,
- mobile: true,
- },
- password: "required",
- }
- });
- var validator2 = $("#form2").validate({
- onsubmit: false,
- onfocusout: function(ele) {
- validator2.element(ele)
- },
- rules: {
- mobile2: {
- required: true,
- mobile: true,
- },
- captcha: "required",
- }
- });
- jQuery.validator.addMethod("mobile", function(value, element, param) {
- var reg=/^[1][3,4,5,7,8][0-9]{9}$/;
- return reg.test(value);
- }, "手机号码有误");
- //切换tab
- $tabs.on('click','li',function() {
- var idx = $(this).index(),
- mob = '';
-
- if(idx == 1) { // 点击验证码登录选项卡
- mob = $mobile1.val();
- if(mob) {
- $mobile.val(mob);
- validator2.element($mobile2)
- }
- } else { // 点击手机登陆选项卡
- mob = $mobile2.val();
- if(mob) {
- $mobile.val(mob);
- validator1.element($mobile1)
- }
- }
- })
- //发送短信
- $getCaptcha.click(function() {
- if($getCaptcha.hasClass('disabled')) {
- return ;
- }
- if(validator2.element($mobile2)) {
- setTimer();
- sendPost('common/captcha',{mobile: $mobile2.val(),type: 5,captchaToken: 5},function(){
- ask('请求失败')
- },function(res){
- if(res.status == 200){
- tip('发送成功','add')
- }else{
- tip('获取验证码失败')
- }
- })
- }
- })
- //提交
- $submit.click(function() {
- var index = $('.nav-tabs>li.active').index();
- var mobile = '',
- password = '',
- captcha = '';
- if(index == 0) { // 点击手机登陆选项卡
- if($("#form1").valid()){
- $(this).attr('disabled','disabled')
- mobile = $mobile1.val();
- password = $password.val();
- sendPost('login/public_key',{},function(){
- tip('请求失败')
- $submit.removeAttr('disabled')
- },function(res){
- if (res.status == 200) {
- var mod = res.data.modulus;
- var exp = res.data.exponent;
- key = RSAUtils.getKeyPair(exp, "", mod);
- if (key) {
- encryedPwd = RSAUtils.encryStr(key, password);
- login({
- mobile: mobile,
- password: encryedPwd,
- platform: 4
- })
- }else {
- tip("获取数据失败")
- $submit.removeAttr('disabled')
- }
- }
- })
- }
- }else{ // 点击验证码登录选项卡
- if($("#form2").valid()) {
- $(this).attr('disabled','disabled')
- mobile = $mobile2.val();
- captcha = $captcha.val();
- login({
- mobile: mobile,
- captcha: captcha,
- platform: 4
- })
- }
- }
- })
-
- }
- })
- //登录
- function login(data) {
- sendPost('login/doctor',data,function(){
- $submit.removeAttr('disabled')
- tip('请求失败')
- },function(res){
- $submit.removeAttr('disabled')
- if(res.status == 200) {
- var data = res.data;
- //添加医生到userRole
- localStorage.setItem('wlyyAgentForDoc',JSON.stringify(data))
- alert("登录成功")
- location.href = "app/record/html/record.html"
- }else{
- tip(res.msg)
- }
- })
- }
|