login.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  6. <title>后台登录</title>
  7. <link rel="stylesheet" href="__JS__/layui/css/layui.css">
  8. <link rel="stylesheet" href="__CSS__/admin.css">
  9. <link rel="stylesheet" href="__CSS__/login.css">
  10. <!--<link id="layuicss-layer" rel="stylesheet" href="__CSS__/layer.css" media="all">-->
  11. <script src="http://static.geetest.com/static/tools/gt.js"></script>
  12. <script>
  13. /*保证登录页面是顶级页面*/
  14. if(window.top!==window.self){window.top.location=window.location};
  15. </script>
  16. </head>
  17. <body layadmin-themealias="default">
  18. <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" >
  19. <div class="layadmin-user-login-main">
  20. <div class="layadmin-user-login-box layadmin-user-login-header">
  21. <h2>layui后台</h2>
  22. <p>后台管理系统</p>
  23. </div>
  24. <div class="layadmin-user-login-box layadmin-user-login-body">
  25. <form class="layui-form" onsubmit="return false;">
  26. <div class="layui-form-item">
  27. <label class="layadmin-user-login-icon layui-icon layui-icon-username"
  28. for="LAY-user-login-username"></label>
  29. <input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
  30. </div>
  31. <div class="layui-form-item">
  32. <label class="layadmin-user-login-icon layui-icon layui-icon-password"
  33. for="LAY-user-login-password"></label>
  34. <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
  35. </div>
  36. <div class="layui-form-item">
  37. <div class="layui-row">
  38. {if condition="config('verify_type') eq 1"}
  39. <div class="layui-col-xs7">
  40. <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
  41. for="LAY-user-login-vercode"></label>
  42. <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">
  43. </div>
  44. <div class="layui-col-xs5">
  45. <div style="margin-left: 10px;">
  46. <img src="{:url('checkVerify')}" onclick="javascript:this.src='{:url('checkVerify')}?tm='+Math.random();" style="float:right;cursor: pointer" id="verify"/>
  47. </div>
  48. </div>
  49. {elseif condition="config('verify_type') eq 2"/}
  50. <div class="layui-col-xs12" id="geeFa">
  51. <div id="embed-captcha"></div>
  52. </div>
  53. <p id="wait">正在加载验证码.... <i class="layui-icon layui-icon-loading-1 layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i></p>
  54. {/if}
  55. </div>
  56. </div>
  57. <div class="layui-form-item" style="margin-bottom: 20px;">
  58. <!--<input type="checkbox" name="remember" lay-skin="primary" title="记住密码">-->
  59. <!--<div class="layui-unselect layui-form-checkbox" lay-skin="primary"><span>记住密码</span><i-->
  60. <!--class="layui-icon layui-icon-ok"></i></div>-->
  61. <!--<a href="javascript:;" class="layadmin-user-jump-change layadmin-link" style="margin-top: 7px;">忘记密码?</a>-->
  62. </div>
  63. <div class="layui-form-item">
  64. <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="LAY-login">登 录</button>
  65. </div>
  66. </form>
  67. </div>
  68. </div>
  69. <div class="layui-trans layadmin-user-login-footer">
  70. <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
  71. </div>
  72. </div>
  73. <script src="__JS__/layui/layui.all.js"></script>
  74. <script src="__JS__/jquery.min.js"></script>
  75. <script src="__JS__/wk.js"></script>
  76. <script>
  77. $('#LAY-user-login-username').focus();
  78. var handlerEmbed = function (captchaObj) {
  79. $("#embed-submit").click(function (e) {
  80. var validate = captchaObj.getValidate();
  81. if (!validate) {
  82. $("#notice")[0].className = "show";
  83. setTimeout(function () {
  84. $("#notice")[0].className = "hide";
  85. }, 2000);
  86. e.preventDefault();
  87. }
  88. });
  89. // 将验证码加到id为captcha的元素里
  90. captchaObj.appendTo("#embed-captcha");
  91. captchaObj.onReady(function () {
  92. $("#wait")[0].className = "layui-hide";
  93. });
  94. // 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
  95. };
  96. var geeCheck = function(){
  97. $.ajax({
  98. // 获取id,challenge,success(是否启用failback)
  99. url: "{:url('getVerify',array('t'=>time()))}", // 加随机数防止缓存
  100. type: "get",
  101. dataType: "json",
  102. success: function (data) {
  103. // 使用initGeetest接口
  104. // 参数1:配置参数
  105. // 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
  106. initGeetest({
  107. gt: data.gt,
  108. challenge: data.challenge,
  109. product: "float", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
  110. offline: !data.success, // 表示用户后台检测极验服务器是否宕机,一般不需要关注
  111. width:"100%",
  112. }, handlerEmbed);
  113. }
  114. });
  115. }
  116. if('{:config('verify_type')}' == 2){
  117. geeCheck();
  118. }
  119. layui.use('form', function(){
  120. var form = layui.form;
  121. //监听提交
  122. form.on('submit(LAY-login)', function(data){
  123. $(".layui-btn").addClass('layui-disabled').attr('disabled','disabled').html('登录中... &nbsp;<i class="layui-icon layui-icon-loading-1 layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>');
  124. $.ajax({
  125. url:"{:url('doLogin')}",
  126. type:'post',
  127. dataType:'json',
  128. data:data.field,
  129. success:function(res){
  130. if(res.code == 1){
  131. setTimeout(function(){
  132. location.href=res.url;
  133. },1500);
  134. }else{
  135. layer.msg(res.msg,{icon:2,time:1500,anim: 6},function(index){
  136. if('{:config('verify_type')}' == 2 && res.code != -3){
  137. $("#wait").removeClass('layui-hide');
  138. $('#embed-captcha').remove();
  139. $('#geeFa').append('<div id="embed-captcha"></div>')
  140. geeCheck();
  141. }else if('{:config('verify_type')}' == 1){
  142. $('#verify').attr("src","{:url('checkVerify')}?tm="+Math.random());
  143. }
  144. switch(res.code)
  145. {
  146. case -1:
  147. $('#LAY-user-login-username').focus();
  148. break;
  149. case -2:
  150. $('#LAY-user-login-password').focus();
  151. break;
  152. case -4:
  153. $('#LAY-user-login-vercode').focus();
  154. break;
  155. }
  156. layer.close(index);
  157. })
  158. $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled').text("登 录");
  159. return false;
  160. }
  161. }
  162. ,error:function(event, xhr, options, exc){
  163. switch (event.status) {
  164. case 403:
  165. wk.error('403:禁止访问...');
  166. break;
  167. case 404:
  168. wk.error('404:请求服务器出错...');
  169. break;
  170. case 500:
  171. wk.error('500:服务器错误...');
  172. break;
  173. }
  174. $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled').text("登 录");
  175. }
  176. })
  177. });
  178. });
  179. //防止页面后退
  180. history.pushState(null, null, document.URL);
  181. window.addEventListener('popstate', function () {
  182. history.pushState(null, null, document.URL);
  183. });
  184. </script>
  185. </body>
  186. </html>