apilogin.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>接口服务登录</title>
  6. <link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  7. <script src="//cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  8. <script src="//cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  9. <style type="text/css">
  10. .login-box {
  11. width: 360px;
  12. padding: 30px 20px;
  13. background: #fff;
  14. margin: auto;
  15. margin-top: 170px;
  16. }
  17. .login-box-body h3 {
  18. display: block;
  19. font-weight: 500;
  20. line-height: 1.1;
  21. color: inherit;
  22. font-size: 24px;
  23. text-align: center;
  24. padding-top: 20px;
  25. padding-bottom: 20px;
  26. }
  27. </style>
  28. </head>
  29. <body style="background: #d2d6de;">
  30. <div class="login-box">
  31. <!-- /.login-logo -->
  32. <div class="login-box-body">
  33. <!--<div class="logo"><img src="images/logo.png"></div>-->
  34. <h3>接口服务登录</h3>
  35. <div>
  36. <div class="form-group has-feedback">
  37. <input id="userName" type="text" class="form-control" name="account" placeholder="用户名">
  38. <span class="glyphicon glyphicon-user form-control-feedback"></span>
  39. </div>
  40. <div class="form-group has-feedback">
  41. <input id="password" type="password" class="form-control" name="pwd" placeholder="密码">
  42. <span class="glyphicon glyphicon-lock form-control-feedback"></span>
  43. </div>
  44. <div style="margin-left: -18px;text-align: center">
  45. <button id="loginBtn" type="submit" class="btn btn-primary" style="width: 310px;">登录</button>
  46. </div>
  47. </div>
  48. <!-- /.login-box-body -->
  49. </div>
  50. </div>
  51. <script type="text/javascript">
  52. $(function () {
  53. $("#loginBtn").click(function () {
  54. login();
  55. });
  56. $(document).keydown(function (event) {
  57. if (event.keyCode == 13) {
  58. $("#loginBtn").click();
  59. }
  60. });
  61. });
  62. //登录方法
  63. function login() {
  64. $("#loginBtn").html("登陆中...");
  65. var srcurl = window.location.href;
  66. var url="/user/login";
  67. if (srcurl.indexOf("apis") != -1) {
  68. url="/apis/user/login";
  69. }
  70. var account=$("#userName").val();
  71. var password=$("#password").val();
  72. if(account ==""){
  73. alert("用户名不能为空");
  74. return;
  75. }
  76. if(password==""){
  77. alert("请输入密码");
  78. return;
  79. }
  80. var data={
  81. "account":account,
  82. "password":password
  83. };
  84. $.ajax({
  85. url:url,
  86. type:'post',
  87. data: {
  88. "user": JSON.stringify(data)
  89. },
  90. dataType:'json',
  91. contentType : 'application/json',
  92. success:function (res) {
  93. if(res.httpCode == 200){
  94. $("#loginBtn").html("登陆成功");
  95. var destUrl="/xdoc/index";
  96. if (srcurl.indexOf("apis") != -1) {
  97. destUrl="/apis/xdoc/index";
  98. }
  99. window.location.href=destUrl;
  100. }
  101. else{
  102. $("#loginBtn").html("登陆");
  103. alert(res.msg);
  104. }
  105. },
  106. error:function (res) {
  107. alert(res.msg);
  108. }
  109. })
  110. }
  111. </script>
  112. </body>
  113. </html>