saas.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. (function($) {
  2. if (typeof $.cookie == 'undefined') {
  3. $.cookie = {};
  4. $.cookie.set = function(c, a, d) {
  5. d = d || 30;
  6. var b = new Date();
  7. b.setTime(b.getTime() + d * 24 * 60 * 60 * 1000);
  8. document.cookie = c + "=" + escape(a) + ";expires=" + b.toGMTString()
  9. };
  10. $.cookie.get = function(b) {
  11. var a = document.cookie.match(new RegExp("(^| )" + b + "=([^;]*)(;|$)"));
  12. if (a != null) {
  13. return unescape(a[2])
  14. }
  15. return null
  16. };
  17. $.cookie.del = function(b) {
  18. $.cookie.set(b, 1, -1);
  19. };
  20. }
  21. if (typeof $.location == 'undefined') {
  22. $.location = function(name) {
  23. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  24. var r = window.location.search.substr(1).match(reg);
  25. if (r != null)
  26. return decodeURI(r[2]);
  27. return null;
  28. };
  29. }
  30. var _username = $.cookie.get('s_username'), _password = $.cookie.get('s_password'), _remember = $.cookie
  31. .get('s_remember');
  32. if (_username && _username != '')
  33. $('#s_username').val(_username);
  34. $('#s_password').val(_password);
  35. if (_remember != null && _remember == 0) {
  36. $('#remember').attr('checked', false);
  37. }
  38. window.basePath = (function() {
  39. var fullPath = window.document.location.href;
  40. var path = window.document.location.pathname;
  41. var subpos = fullPath.indexOf('//');
  42. var subpath = subpos > -1 ? fullPath.substring(0, subpos + 2) : '';
  43. if (subpos > -1)
  44. fullPath = fullPath.substring(subpos + 2);
  45. var pos = fullPath.indexOf(path);
  46. return subpath + fullPath.substring(0, pos) + path.substring(0, path.substr(1).indexOf('/') + 1) + "/";
  47. })();
  48. (function() {
  49. if(typeof basePath == 'undefined')
  50. return;
  51. $.ajax({
  52. type : "GET",
  53. contentType : "application/json",
  54. url : basePath + "/common/saas/master.action?basePath=" + basePath,
  55. success : function(c) {
  56. setLoading(false);
  57. if(c && c.ma_name) {
  58. if(!c.enable)
  59. window.location.href = basePath + "common/saas/disable.action";
  60. else {
  61. window._init = c.init;
  62. window.sob = c.ma_name;
  63. $('#en-info h1').text(c.ma_function);
  64. // 演示模式,自动登录
  65. if('guest' == c.type && c.tempName) {
  66. $.cookie.set("s_username_" + c.ma_name, c.tempName);
  67. $('#login-wrap').addClass('hide');
  68. $('#guest-wrap').addClass('slidein');
  69. var page = $.location("_page");
  70. if(!page || page != 'logout') {
  71. login(c.tempName, '111111');
  72. }
  73. }
  74. }
  75. } else
  76. window.location.href = basePath + "common/saas/error.action";
  77. }
  78. });
  79. })();
  80. })(jQuery);
  81. function login(username, password) {
  82. username = username || $("#s_username").val();
  83. password = password || $("#s_password").val();
  84. setLoading(true, '登录中...');
  85. $.ajax({
  86. type : "POST",
  87. contentType : "application/json",
  88. url : basePath + "/common/login.action?username=" + username + "&password=" + password + "&sob=" + sob,
  89. success : function(c) {
  90. setLoading(false);
  91. if (c.success) {
  92. $.cookie.set("s_username", username);
  93. if ($("#remember").attr("checked")) {
  94. $.cookie.del('s_remember');
  95. $.cookie.set("s_password", password);
  96. } else {
  97. $.cookie.set("s_remember", '0');
  98. $.cookie.del("s_password");
  99. }
  100. var path = basePath, mobile = $.location("mobile");
  101. if(!window._init) {
  102. path += 'system/init.action';
  103. }
  104. if (mobile != null) {
  105. path += "?mobile=0";
  106. }
  107. document.location.href = path;
  108. } else {
  109. if (c.reason) {
  110. $.showtip(c.reason, 6000);
  111. } else {
  112. $.showtip(c.exceptionInfo, 6000);
  113. }
  114. }
  115. }
  116. });
  117. }
  118. // loading
  119. function setLoading(isLoading, loadingText) {
  120. $('.loading-container').css('display', isLoading ? 'block' : 'none');
  121. $('.loading-back').css('display', isLoading ? 'block' : 'none');
  122. if(isLoading) {
  123. $('.loading-container').text(loadingText);
  124. }
  125. };