login.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 = APIService.agentName;
  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. if(userAgent.imei) {
  204. localStorage.setItem('WLYY_IMEI',userAgent.imei)
  205. }
  206. return ;
  207. }
  208. function login(data) {
  209. loginApis.login(data)
  210. .then(function(res) {
  211. $submit.removeAttr('disabled')
  212. if(res.status == 200) {
  213. var data = res.data;
  214. localStorage.setItem(agentName,JSON.stringify({
  215. id: data.id,
  216. uid: data.uid,
  217. token: data.token,
  218. imei: localStorage.getItem('WLYY_IMEI'),
  219. platform: 4
  220. }))
  221. if(redirect_url) {
  222. window.location.href = decodeURIComponent(redirect_url)
  223. }
  224. } else {
  225. toastr.error(res.msg || "登录失败!")
  226. }
  227. })
  228. .catch(function(e) {
  229. $submit.removeAttr('disabled')
  230. console && console.error(e)
  231. })
  232. }
  233. function setTimer() {
  234. $getCaptcha.addClass('disabled');
  235. var seconds = 59;
  236. timer = setInterval(function() {
  237. if(seconds == 0) {
  238. clearInterval(timer);
  239. timer = null;
  240. seconds = 59;
  241. $getCaptcha.text("获取验证码");
  242. $getCaptcha.removeClass('disabled');
  243. return ;
  244. }
  245. $getCaptcha.text((seconds--)+"s后重新获取");
  246. }, 1000)
  247. }
  248. $eyeIcon.click(function() {
  249. $el = $(this);
  250. if($el.hasClass('fa-eye')) {
  251. $el.removeClass('fa-eye').addClass('fa-eye-slash');
  252. $password.attr('type','password')
  253. } else {
  254. $el.removeClass('fa-eye-slash').addClass('fa-eye');
  255. $password.attr('type','text')
  256. }
  257. })
  258. $getCaptcha.click(function() {
  259. if($getCaptcha.hasClass('disabled')) {
  260. return ;
  261. }
  262. if(validator2.element($mobile2)) {
  263. setTimer();
  264. loginApis.getCaptcha({
  265. mobile: $mobile2.val(),
  266. type: 5,
  267. captchaToken: 5
  268. }).then(function(res) {
  269. if(res.status == 200) {
  270. toastr.success("短信发送成功!")
  271. } else {
  272. toastr.error(res.msg || "短信发送失败!")
  273. }
  274. }).catch(function(e) {
  275. console && console.error(e)
  276. })
  277. }
  278. })
  279. $submit.click(function() {
  280. var index = $('.nav-tabs>li.active').index();
  281. var mobile = '',
  282. password = '',
  283. captcha = '';
  284. if(index == 0) { // 点击手机登陆选项卡
  285. if($("#form1").valid()) {
  286. $(this).attr('disabled','disabled')
  287. mobile = $mobile1.val();
  288. password = $password.val();
  289. loginApis.publicKey().then(function(res) {
  290. if (res.status == 200) {
  291. var mod = res.data.modulus;
  292. var exp = res.data.exponent;
  293. key = RSAUtils.getKeyPair(exp, "", mod);
  294. if (key) {
  295. encryedPwd = RSAUtils.encryStr(key, password);
  296. login({
  297. mobile: mobile,
  298. password: encryedPwd,
  299. platform: 4
  300. })
  301. }else {
  302. toastr.error(res.msg || "登录失败!")
  303. $submit.removeAttr('disabled')
  304. }
  305. }
  306. })
  307. }
  308. } else { // 点击验证码登录选项卡
  309. if($("#form2").valid()) {
  310. $(this).attr('disabled','disabled')
  311. mobile = $mobile2.val();
  312. captcha = $captcha.val();
  313. login({
  314. mobile: mobile,
  315. captcha: captcha,
  316. platform: 4
  317. })
  318. }
  319. }
  320. })
  321. var validator1 = $("#form1").validate({
  322. onsubmit: false,
  323. onfocusout: function(ele) {
  324. validator1.element(ele)
  325. },
  326. rules: {
  327. mobile1: {
  328. required: true,
  329. mobile: true,
  330. },
  331.    password: "required",
  332. }
  333. });
  334. var validator2 = $("#form2").validate({
  335. onsubmit: false,
  336. onfocusout: function(ele) {
  337. validator2.element(ele)
  338. },
  339. rules: {
  340. mobile2: {
  341. required: true,
  342. mobile: true,
  343. },
  344.    captcha: "required",
  345. }
  346. });
  347. $tabs.on('click','li',function() {
  348. var idx = $(this).index(),
  349. mob = '';
  350. if(idx == 1) { // 点击验证码登录选项卡
  351. mob = $mobile1.val();
  352. if(mob) {
  353. $mobile.val(mob);
  354. validator2.element($mobile2)
  355. }
  356. } else { // 点击手机登陆选项卡
  357. mob = $mobile2.val();
  358. if(mob) {
  359. $mobile.val(mob);
  360. validator1.element($mobile1)
  361. }
  362. }
  363. })
  364. //$("#form1").valid();
  365. jQuery.validator.addMethod("mobile", function(value, element, param) {
  366. var reg=/^[1][3,4,5,7,8][0-9]{9}$/;
  367. return reg.test(value);
  368. }, "手机号码有误");
  369. })
  370. </script>
  371. </body>
  372. </html>