/** * 有关 访问服务器的uri */ var $http = function() { // this.ip = "http://192.168.242.26:9002"; this.ip = "https://b2bcnapi.sailuntire.com/api/test/b2bapi/action/api/tms"; //this.ip = "http://b2bcnapi.sailuntire.com/api/web"; // this.ip = "http://192.168.237.6/api/web"; // 获取签收单据的主表信息 this.signOrderOfHead = "/signOrderOfHead.xhtml"; /****** 获取签收单据的明细信息 ******/ this.signOrderOfItem = "/signOrderOfItem.xhtml"; } // api的ajax $http.prototype.$post = function(url, data, callback, other) { var content = "", urlT = ""; if (data.url == "json") { delete data.url; // 确认contenttype选项 content = "application/json;charset=UTF-8"; } else { content = "application/x-www-form-urlencoded" } var datas = this.serize(data); if ( typeof other != 'undefined' && other != "" && other != 'undefined') { urlT = this.ip + eval('this.' + url) + '/' + other; } else { urlT = this.ip + eval('this.' + url); } api.showProgress({ }); console.log(urlT) console.log(JSON.stringify(datas)) api.ajax({ url : urlT, method : 'post', data : datas, headers : { "Content-type" : content }, }, function(ret, err) { api.hideProgress(); api.refreshHeaderLoadDone(); if (ret) { // console.log(JSON.stringify(ret)); callback(ret); } else { api.toast({ msg: '当前网络不稳定,请稍后再试' }); } }); } // get方法 $http.prototype.$get = function(url, data, callback, other) { var urlT = other == 'formdata' ? (this.ip + eval('this.' + url)) : (this.ip + eval('this.' + url) + '?' + data); api.showProgress({ }); api.ajax({ url : urlT, method : 'get', data : {}, headers : { "Content-type" : "application/json;charset=UTF-8" }, }, function(ret, err) { api.hideProgress(); api.refreshHeaderLoadDone(); if (ret) { callback(ret); } else { api.toast({ msg: '当前网络不稳定,请稍后再试' }); } }); } // 对数据进行处理,第一个为values,第二个为file body $http.prototype.serize = function(data) { var serizeData; if ( data instanceof Array) { if (data.length > 1) { serizeData = { values : data[0] } } else { serizeData = { values : data[0], files : data[1] } } } else { if (data.type == 'body') { delete data.type; if (data.yy == 'keng') { delete data.yy serizeData = { body : data.id } } else { serizeData = { body : data } } } else { serizeData = { values : data } } } return serizeData; } function alertJson(str) { alert(JSON.stringify(str)); }