function.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. window.location.href = "/";
  24. }
  25. }});
  26. });
  27. return false;
  28. }
  29. function loginout(){
  30. ajax(apiUrl+"/loginOut",{},function(res){
  31. alert(res.code.toString().decode(1, "登出成功。", "登出失败"), res.code, function(){
  32. if(res.code == 1){
  33. window.location.href = "/";
  34. }
  35. });
  36. });
  37. }
  38. function getMenu(){
  39. 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":[]}]};
  40. /*ajax({url:"api/?a=public&act=menu",data:{},callBack:function(res){
  41. if(res.code == 1){*/
  42. $.each(res.data,function(index, items){
  43. if(getPageName(items.url)){
  44. openIndex = index;
  45. res.data[index]['parentIndex'] = true;
  46. }
  47. if(items.list.length > 0){
  48. $.each(items.list,function(i, item){
  49. if(getPageName(item.url)){
  50. openIndex = index;
  51. res.data[index]['parentIndex'] = true;
  52. res.data[index]['list'][i]['subIndex'] = true;
  53. }
  54. });
  55. }else
  56. delete res.data[index]['list'];
  57. });
  58. $("#menu").html($.Template7.renderTpl("menu_template",res));
  59. $("#menu>li:eq("+openIndex+")>ul.contentTxt").removeClass("contentTxt");
  60. /*}
  61. },load:false});*/
  62. }
  63. function getPageName(url){
  64. url = url.replace(".html","");
  65. var paramData = {
  66. pathname : window.location.pathname.replace("/","").replace("blm/","").replace(".html",""),
  67. url : url
  68. };
  69. paramData.pageName = paramData.pathname.split("_");
  70. if(paramData.pageName.length <= 0)
  71. paramData.pageName.push(paramData.pathname);
  72. if(paramData.url.indexOf("?") >= 1){
  73. paramData.url = paramData.url.split("?")[0];
  74. }
  75. paramData.url = paramData.url.split("/");
  76. if(paramData.url.length > 1)
  77. paramData.url = paramData.url[paramData.url.length - 1];
  78. else
  79. paramData.url = paramData.url[0];
  80. return paramData.pageName.length <= 0 && paramData.url.isEmpty() ? false : !$.inArray(paramData.url, paramData.pageName);
  81. }
  82. function modfiyPass(){
  83. var data = $("#passwordFrm").serializeJSON();
  84. if(data['old_password'].isEmpty()){
  85. alert("请输入旧密码。", 0, function(){
  86. $("input[name='old_password']").focus();
  87. });
  88. return false;
  89. }
  90. if(data['password'].isEmpty()){
  91. alert("请输入新密码。", 0, function(){
  92. $("input[name='password']").focus();
  93. });
  94. return false;
  95. }
  96. if(data['new_password'].isEmpty()){
  97. alert("请输入确认密码。", 0, function(){
  98. $("input[name='new_password']").focus();
  99. });
  100. return false;
  101. }
  102. if(data['password'] != data['new_password']){
  103. alert("两次密码不一致", 0, function(){
  104. $("input[name='new_password']").focus();
  105. });
  106. return false;
  107. }
  108. data['old_password'] = $.md5(data['old_password']);
  109. data['password'] = $.md5(data['password']);
  110. data['new_password'] = "";
  111. ajax("api/?a=public&act=password",data,function(res){
  112. alert(res.msg, res.code, function(){
  113. if(res.code == 1) window.location.href = document.URL;
  114. });
  115. });
  116. return false;
  117. }
  118. function closeImg(o){
  119. $(o).parent().hide().empty();
  120. $("#pathImg").val("");
  121. }
  122. function checkAll(obj){
  123. $("input[type='checkbox']").prop("checked", obj.checked);
  124. $.checkbox();
  125. }
  126. function itemCheck(){
  127. $("input[name='all']").prop("checked", $("input[type='checkbox']").length == $("input[type='checkbox']:not('input[name='all']'):checked").length ? true : false);
  128. $.checkbox();
  129. }
  130. function resetCheckAll(){
  131. $("input[name='all']").prop("checked",false);
  132. $.checkbox();
  133. }