You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

73 lines
2.1 KiB

  1. function GetPageurl()
  2. {
  3. var url=window.location.href;//获取完整URL地址
  4. var tmp= new Array();//临时变量,用于保存分割字符串
  5. tmp=url.split("/");//按照"/"分割
  6. var cc = tmp[tmp.length-1];//获取最后一部分,即文件名和参数
  7. tmp=cc.split("?");//把参数和文件名分割开
  8. return tmp[0];//返回值
  9. }
  10. function getQueryString(name) {
  11. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  12. var r = window.location.search.substr(1).match(reg);
  13. if (r != null) return unescape(r[2]); return '';
  14. }
  15. function checkLogin(){
  16. var curWwwPath=window.location.href;
  17. var pathname= window.location.pathname;
  18. var pos=curWwwPath.indexOf(pathname);
  19. var localhostPaht=curWwwPath.substring(0,pos);
  20. xm_data=$.cookie('xm_data');
  21. if(xm_data ==undefined){
  22. var refresh=encodeURI(window.location.href);
  23. ZZAlertInfo('未登录的用户请先登录!',function(){
  24. window.location.href=localhostPaht+'/login.html?refresh='+refresh;
  25. },function(){
  26. window.location.href=localhostPaht+'/login.html?refresh='+refresh;
  27. },function(){
  28. window.location.href=localhostPaht+'/login.html?refresh='+refresh;
  29. });
  30. window.location.href=localhostPaht+'/login.html?refresh='+refresh;
  31. return false;
  32. }else{
  33. return true;
  34. }
  35. }
  36. function checkAuth(){
  37. var curWwwPath=window.location.href;
  38. var pathname= window.location.pathname;
  39. var pos=curWwwPath.indexOf(pathname);
  40. var localhostPaht=curWwwPath.substring(0,pos);
  41. $.ajax({
  42. async: false,
  43. type:'post',
  44. dataType: "json",
  45. data:{method:'checkAuth',data:xm_data,pathname:pathname},
  46. url : localhostPaht+'/st-xm/Api/login.php',
  47. success : function(data) {
  48. if(data.errcode ==0){
  49. result=true;
  50. }else if(data.errcode ==1){
  51. ZZAlertInfo(data.errinfo,function(){
  52. window.location.href=localhostPaht+"/hello.html";
  53. });
  54. result=false;
  55. }else if(data.errcode==2){
  56. ZZAlertInfo(data.errinfo,function(){
  57. window.location.href=localhostPaht+"/login.html";
  58. });
  59. result=false;
  60. }
  61. },
  62. error : function() {
  63. ZZAlertInfo('fail');
  64. result=false;
  65. }
  66. });
  67. return result;
  68. }
  69. function login(){
  70. if(checkLogin()){
  71. checkAuth();
  72. }
  73. }