login.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 autocomplete="off" id="mobile1" mobile type="text" name="mobile1" class="form-control" placeholder="请输入手机号码" required="">
  119. </div>
  120. <div class="form-group">
  121. <input autocomplete="off" 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. </form>
  126. </div>
  127. </div>
  128. <div id="tab-2" class="tab-pane">
  129. <div class="panel-body">
  130. <form id="form2" class="m-t" role="form" onsubmit="return false;">
  131. <div class="form-group">
  132. <input autocomplete="off" id="mobile2" name="mobile2" mobile type="text" class="form-control" placeholder="请输入手机号码" required="">
  133. </div>
  134. <div class="form-group">
  135. <input autocomplete="off" id="captcha" name="captcha" type="text" class="form-control" placeholder="请输入短信验证码" required="">
  136. <a id="getCaptcha" href="javascript:void(0);">获取验证码</a>
  137. </div>
  138. <button type="submit" class="btn btn-success block full-width m-b">登 录</button>
  139. </form>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. </head>
  148. <body >
  149. <script src="js/jquery.min.js?v=2.1.4"></script>
  150. <script src="js/es6-promise.js" type="text/javascript" charset="utf-8"></script>
  151. <script src="js/bootstrap.min.js?v=3.3.6"></script>
  152. <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
  153. <script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
  154. <script src="js/plugins/layer/layer.min.js"></script>
  155. <script src="js/hplus.min.js?v=4.1.0"></script>
  156. <script type="text/javascript" src="js/contabs.min.js"></script>
  157. <script src="js/plugins/pace/pace.min.js"></script>
  158. <script src="js/plugins/validate/jquery.validate.min.js"></script>
  159. <script src="js/plugins/validate/messages_zh.min.js"></script>
  160. <script src="js/plugins/toastr/toastr.min.js"></script>
  161. <script src="js/security.js"></script>
  162. <script src="js/api-service.js"></script>
  163. <script src="js/login-api.js"></script>
  164. <script>
  165. //获取链接上的参数
  166. function GetRequest() {
  167. var url = location.search; //获取url中"?"符后的字串
  168. var theRequest = new Object();
  169. if (url.indexOf("?") != -1) {
  170. var str = url.substr(1);
  171. strs = str.split("&");
  172. for (var i = 0; i < strs.length; i++) {
  173. theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  174. }
  175. }
  176. return theRequest;
  177. }
  178. </script>
  179. <script>
  180. $(function() {
  181. var Requests = GetRequest();
  182. var redirect_url = Requests.redirect_url;
  183. var userAgent = Requests.userAgent;
  184. var agentName = APIService.agentName;
  185. toastr.options = {
  186. "closeButton": true,
  187. "positionClass": "toast-top-center"
  188. }
  189. var $eyeIcon = $('.psw-eye'),
  190. $mobile1 = $('#mobile1'),
  191. $password = $('#password'),
  192. $mobile2 = $('#mobile2'),
  193. $captcha = $('#captcha'),
  194. $mobile = $('input[mobile]'),
  195. $tabs = $('.nav-tabs'),
  196. $getCaptcha = $('#getCaptcha'),
  197. $submit = $('button[type="submit"]');
  198. var timer = null;
  199. if(userAgent) {
  200. userAgent = decodeURIComponent(userAgent)
  201. var userAgentStr = userAgent
  202. window.localStorage.setItem(agentName, userAgent)
  203. if(userAgent){
  204. userAgent = JSON.parse(userAgent);
  205. }
  206. if(userAgent.imei) {
  207. localStorage.setItem('WLYY_IMEI',userAgent.imei)
  208. }
  209. $.ajax(APIService.server +'doctor/doctorRole',{
  210. data:{},
  211. dataType: 'json',
  212. type:'get',
  213. beforeSend: function(request) {
  214. request.setRequestHeader("userAgent", userAgentStr);
  215. },
  216. timeout: 30000,
  217. success: function(res) {
  218. if(res.status == 200){
  219. var data = res.data;
  220. //添加医生到userRole
  221. var addData = {
  222. areas:data.hospital,
  223. authOperate:data.doctorAuthOperate,
  224. code:data.hospital,
  225. isManage:0,
  226. level:4,
  227. name:data.name
  228. }
  229. data.token = userAgent.token
  230. data.userRole.push(addData)
  231. localStorage.setItem('wlyyAgent',JSON.stringify(data))
  232. }
  233. }
  234. })
  235. return ;
  236. }
  237. function login(data) {
  238. loginApis.login(data)
  239. .then(function(res) {
  240. $submit.removeAttr('disabled')
  241. if(res.status == 200) {
  242. var data = res.data;
  243. localStorage.setItem(agentName,JSON.stringify({
  244. id: data.id,
  245. uid: data.uid,
  246. token: data.token,
  247. imei: localStorage.getItem('WLYY_IMEI'),
  248. platform: 4
  249. }))
  250. localStorage.setItem("app_storage", JSON.stringify({
  251. 'api_login_doctor': data,
  252. 'IMEI': localStorage.getItem('WLYY_IMEI')
  253. }))
  254. if(redirect_url) {
  255. window.location.href = decodeURIComponent(redirect_url)
  256. }else{
  257. window.location.href = "index.html"
  258. }
  259. } else {
  260. toastr.error(res.msg || "登录失败!")
  261. }
  262. })
  263. .catch(function(e) {
  264. $submit.removeAttr('disabled')
  265. console && console.error(e)
  266. })
  267. }
  268. function setTimer() {
  269. $getCaptcha.addClass('disabled');
  270. var seconds = 59;
  271. timer = setInterval(function() {
  272. if(seconds == 0) {
  273. clearInterval(timer);
  274. timer = null;
  275. seconds = 59;
  276. $getCaptcha.text("获取验证码");
  277. $getCaptcha.removeClass('disabled');
  278. return ;
  279. }
  280. $getCaptcha.text((seconds--)+"s后重新获取");
  281. }, 1000)
  282. }
  283. $eyeIcon.click(function() {
  284. $el = $(this);
  285. if($el.hasClass('fa-eye')) {
  286. $el.removeClass('fa-eye').addClass('fa-eye-slash');
  287. $password.attr('type','password')
  288. } else {
  289. $el.removeClass('fa-eye-slash').addClass('fa-eye');
  290. $password.attr('type','text')
  291. }
  292. })
  293. $getCaptcha.click(function() {
  294. if($getCaptcha.hasClass('disabled')) {
  295. return ;
  296. }
  297. if(validator2.element($mobile2)) {
  298. setTimer();
  299. loginApis.getCaptcha({
  300. mobile: $mobile2.val(),
  301. type: 5,
  302. captchaToken: 5
  303. }).then(function(res) {
  304. if(res.status == 200) {
  305. toastr.success("短信发送成功!")
  306. } else {
  307. toastr.error(res.msg || "短信发送失败!")
  308. }
  309. }).catch(function(e) {
  310. console && console.error(e)
  311. })
  312. }
  313. })
  314. $submit.click(function() {
  315. var index = $('.nav-tabs>li.active').index();
  316. var mobile = '',
  317. password = '',
  318. captcha = '';
  319. if(index == 0) { // 点击手机登陆选项卡
  320. if($("#form1").valid()) {
  321. $(this).attr('disabled','disabled')
  322. mobile = $mobile1.val();
  323. password = $password.val();
  324. loginApis.publicKey().then(function(res) {
  325. if (res.status == 200) {
  326. var mod = res.data.modulus;
  327. var exp = res.data.exponent;
  328. key = RSAUtils.getKeyPair(exp, "", mod);
  329. if (key) {
  330. encryedPwd = RSAUtils.encryStr(key, password);
  331. login({
  332. mobile: mobile,
  333. password: encryedPwd,
  334. platform: 4
  335. })
  336. }else {
  337. toastr.error(res.msg || "登录失败!")
  338. $submit.removeAttr('disabled')
  339. }
  340. }
  341. })
  342. }
  343. } else { // 点击验证码登录选项卡
  344. if($("#form2").valid()) {
  345. $(this).attr('disabled','disabled')
  346. mobile = $mobile2.val();
  347. captcha = $captcha.val();
  348. login({
  349. mobile: mobile,
  350. captcha: captcha,
  351. platform: 4
  352. })
  353. }
  354. }
  355. })
  356. var validator1 = $("#form1").validate({
  357. onsubmit: false,
  358. onfocusout: function(ele) {
  359. validator1.element(ele)
  360. },
  361. rules: {
  362. mobile1: {
  363. required: true,
  364. mobile: true,
  365. },
  366.    password: "required",
  367. }
  368. });
  369. var validator2 = $("#form2").validate({
  370. onsubmit: false,
  371. onfocusout: function(ele) {
  372. validator2.element(ele)
  373. },
  374. rules: {
  375. mobile2: {
  376. required: true,
  377. mobile: true,
  378. },
  379.    captcha: "required",
  380. }
  381. });
  382. $tabs.on('click','li',function() {
  383. var idx = $(this).index(),
  384. mob = '';
  385. if(idx == 1) { // 点击验证码登录选项卡
  386. mob = $mobile1.val();
  387. if(mob) {
  388. $mobile.val(mob);
  389. validator2.element($mobile2)
  390. }
  391. } else { // 点击手机登陆选项卡
  392. mob = $mobile2.val();
  393. if(mob) {
  394. $mobile.val(mob);
  395. validator1.element($mobile1)
  396. }
  397. }
  398. })
  399. //$("#form1").valid();
  400. jQuery.validator.addMethod("mobile", function(value, element, param) {
  401. var reg=/^[1][3,4,5,7,8][0-9]{9}$/;
  402. return reg.test(value);
  403. }, "手机号码有误");
  404. })
  405. </script>
  406. </body>
  407. </html>