app.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // 获取Url参数
  2. function getUrlParam(name){
  3. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  4. var r = window.location.search.substr(1).match(reg);
  5. if (r != null)
  6. return decodeURI(r[2]);
  7. return null;
  8. }
  9. // 获取跟路径
  10. function getRootPath() {
  11. var pathName = window.location.pathname.substring(1);
  12. var webName = pathName == '' ? '' : pathName.substring(0, pathName
  13. .indexOf('/'));
  14. if (webName == "") {
  15. return window.location.protocol + '//' + window.location.host;
  16. } else {
  17. return window.location.protocol + '//' + window.location.host + '/'
  18. + webName;
  19. }
  20. }
  21. var rootPath = getRootPath();
  22. $(function() {
  23. 'use strict';
  24. var b_username = getUrlParam('b_username');
  25. var b_password = getUrlParam('b_password');
  26. var b_enuu = getUrlParam('b_enuu');
  27. var page = getUrlParam('page');
  28. function checkError(reason) {
  29. $('#loading').hide();
  30. $('#chech-error .weui_msg_desc').text(reason);
  31. $('#chech-error').show();
  32. };
  33. function login() {
  34. $.ajax({
  35. type: 'POST',
  36. url: rootPath + '/j_spring_security_check',
  37. data: {
  38. j_username: b_username,
  39. j_password: b_password,
  40. t_enuu: b_enuu
  41. }, headers : {
  42. 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
  43. },
  44. success: function(data, status, res) {
  45. if(res.status === 200) {
  46. $('#loading .weui_toast_content').text('正在跳转...')
  47. window.location.href = rootPath + (page || '/');
  48. } else if(res.status === 207 && data instanceof Array) {
  49. var t;
  50. if(b_enuu) {
  51. t = '您的UAS商务平台账号并未绑定当前企业';
  52. } else {
  53. t = '您的UAS商务平台账号绑定了多个企业';
  54. }
  55. $('#loading').hide();
  56. $('#redirect-error .weui_msg_desc').text(t).show();
  57. $.each(data, function(k, v) {
  58. var html = '<a class="weui_cell">' +
  59. '<div class="weui_cell_bd weui_cell_primary">' +
  60. '<p>' + v.enName + '</p>' +
  61. '</div>' +
  62. '<div class="weui_cell_ft"></div>' +
  63. '</a>';
  64. var element = $(html);
  65. element.on('click', function(e) {
  66. b_enuu = v.uu;
  67. login();
  68. });
  69. $('#redirect-error .enterprises').append(element);
  70. });
  71. $('#redirect-error').show();
  72. }
  73. },
  74. error: function(res) {
  75. checkError(res.responseText);
  76. }
  77. });
  78. };
  79. if(b_username) {
  80. login();
  81. } else {
  82. checkError('用户名无效或不存在');
  83. };
  84. });