var apiUrl = "http://hzadmin.huojutech.com/admin/"; function isLogion(){ return $.cookie.get("token"); } function checkLogin(){ var data = $("#loginForm").serializeJSON(); if(data.name.isEmpty()){ alert("请输入登录用户名。", 0, function(){ $("input[name='name']").focus(); }); return false; } if(data.password.isEmpty() || !/^[\w-_.]{5,16}$/i.test(data.password)){ alert("请输入由5-20位的字母、数字和下划线组成的密码。", 0, function(){ $("input[name='password']").focus(); }); return false; } data.password = $.md5(data.password); ajax(apiUrl+"login",data,function(res){ alert({title:"登录提示",nav:res.msg,flag:res.code,next:function(){ if(res.code == 1){ $.cookie.set("token",res.data.token); window.location.href = "/"; } }}); }); return false; } function loginout(){ ajax(apiUrl+"/loginOut",{},function(res){ alert(res.code.toString().decode(1, "登出成功。", "登出失败"), res.code, function(){ if(res.code == 1){ $.cookie.remove("token"); window.location.href = "/"; } }); }); } function getMenu(){ 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":[]}]}; /*ajax({url:"api/?a=public&act=menu",data:{},callBack:function(res){ if(res.code == 1){*/ $.each(res.data,function(index, items){ if(getPageName(items.url)){ openIndex = index; res.data[index]['parentIndex'] = true; } if(items.list.length > 0){ $.each(items.list,function(i, item){ if(getPageName(item.url)){ openIndex = index; res.data[index]['parentIndex'] = true; res.data[index]['list'][i]['subIndex'] = true; } }); }else delete res.data[index]['list']; }); $("#menu").html($.Template7.renderTpl("menu_template",res)); $("#menu>li:eq("+openIndex+")>ul.contentTxt").removeClass("contentTxt"); /*} },load:false});*/ } function getPageName(url){ url = url.replace(".html",""); var paramData = { pathname : window.location.pathname.replace("/","").replace("blm/","").replace(".html",""), url : url }; paramData.pageName = paramData.pathname.split("_"); if(paramData.pageName.length <= 0) paramData.pageName.push(paramData.pathname); if(paramData.url.indexOf("?") >= 1){ paramData.url = paramData.url.split("?")[0]; } paramData.url = paramData.url.split("/"); if(paramData.url.length > 1) paramData.url = paramData.url[paramData.url.length - 1]; else paramData.url = paramData.url[0]; return paramData.pageName.length <= 0 && paramData.url.isEmpty() ? false : !$.inArray(paramData.url, paramData.pageName); } function modfiyPass(){ var data = $("#passwordFrm").serializeJSON(); if(data['old_password'].isEmpty()){ alert("请输入旧密码。", 0, function(){ $("input[name='old_password']").focus(); }); return false; } if(data['password'].isEmpty()){ alert("请输入新密码。", 0, function(){ $("input[name='password']").focus(); }); return false; } if(data['new_password'].isEmpty()){ alert("请输入确认密码。", 0, function(){ $("input[name='new_password']").focus(); }); return false; } if(data['password'] != data['new_password']){ alert("两次密码不一致", 0, function(){ $("input[name='new_password']").focus(); }); return false; } data['old_password'] = $.md5(data['old_password']); data['password'] = $.md5(data['password']); data['new_password'] = ""; ajax("api/?a=public&act=password",data,function(res){ alert(res.msg, res.code, function(){ if(res.code == 1) window.location.href = document.URL; }); }); return false; } function closeImg(o){ $(o).parent().hide().empty(); $("#pathImg").val(""); } function checkAll(obj){ $("input[type='checkbox']").prop("checked", obj.checked); $.checkbox(); } function itemCheck(){ $("input[name='all']").prop("checked", $("input[type='checkbox']").length == $("input[type='checkbox']:not('input[name='all']'):checked").length ? true : false); $.checkbox(); } function resetCheckAll(){ $("input[name='all']").prop("checked",false); $.checkbox(); }