login.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>登录</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="renderer" content="webkit">
  8. <meta http-equiv="Cache-Control" content="no-siteapp" />
  9. <meta name="keywords" content="登录">
  10. <meta name="description" content="登录">
  11. <!--[if lt IE 9]>
  12. <meta http-equiv="refresh" content="0;ie.html" />
  13. <![endif]-->
  14. <link rel="shortcut icon" href="favicon.ico">
  15. <link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
  16. <link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
  17. <link href="css/animate.min.css" rel="stylesheet">
  18. <link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
  19. <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
  20. <style>
  21. body {
  22. background: url(img/BG.jpg);
  23. }
  24. #main {
  25. width: 1200px;
  26. margin: 0 auto;
  27. }
  28. .tabs-container {
  29. margin-top: 40;
  30. border: 10px solid rgba(255,255,255,0.2);
  31. }
  32. .tabs-container .nav-tabs {
  33. border: 0;
  34. }
  35. .nav.nav-tabs {
  36. background-color: #fff;
  37. }
  38. .nav.nav-tabs li {
  39. width: 50%;
  40. text-align: center;
  41. padding: 0 15px;
  42. }
  43. .nav.nav-tabs li.active a {
  44. color: #1eaaff;
  45. }
  46. .tabs-container .nav-tabs>li.active>a,
  47. .tabs-container .nav-tabs>li.active>a:focus,
  48. .tabs-container .nav-tabs>li.active>a:hover {
  49. border: 0;
  50. border-bottom: 3px solid #1eaaff;
  51. }
  52. #loginForm {
  53. margin-top: 120px;
  54. }
  55. button[type="submit"] {
  56. margin-top: 40px;
  57. }
  58. .form-group {
  59. position: relative;
  60. }
  61. .fa-eye,
  62. .fa-eye-slash {
  63. position: absolute;
  64. top: 16px;
  65. right: 10px;
  66. margin-top: -8px;
  67. font-size: 16px;
  68. cursor: pointer;
  69. }
  70. #getCaptcha {
  71. position: absolute;
  72. top: 8px;
  73. right: 10px;
  74. }
  75. #getCaptcha.disabled{
  76. cursor: not-allowed;
  77. filter: alpha(opacity=65);
  78. -webkit-box-shadow: none;
  79. box-shadow: none;
  80. opacity: .65;
  81. }
  82. @media only screen and (max-width: 1200px) {
  83. #main,.left-img,#loginForm {
  84. width: 100%;
  85. }
  86. #loginForm {
  87. margin-top: 0px;
  88. }
  89. .left-img > img{
  90. display: block;
  91. width: 400px;
  92. margin: 0 auto;
  93. }
  94. .tabs-container {
  95. width: 400px;
  96. margin: -40px auto 0;
  97. }
  98. }
  99. </style>
  100. <div id="main">
  101. <div class="row">
  102. <div class="col-sm-8 left-img">
  103. <img src="img/icon_chahua.png" />
  104. </div>
  105. <div id="loginForm" class="col-sm-4">
  106. <div class="tabs-container">
  107. <ul class="nav nav-tabs">
  108. <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">手机号登录</a>
  109. </li>
  110. <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">验证码登录</a>
  111. </li>
  112. </ul>
  113. <div class="tab-content">
  114. <div id="tab-1" class="tab-pane active">
  115. <div class="panel-body">
  116. <form id="form1" class="m-t" role="form" onsubmit="return false;">
  117. <div class="form-group">
  118. <input id="mobile1" mobile type="text" name="mobile1" class="form-control" placeholder="请输入手机号码" required="">
  119. </div>
  120. <div class="form-group">
  121. <input id="password" type="password" name="password" class="form-control" placeholder="初始密码为手机号码后六位" required="">
  122. <i class="fa fa-eye-slash psw-eye" aria-hidden="true"></i>
  123. </div>
  124. <button type="submit" class="btn btn-success block full-width m-b">登 录</button>
  125. <p class="text-muted text-center"> <a href="login.html#"><small>忘记密码了?</small></a> | <a href="register.html">注册一个新账号</a>
  126. </p>
  127. </form>
  128. </div>
  129. </div>
  130. <div id="tab-2" class="tab-pane">
  131. <div class="panel-body">
  132. <form id="form2" class="m-t" role="form" onsubmit="return false;">
  133. <div class="form-group">
  134. <input id="mobile2" name="mobile2" mobile type="text" class="form-control" placeholder="请输入手机号码" required="">
  135. </div>
  136. <div class="form-group">
  137. <input id="captcha" name="captcha" type="text" class="form-control" placeholder="请输入短信验证码" required="">
  138. <a id="getCaptcha" href="javascript:void(0);">获取验证码</a>
  139. </div>
  140. <button type="submit" class="btn btn-success block full-width m-b">登 录</button>
  141. </form>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </head>
  150. <body >
  151. <script src="js/jquery.min.js?v=2.1.4"></script>
  152. <script src="js/bootstrap.min.js?v=3.3.6"></script>
  153. <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
  154. <script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
  155. <script src="js/plugins/layer/layer.min.js"></script>
  156. <script src="js/hplus.min.js?v=4.1.0"></script>
  157. <script type="text/javascript" src="js/contabs.min.js"></script>
  158. <script src="js/plugins/pace/pace.min.js"></script>
  159. <script src="js/plugins/validate/jquery.validate.min.js"></script>
  160. <script src="js/plugins/validate/messages_zh.min.js"></script>
  161. <script src="js/plugins/toastr/toastr.min.js"></script>
  162. <script src="js/security.js"></script>
  163. <script src="js/api-service.js"></script>
  164. <script src="js/login-api.js"></script>
  165. <script>
  166. //获取链接上的参数
  167. function GetRequest() {
  168. var url = location.search; //获取url中"?"符后的字串
  169. var theRequest = new Object();
  170. if (url.indexOf("?") != -1) {
  171. var str = url.substr(1);
  172. strs = str.split("&");
  173. for (var i = 0; i < strs.length; i++) {
  174. theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  175. }
  176. }
  177. return theRequest;
  178. }
  179. </script>
  180. <script>
  181. $(function() {
  182. var Requests = GetRequest();
  183. var redirect_url = Requests.redirect_url;
  184. var userAgent = Requests.userAgent;
  185. var agentName = "wlyyAgent";
  186. toastr.options = {
  187. "closeButton": true,
  188. "positionClass": "toast-top-center"
  189. }
  190. var $eyeIcon = $('.psw-eye'),
  191. $mobile1 = $('#mobile1'),
  192. $password = $('#password'),
  193. $mobile2 = $('#mobile2'),
  194. $captcha = $('#captcha'),
  195. $mobile = $('input[mobile]'),
  196. $tabs = $('.nav-tabs'),
  197. $getCaptcha = $('#getCaptcha'),
  198. $submit = $('button[type="submit"]');
  199. var timer = null;
  200. if(userAgent) {
  201. userAgent = decodeURIComponent(userAgent)
  202. localStorage.setItem(agentName, userAgent)
  203. return ;
  204. }
  205. function login(data) {
  206. loginApis.login(data)
  207. .then(function(res) {
  208. $submit.removeAttr('disabled')
  209. if(res.status == 200) {
  210. var data = res.data;
  211. localStorage.setItem(agentName,JSON.stringify({
  212. id: data.id,
  213. uid: data.uid,
  214. token: data.token,
  215. imei: localStorage.getItem('WLYY_IMEI'),
  216. platform: 4
  217. }))
  218. if(redirect_url) {
  219. window.location.href = decodeURIComponent(redirect_url)
  220. }
  221. } else {
  222. toastr.error(res.msg || "登录失败!")
  223. }
  224. })
  225. .catch(function(e) {
  226. $submit.removeAttr('disabled')
  227. console && console.error(e)
  228. })
  229. }
  230. function setTimer() {
  231. $getCaptcha.addClass('disabled');
  232. var seconds = 59;
  233. timer = setInterval(function() {
  234. if(seconds == 0) {
  235. clearInterval(timer);
  236. timer = null;
  237. seconds = 59;
  238. $getCaptcha.text("获取验证码");
  239. $getCaptcha.removeClass('disabled');
  240. return ;
  241. }
  242. $getCaptcha.text((seconds--)+"s后重新获取");
  243. }, 1000)
  244. }
  245. $eyeIcon.click(function() {
  246. $el = $(this);
  247. if($el.hasClass('fa-eye')) {
  248. $el.removeClass('fa-eye').addClass('fa-eye-slash');
  249. $password.attr('type','password')
  250. } else {
  251. $el.removeClass('fa-eye-slash').addClass('fa-eye');
  252. $password.attr('type','text')
  253. }
  254. })
  255. $getCaptcha.click(function() {
  256. if($getCaptcha.hasClass('disabled')) {
  257. return ;
  258. }
  259. if(validator2.element($mobile2)) {
  260. setTimer();
  261. loginApis.getCaptcha({
  262. mobile: $mobile2.val(),
  263. type: 5,
  264. captchaToken: 5
  265. }).then(function(res) {
  266. if(res.status == 200) {
  267. toastr.success("短信发送成功!")
  268. } else {
  269. toastr.error(res.msg || "短信发送失败!")
  270. }
  271. }).catch(function(e) {
  272. console && console.error(e)
  273. })
  274. }
  275. })
  276. $submit.click(function() {
  277. var index = $('.nav-tabs>li.active').index();
  278. var mobile = '',
  279. password = '',
  280. captcha = '';
  281. if(index == 0) { // 点击手机登陆选项卡
  282. if($("#form1").valid()) {
  283. $(this).attr('disabled','disabled')
  284. mobile = $mobile1.val();
  285. password = $password.val();
  286. loginApis.publicKey().then(function(res) {
  287. if (res.status == 200) {
  288. var mod = res.data.modulus;
  289. var exp = res.data.exponent;
  290. key = RSAUtils.getKeyPair(exp, "", mod);
  291. if (key) {
  292. encryedPwd = RSAUtils.encryStr(key, password);
  293. login({
  294. mobile: mobile,
  295. password: encryedPwd
  296. })
  297. }else {
  298. toastr.error(res.msg || "登录失败!")
  299. $submit.removeAttr('disabled')
  300. }
  301. }
  302. })
  303. }
  304. } else { // 点击验证码登录选项卡
  305. if($("#form2").valid()) {
  306. $(this).attr('disabled','disabled')
  307. mobile = $mobile2.val();
  308. captcha = $captcha.val();
  309. login({
  310. mobile: mobile,
  311. captcha: captcha
  312. })
  313. }
  314. }
  315. })
  316. var validator1 = $("#form1").validate({
  317. onsubmit: false,
  318. onfocusout: function(ele) {
  319. validator1.element(ele)
  320. },
  321.    rules: {
  322.       mobile1: {
  323. required: true,
  324. mobile: true,
  325. },
  326.    password: "required",
  327. }
  328. });
  329. var validator2 = $("#form2").validate({
  330. onsubmit: false,
  331. onfocusout: function(ele) {
  332. validator2.element(ele)
  333. },
  334.    rules: {
  335.       mobile2: {
  336. required: true,
  337. mobile: true,
  338. },
  339.    captcha: "required",
  340. }
  341. });
  342. $tabs.on('click','li',function() {
  343. var idx = $(this).index(),
  344. mob = '';
  345. if(idx == 1) { // 点击验证码登录选项卡
  346. mob = $mobile1.val();
  347. if(mob) {
  348. $mobile.val(mob);
  349. validator2.element($mobile2)
  350. }
  351. } else { // 点击手机登陆选项卡
  352. mob = $mobile2.val();
  353. if(mob) {
  354. $mobile.val(mob);
  355. validator1.element($mobile1)
  356. }
  357. }
  358. })
  359. //$("#form1").valid();
  360. jQuery.validator.addMethod("mobile", function(value, element, param) {
  361. var reg=/^[1][3,4,5,7,8][0-9]{9}$/;
  362. return reg.test(value);
  363. }, "手机号码有误");
  364. })
  365. </script>
  366. </body>
  367. </html>