ec.api=function(controller){this.api_base="/"+controller+"/";this.ajax=function(_url,_type,_data,_success,_error,mask){if(L.language){_url+=(_url.indexOf("?")>-1?"&":"?")+"language="+L.language}if(mask)ke.mask();$.ajax({dataType:"json",xhrFields:{withCredentials:true},crossDomain:true,contentType:"application/json",cache:false,type:_type,url:_url,data:_data,async:true,success:_success,error:function(XMLHttpRequest,textStatus,errorThrown){if(mask)ke.unMask();ec.api.error(XMLHttpRequest,textStatus,_error)},complete:function(XMLHttpRequest,status){if(mask)ke.unMask();if(status=="timeout"){ajaxTimeoutTest.abort();$.messager.confirm(L.G("系统错误"),L.G("抱歉,操作已超时"),null,"error")}}})};this.excute=function(fun,data,_type,_callback){if(data==null)data="";var type="get";if(ke.isString(_type))type=_type;var url=this.api_base+fun;this.ajax(url,_type,data,_callback)};this.get=function(fun,callback,error,mask){this.ajax(this.api_base+fun,"get",null,callback,error,mask)};this.put=function(fun,data,callback,error,mask){if(data){if($.isFunction(data)){error=callback;callback=data;data=""}else data=JSON.stringify(data)}this.ajax(this.api_base+fun,"put",data,callback,error,mask)};this.post=function(fun,data,callback,mask){if(data){if($.isFunction(data)){error=callback;callback=data;data=""}else data=JSON.stringify(data)}this.ajax(this.api_base+fun,"post",data,callback,null,mask)}};ec.api.error=function(req,textStatus,_error){try{var r=JSON.parse(req.responseText);if(_error)_error(r);if(r.code==1e3||r.code==-1||r.code==0){window.top.ec.notifyE(r.msg);if(window._btnLoadingElement){ec.btnLoading(window._btnLoadingElement,window._btnLoadingElementText,false);window._btnLoadingElement=null}}else if(r.code=1001)window.top.location.href=(L&&L.route)+"/account/login";else alert(req.responseText)}catch(e){alert(req.responseText)}if(ec.api.errorEnd)ec.api.errorEnd()};L.push(["系统错误","System error","抱歉,操作已超时","Sorry, the operation has timed out"]);