login.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. function uuid(len, radix) {
  180. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  181. var uuid = [], i;
  182. radix = radix || chars.length;
  183. if (len) {
  184. // Compact form
  185. for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
  186. } else {
  187. // rfc4122, version 4 form
  188. var r;
  189. // rfc4122 requires these characters
  190. uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
  191. uuid[14] = '4';
  192. // Fill in random data. At i==19 set the high bits of clock sequence as
  193. // per rfc4122, sec. 4.1.5
  194. for (i = 0; i < 36; i++) {
  195. if (!uuid[i]) {
  196. r = 0 | Math.random()*16;
  197. uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
  198. }
  199. }
  200. }
  201. return uuid.join('');
  202. }
  203. var IMEI = localStorage.getItem('WLYY_IMEI') || uuid(16, 16)
  204. localStorage.setItem('WLYY_IMEI', IMEI)
  205. </script>
  206. <script>
  207. $(function() {
  208. var Requests = GetRequest();
  209. var redirect_url = Requests.redirect_url;
  210. var userAgent = Requests.userAgent;
  211. var agentName = "wlyyAgent";
  212. toastr.options = {
  213. "closeButton": true,
  214. "positionClass": "toast-top-center"
  215. }
  216. var $eyeIcon = $('.psw-eye'),
  217. $mobile1 = $('#mobile1'),
  218. $password = $('#password'),
  219. $mobile2 = $('#mobile2'),
  220. $captcha = $('#captcha'),
  221. $mobile = $('input[mobile]'),
  222. $tabs = $('.nav-tabs'),
  223. $getCaptcha = $('#getCaptcha'),
  224. $submit = $('button[type="submit"]');
  225. var timer = null;
  226. if(userAgent) {
  227. userAgent = decodeURIComponent(userAgent)
  228. localStorage.setItem(agentName, userAgent)
  229. return ;
  230. }
  231. function login(data) {
  232. loginApis.login(data)
  233. .then(function(res) {
  234. $submit.removeAttr('disabled')
  235. if(res.status == 200) {
  236. var data = res.data;
  237. localStorage.setItem(agentName,JSON.stringify({
  238. id: data.id,
  239. uid: data.uid,
  240. token: data.token,
  241. imei: localStorage.getItem('WLYY_IMEI'),
  242. platform: 4
  243. }))
  244. if(redirect_url) {
  245. window.location.href = decodeURIComponent(redirect_url)
  246. }
  247. } else {
  248. toastr.error(res.msg || "登录失败!")
  249. }
  250. })
  251. .catch(function(e) {
  252. $submit.removeAttr('disabled')
  253. console && console.error(e)
  254. })
  255. }
  256. function setTimer() {
  257. $getCaptcha.addClass('disabled');
  258. var seconds = 59;
  259. timer = setInterval(function() {
  260. if(seconds == 0) {
  261. clearInterval(timer);
  262. timer = null;
  263. seconds = 59;
  264. $getCaptcha.text("获取验证码");
  265. $getCaptcha.removeClass('disabled');
  266. return ;
  267. }
  268. $getCaptcha.text((seconds--)+"s后重新获取");
  269. }, 1000)
  270. }
  271. $eyeIcon.click(function() {
  272. $el = $(this);
  273. if($el.hasClass('fa-eye')) {
  274. $el.removeClass('fa-eye').addClass('fa-eye-slash');
  275. $password.attr('type','password')
  276. } else {
  277. $el.removeClass('fa-eye-slash').addClass('fa-eye');
  278. $password.attr('type','text')
  279. }
  280. })
  281. $getCaptcha.click(function() {
  282. if($getCaptcha.hasClass('disabled')) {
  283. return ;
  284. }
  285. if(validator2.element($mobile2)) {
  286. setTimer();
  287. loginApis.getCaptcha({
  288. mobile: $mobile2.val(),
  289. type: 5,
  290. captchaToken: 5
  291. }).then(function(res) {
  292. if(res.status == 200) {
  293. toastr.success("短信发送成功!")
  294. } else {
  295. toastr.error(res.msg || "短信发送失败!")
  296. }
  297. }).catch(function(e) {
  298. console && console.error(e)
  299. })
  300. }
  301. })
  302. $submit.click(function() {
  303. var index = $('.nav-tabs>li.active').index();
  304. var mobile = '',
  305. password = '',
  306. captcha = '';
  307. if(index == 0) { // 点击手机登陆选项卡
  308. if($("#form1").valid()) {
  309. $(this).attr('disabled','disabled')
  310. mobile = $mobile1.val();
  311. password = $password.val();
  312. loginApis.publicKey().then(function(res) {
  313. if (res.status == 200) {
  314. var mod = res.data.modulus;
  315. var exp = res.data.exponent;
  316. key = RSAUtils.getKeyPair(exp, "", mod);
  317. if (key) {
  318. encryedPwd = RSAUtils.encryStr(key, password);
  319. login({
  320. mobile: mobile,
  321. password: encryedPwd
  322. })
  323. }else {
  324. toastr.error(res.msg || "登录失败!")
  325. $submit.removeAttr('disabled')
  326. }
  327. }
  328. })
  329. }
  330. } else { // 点击验证码登录选项卡
  331. if($("#form2").valid()) {
  332. $(this).attr('disabled','disabled')
  333. mobile = $mobile2.val();
  334. captcha = $captcha.val();
  335. login({
  336. mobile: mobile,
  337. captcha: captcha
  338. })
  339. }
  340. }
  341. })
  342. var validator1 = $("#form1").validate({
  343. onsubmit: false,
  344. onfocusout: function(ele) {
  345. validator1.element(ele)
  346. },
  347.    rules: {
  348.       mobile1: {
  349. required: true,
  350. mobile: true,
  351. },
  352.    password: "required",
  353. }
  354. });
  355. var validator2 = $("#form2").validate({
  356. onsubmit: false,
  357. onfocusout: function(ele) {
  358. validator2.element(ele)
  359. },
  360.    rules: {
  361.       mobile2: {
  362. required: true,
  363. mobile: true,
  364. },
  365.    captcha: "required",
  366. }
  367. });
  368. $tabs.on('click','li',function() {
  369. var idx = $(this).index(),
  370. mob = '';
  371. if(idx == 1) { // 点击验证码登录选项卡
  372. mob = $mobile1.val();
  373. if(mob) {
  374. $mobile.val(mob);
  375. validator2.element($mobile2)
  376. }
  377. } else { // 点击手机登陆选项卡
  378. mob = $mobile2.val();
  379. if(mob) {
  380. $mobile.val(mob);
  381. validator1.element($mobile1)
  382. }
  383. }
  384. })
  385. //$("#form1").valid();
  386. jQuery.validator.addMethod("mobile", function(value, element, param) {
  387. var reg=/^[1][3,4,5,7,8][0-9]{9}$/;
  388. return reg.test(value);
  389. }, "手机号码有误");
  390. })
  391. </script>
  392. </body>
  393. </html>