loginJs.jsp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
  2. <%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>
  3. <script>
  4. var loginPage = {
  5. init:function(){
  6. var me = this;
  7. $('#txtPassword').keydown(function(event){
  8. if(event.which == "13")
  9. me.login();
  10. });
  11. $("#btnLogin").click(function(){
  12. me.login();
  13. });
  14. },
  15. login:function(){
  16. var user = $("#txtUser").val();
  17. var password = $("#txtPassword").val();
  18. if(user.length == 0 || password.length ==0)
  19. {
  20. $.ligerDialog.error("用户名或密码不能为空!");
  21. return;
  22. }
  23. $.ajax({ //获取表的字段列表
  24. type: "POST",
  25. url : "${contextRoot}/system/loginAction",
  26. dataType : "json",
  27. data:{user:user,password:password},
  28. cache:false,
  29. success :function(data){
  30. if(data.successFlg) {
  31. var tenantSession = data.data;
  32. localStorage.setItem("userRole",tenantSession.role);
  33. location.href = "${contextRoot}/indexPage";
  34. }
  35. else{
  36. $.ligerDialog.error(data.message);
  37. }
  38. },
  39. error :function(data){
  40. $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
  41. }
  42. });
  43. }
  44. };
  45. $(function(){
  46. var urlType = "${urlType}";
  47. if(urlType != ''){
  48. location.href = "${contextRoot}/"+urlType+"/loginPage";
  49. }
  50. //session过期
  51. if(location.href.indexOf('loginPage')<0)
  52. {
  53. location.href = "${contextRoot}/loginPage";
  54. }
  55. //内嵌页面
  56. if(self.location!=top.location)
  57. {
  58. <%--top.location.href = "${contextRoot}/loginPage";--%>
  59. top.location.href = window.location;
  60. }
  61. loginPage.init();
  62. });
  63. </script>