xinyb
2024-06-19 d4f9eb07c191f2c1660f8b8701225a288038c10d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
 var isonescore='';
 var hostUrl='';
 var SessionKey='data_base_id';
 var oauth2HostName='';
 var loginSelectArr;//登录时账号多个角色时候存放集合
 // var logov='';
 var rsakey={
     pubkey:"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkRupiYcKVGGUtDBDoR1t/1zm3ZtZgnte39iTJW6hlqjdY0UagKjpNiIv7J6XjtgfX7SgsR4AWnivqQHAICIvdPKfGZZzIs62OQ19MqrDTMoB/LvK5teNWhClv23WMUfRbP+EHgprT6hTw8U5apw1IB6i/y57NkLav792wiYBYRU4X45NoTaT+aiTSLFEflbfm94EXnhSS3vFkBmrZGy5BRNI8gmzafroslGx2Hk90CqlNdeKYxgZQ6xtvj+u33yrszWvPT6F9fsJT8aMjtvH050iYKRVct+x6Q7VRJgCI4MgvAexnTKdxW54YzvXCuO5bDiy5la7CgerWkTAq9dzXwIDAQAB"
 };
(function($) {    
    $.Read=function(){        
        var _this=this;
        var select;
        var browserName = myexplorer();
        if (browserName && browserName != "" && browserName != "谷歌") {
            $(".tips").show();  
            alert("您正在使用 " + browserName +" 浏览器,强烈推荐您使用【谷歌】浏览器登录系统!");
        }else {
            $(".tips").hide(); 
        }
                
        if(window.parent.length>0){
            window.parent.location=hostUrl+'/login.jsp';
        }
        
        if($("#snDiv").is(":visible")){
             $("#cltsn").focus(); 
        } else{
             $("#name").focus(); 
        }
        
        //系统下拉选择
        this.setDate=function(event){
            if(event.selectedIndex!=-1){
                var text=event.options[event.selectedIndex].text;
                var version = $(event.options[event.selectedIndex]).attr("version");
                    $.post('/getDateDemo.do',{'id':event.value,"dataBaseDis":text,"version":version},function(data){
                        if(data!=null&&$.trim(data)!=""){
                            if(data.indexOf("<html>")!=-1){
                                location = "/home.jsp";
                                return;
                            }
                            alert(data);
                        }
                    });
                //设置有LOGO加载
                $('.login_logo img').attr('src','/getLogoIcon.do?dbid='+event.value);
             }    
            select=event;                         
        }
        
        this.reloadCode=function(i,event) { 
                 if(null!=event){
                     event.src="/imageCode?rand="+i; 
                 }                     
        }
        
        this.initValue=function(){
            if(select.selectedIndex!=-1){
                var text=select.options[select.selectedIndex].text;
                $("#dataBaseDis").val(text);
                return;
            }
        }
        
        this.disableButton=function(){
             $("#sub").attr("disabled",true);
             $("#sub").css("background-color","#bec4c8");
         }
        
        $("#sub").click(function(){
            _this.disableButton();
            var flg=false;
            var isAccount=$($(".nav_tab")[0]).hasClass("active");//是否是账号登录,flse表示短信登录
            if($("#snDiv").is(":visible") && isAccount){
                if($("#cltsn").val()==""){
                    $(".cltsn").find("span").html("请输入通行证");
                     $("#cltsn").addClass("errorinput");
                }
                flg=true;
            } 
            if($("#name").val()=="" && isAccount){
                $(".name").find("span").html("请输入账号 / 手机号");
                 $("#name").addClass("errorinput");
                flg=true;
            }
            if($("#pwd").val()=="" && isAccount){
                $(".pwd").find("span").html("请输入密码");
                $("#pwd").addClass("errorinput");
                flg=true;
            }
            if($("#code").val()=="" && isAccount){
                $(".code").find("span").html("请输入验证码");
                $("#code").addClass("errorinput");
                flg=true;
            }
            //短信登录验证
            if($("#telephone").val()=="" && !isAccount){
                $(".telephone").find("span").html("请输入手机号码");
                $("#telephone").addClass("errorinput");
                flg=true;
            }
            if($("#phoneCode").val()=="" && !isAccount){
                $(".phoneCode").find("span").html("请输入手机验证码");
                $("#phoneCode").addClass("errorinput");
                flg=true;
            }
            
            if(flg){
                removeDisableButton();
                return false;
            }
 
            if(!flg && ""==select.value && isonescore==""){            
                $(".login_select").find("span").html("请选择一个系统");
                if(!$(".select").hasClass('l_select')){
                    $(".select").addClass('l_select');
                }
                $(".login_select").show()
                removeDisableButton();
                return false;
            }
            if($("#name").val()!=""&&$("#pwd").val()!=""&&$("#code").val()!=""){
                _this.initValue();
                if(typeof(isonescore)!="undefined"&&isonescore!=""){
                    $("#isone").val(isonescore);
                }
                var encrypt = new JSEncrypt();
                encrypt.setPublicKey(rsakey.pubkey);
                var encryptPwd = encrypt.encrypt($("#pwd").val());
                var encryptUser = encrypt.encrypt($("#name").val());
                //登录请求
                loginRequest(encryptUser,encryptPwd,select.value);
            }else if($("#telephone").val()!="" && $("#phoneCode").val()!=""){
                //短信登录
                loginRequest("","",select.value);
            }            
        });
        
        $("#name").keydown(function(e){
            var e=e||window.event;
            if(e.keyCode==13){//回车键
                $("#pwd").focus();
            }    
        });
        
        $("#pwd").keydown(function(e){
            var e=e||window.event;
            if(e.keyCode==13){//回车键
            if(document.getElementById("code")){
                $("#code").focus();
                return;
            }
                $("#sub").click();
            }    
        });
        
        $("#code").keydown(function(e){
            var e=e||window.event;
            if(e.keyCode==13){//回车键
                $("#sub").click();
            }    
        });
        
        $("#reset").click(function(){
            $("#name").val("");
            $("#pwd").val("");
            $("#code").val("");
            $("#name").focus();
            
        });    
        // $("#ppwd").keyup(function() {
        //     $("#pwd").val(hex_md5($("#ppwd").attr("value"))); 
             
        // });
        
        // $(".sub_button").click(function(){
        //     _this.initValue();
        // });
 
        $("#randomming").click(function(){
            _this.reloadCode(Math.random(),this);      
        });       
        
        $(".pop-sns-weixin-m").on("touchstart",function () {
            $(".icon-weixin-m").addClass("weixin-hover");
        });
        $(".pop-sns-qq-m").on("touchstart",function () {
            $(".icon-qq-m").addClass("qq-hover");
        });
        $(".pop-sns-weixin-m").on("touchend",function () {
            $(".icon-weixin-m").removeClass("weixin-hover");
        });
        $(".pop-sns-qq-m").on("touchend",function () {
            $(".icon-qq-m").removeClass("qq-hover");
        });        
        
        $("#dataName").change(function(){
            _this.setDate(this);
        });
        
        $("#dataName").click(function(){
            _this.setDate(this);
        });
        $("#dataName").triggerHandler('click');
        $("#randomming").triggerHandler('click');
        
        $(".pop-sns-weixin").click(function () {
            if(select.selectedIndex==-1){
                alert("必须选择一个账套");
                return ;
             }
            try{
                layer.open({
                      title:'微信二维码',
                      type: 1,
                      resize :false,
                      maxWidth:500,
                      content:'<div style="text-align:center;">'+
                              '<iframe src="'+oauth2HostName+'/oauth2/weixin.do?'+SessionKey + '=' + select.value + '&orghost='
                              + hostUrl+'&SelfRedirect=false" style="width:400px;height:400px;border:1px solid #CCC;"></iframe></div>',
                      end :function(){//关闭二维码层,执行刷新当前页面
                          location.reload();
                      }
                    });
        }catch(e){
            
        }  
            //location = oauth2HostName+"/oauth2/weixin.do?"+SessionKey+"="+select.value+"&orghost="+hostUrl;
        });
        
        $(".pop-sns-qq").click(function () {
            if(select.selectedIndex==-1){
                alert("必须选择一个账套");
                return ;
             }
            location.href=oauth2HostName+'/oauth2/qq.do?'+SessionKey + '=' + select.value + '&orghost='+ hostUrl+'&SelfRedirect=false';
        //     try{
        //         layer.open({
        //               title:'QQ二维码',
        //               type: 1,
        //               resize :false,
        //               maxWidth:500,
        //               content:'<div style="text-align:center;">'+
        //                       '<iframe src="'+oauth2HostName+'/oauth2/qq.do?'+SessionKey + '=' + select.value + '&orghost='
        //                       + hostUrl+'&SelfRedirect=false" style="width:550px;height:400px;border:1px solid #CCC;"></iframe></div>',
        //               end :function(){//关闭二维码层,执行刷新当前页面
        //                   location.reload();
        //               }
        //             });
        // }catch(e){
        //
        // }
            //location =oauth2HostName+"/oauth2/qq.do?"+SessionKey+"="+select.value+"&orghost="+hostUrl;
        });     
 
        //maintaince.dbid=select.value;
    //    maintaince.isStop='false';
        //setInterval(maintaince.checkSysIsExpired, 10000);//10秒调用一次
        //checkSysIsExpired('<%=dbId%>','false');  //检查系统是否停止使用 Added by Johns Wang ,2017-05-26
        
        
        // 登录方式切换
        $(".nav_tab").on("click", function () {
            if(!$(this).hasClass('active')){
                 $(".nav_tab").removeClass("active");
                 $(this).addClass("active");
                 $(".login_form").hide();
                 $(".login_form").eq($(".nav_tab").index(this)).show();
                 if($(".nav_tab").index(this)==1){
                     $("#name").val("");
                    $("#pwd").val("");
                 }
            }
        });
        //二维码切换
        $(".qrcode_login").on("click", function () {
            if(!$(this).hasClass("active")){
                $(this).addClass("active");
                $('.login-password').hide();
                $('.qrcode-logins').show();    
                //获取二维码
                _this.createqrCode();                                                           
            }else{
                if(webSocket!=null){
                    $(this).removeClass("active");
                    $('.login-password').show();
                    $('.qrcode-logins').hide();
                    webSocketClose();//关闭链接
                    webSocket=null;
                }                
            }            
        });
        // 获取验证码按钮
        var countTime = 60;  //倒计时时间
        var isCount = false; // 是否倒计时中
        // 获取验证码按钮点击事件
        $(".get_phoneCode").click(function () {
            var phone=$("#telephone").val();
            if(!(/^1[3456789]\d{9}$/.test(phone))){ 
                $(".telephone").find("span").html("请输入正确的手机号码");
                $("#telephone").addClass("errorinput");
                return; 
            } 
          if (isCount) {
            return;
          }
          $(".get_phoneCode").addClass('is-disabled');          
         // 获取验证码
          $.post('/ws/phoneCode.do',{'dbId':select.value,'telephone':phone,'type':1},function(r){
              if(r!=null){
                  if(r.code && r.code==-1){
                      layer.msg(r.info);
                      return;
                  }
                  isCount = true;          
                  countDown();
                  function countDown() {
                    setTimeout(function () {
                      countTime--;
                      $(".get_phoneCode").text(countTime+'秒后再获取')
                      if (countTime>0){
                        countDown()
                      } else {
                        isCount = false;
                        countTime = 60;
                        $(".get_phoneCode").text('获取验证码').removeClass('is-disabled')
                      }
                    }, 1000)
                  }
              }
          });
        });
        
       //二维码过期刷新
        $('.qrcode-error a').on('click',function(){
            //获取二维码
            _this.createqrCode();            
        });
        
        //生成二维码图片
        this.createqrCode=function(){
            $(".qrcode-error").hide(); 
            $.post("/ws/qrCode.do?appId="+select.value,function(res){
                if(res!=null && res.code==0){
                    $(".qrcode-logins").find("img").attr("src",res.data.url);
                    initWebSocket(hostUrl+"/ws/qrLogin/"+select.value+"/"+res.data.qrcode+"/0",res.data.qrcode);
                }else{
                    alert(res.msg);
                    webSocket=-1;
                }                
            },"json").error(function(e){
                webSocket=-1;
                alert(e.responseText);
                $(".qrcode-logins").find("img").attr("src","");
            }); 
        }
    }          
})(jQuery); 
//登录请求
function loginRequest(encryptUser,encryptPwd,dataName){
    $.ajax({
        type:"POST",
        url: $("#hostUrl").val()+"/login.do",
        //contentType: "application/json", //如果提交的是json数据类型,则必须有此参数,表示提交的数据类型
        dataType: "json", //表示返回值类型,不必须
        data:{
            "account":encryptUser,
            'pwd': encryptPwd,
            'code': $("#code").val(),
            'redirect': $("#redirect").val(),
            'cltsn': $("#cltsn").val(),
            "dataName":dataName,
            "isone":$("#isone").val(),
            "telephone":$("#telephone").val(),
            "phoneCode":$("#phoneCode").val()
            },
        success: function (jsonResult) {
            if(jsonResult!=undefined &&jsonResult!=null){
                if (jsonResult.state == -1009) {//存在多个角色的账号
                    loginSelectArr=jsonResult.data;
                    layer.open({
                        title:'请选择登录身份',
                        type: 2,
                        closeBtn:0,
                        offset:'60px',//只定义top坐标,水平保持居中
                        area: ['500px', '600px'],
                        content: '/general/loginSelect/loginSelect.html'
                    });
                    return false;
                }
                var redirect="";
                if(jsonResult.data!=undefined &&jsonResult.data!=""){
                    var json=JSON.parse(jsonResult.data);
                    redirect=json.redirect;
 
                }
                if(jsonResult.state==-1){//出错
                    removeDisableButton();
                    alert(jsonResult.msg);
                }else{
                    var url=$("#hostUrl").val()+"/home.jsp";
                    if(redirect!=""){
                        url+="?redirect="+redirect;
                    }                           
                    window.location.replace(url);                    
                }
            }
    },
    error: function (data){
        removeDisableButton();
        let msg = data.responseText || "登录请求失败!";//显示错误信息 xin 2022-8-19 17:36:38
        alert(msg);
    }
    });
}
 
function removeDisableButton(){
    $("#sub").attr("disabled",false);
    $("#sub").css("background-color","#116eab");
}
function loginRefresh(){
    layer.closeAll();
    window.location.href= hostUrl + "/home.jsp";
}
 
$(function(){
    hostUrl=$('#hostUrl').val();
    isonescore=$('#isonescore').val();
    SessionKey=$('#SessionKey').val();
    oauth2HostName=$('#oauth2HostName').val();
    // logov=$('#logov').val();
    $.Read();
});