function.js 4.3 KB

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