function.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. var apiUrl = "http://hzadmin.huojutech.com/admin/";
  2. function isLogion(){
  3. return $.cookie.get("token");
  4. }
  5. function checkLogin(){
  6. var data = $("#loginForm").serializeJSON();
  7. if(data.name.isEmpty()){
  8. alert("请输入登录用户名。", 0, function(){
  9. $("input[name='name']").focus();
  10. });
  11. return false;
  12. }
  13. if(data.password.isEmpty() || !/^[\w-_.]{5,16}$/i.test(data.password)){
  14. alert("请输入由5-20位的字母、数字和下划线组成的密码。", 0, function(){
  15. $("input[name='password']").focus();
  16. });
  17. return false;
  18. }
  19. data.password = $.md5(data.password);
  20. ajax(apiUrl+"login",data,function(res){
  21. alert({title:"登录提示",nav:res.msg,flag:res.code,next:function(){
  22. if(res.code == 1){
  23. $.cookie.set("token",res.data.token);
  24. window.location.href = "/";
  25. }
  26. }});
  27. });
  28. return false;
  29. }
  30. function loginout(){
  31. ajax(apiUrl+"/loginOut",{},function(res){
  32. alert(res.code.toString().decode(1, "登出成功。", "登出失败"), res.code, function(){
  33. if(res.code == 1){
  34. $.cookie.remove("token");
  35. window.location.href = "/";
  36. }
  37. });
  38. });
  39. }
  40. function getMenu(){
  41. var openIndex = 0, res = {data:[{"name":"预测管理","parent_id":"0","url":"prediction.html","list":[]},{"name":"用户管理","parent_id":"0","url":"management.html","list":[]},{"name":"火钻管理","parent_id":"0","url":"pierer.html","list":[]}]};
  42. /*ajax({url:"api/?a=public&act=menu",data:{},callBack:function(res){
  43. if(res.code == 1){*/
  44. $.each(res.data,function(index, items){
  45. if(getPageName(items.url)){
  46. openIndex = index;
  47. res.data[index]['parentIndex'] = true;
  48. }
  49. if(items.list.length > 0){
  50. $.each(items.list,function(i, item){
  51. if(getPageName(item.url)){
  52. openIndex = index;
  53. res.data[index]['parentIndex'] = true;
  54. res.data[index]['list'][i]['subIndex'] = true;
  55. }
  56. });
  57. }else
  58. delete res.data[index]['list'];
  59. });
  60. $("#menu").html($.Template7.renderTpl("menu_template",res));
  61. $("#menu>li:eq("+openIndex+")>ul.contentTxt").removeClass("contentTxt");
  62. /*}
  63. },load:false});*/
  64. }
  65. function getPageName(url){
  66. url = url.replace(".html","");
  67. var paramData = {
  68. pathname : window.location.pathname.replace("/","").replace("blm/","").replace(".html",""),
  69. url : url
  70. };
  71. paramData.pageName = paramData.pathname.split("_");
  72. if(paramData.pageName.length <= 0)
  73. paramData.pageName.push(paramData.pathname);
  74. if(paramData.url.indexOf("?") >= 1){
  75. paramData.url = paramData.url.split("?")[0];
  76. }
  77. paramData.url = paramData.url.split("/");
  78. if(paramData.url.length > 1)
  79. paramData.url = paramData.url[paramData.url.length - 1];
  80. else
  81. paramData.url = paramData.url[0];
  82. return paramData.pageName.length <= 0 && paramData.url.isEmpty() ? false : !$.inArray(paramData.url, paramData.pageName);
  83. }
  84. function modfiyPass(){
  85. var data = $("#passwordFrm").serializeJSON();
  86. if(data['old_password'].isEmpty()){
  87. alert("请输入旧密码。", 0, function(){
  88. $("input[name='old_password']").focus();
  89. });
  90. return false;
  91. }
  92. if(data['password'].isEmpty()){
  93. alert("请输入新密码。", 0, function(){
  94. $("input[name='password']").focus();
  95. });
  96. return false;
  97. }
  98. if(data['new_password'].isEmpty()){
  99. alert("请输入确认密码。", 0, function(){
  100. $("input[name='new_password']").focus();
  101. });
  102. return false;
  103. }
  104. if(data['password'] != data['new_password']){
  105. alert("两次密码不一致", 0, function(){
  106. $("input[name='new_password']").focus();
  107. });
  108. return false;
  109. }
  110. data['old_password'] = $.md5(data['old_password']);
  111. data['password'] = $.md5(data['password']);
  112. data['new_password'] = "";
  113. ajax("api/?a=public&act=password",data,function(res){
  114. alert(res.msg, res.code, function(){
  115. if(res.code == 1) window.location.href = document.URL;
  116. });
  117. });
  118. return false;
  119. }
  120. function closeImg(o){
  121. $(o).parent().hide().empty();
  122. $("#pathImg").val("");
  123. }
  124. function checkAll(obj){
  125. $("input[type='checkbox']").prop("checked", obj.checked);
  126. $.checkbox();
  127. }
  128. function itemCheck(){
  129. $("input[name='all']").prop("checked", $("input[type='checkbox']").length == $("input[type='checkbox']:not('input[name='all']'):checked").length ? true : false);
  130. $.checkbox();
  131. }
  132. function resetCheckAll(){
  133. $("input[name='all']").prop("checked",false);
  134. $.checkbox();
  135. }