httpRequest_sub.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * 有关 访问服务器的uri
  3. */
  4. var $http = function() {
  5. //this.ip = "https://b2bcnapi.sailuntire.com/api/test/b2bapi/action/api/tms";//测试
  6. this.ip = "https://b2bcnapi.sailuntire.com/api/b2bapi/action/api/tms";//正式
  7. // 获取签收单据的主表信息
  8. this.signOrderOfHead = "/signOrderOfHead.xhtml";
  9. /****** 获取签收单据的明细信息 ******/
  10. this.signOrderOfItem = "/signOrderOfItem.xhtml";
  11. //获取签收信息
  12. this.getSignMsg = "/getSignMsg.xhtml";
  13. // 签收实际操作
  14. this.signOperate = "/signOperate.xhtml";
  15. }
  16. // api的ajax
  17. $http.prototype.$post = function(url, data, callback, other) {
  18. var content = "", urlT = "";
  19. if (data.url == "json") {
  20. delete data.url;
  21. // 确认contenttype选项
  22. content = "application/json;charset=UTF-8";
  23. } else if(data.url="formdata"){
  24. content = "Content-type:multipart/form-data"
  25. } else{
  26. content = "application/x-www-form-urlencoded"
  27. }
  28. var datas = this.serize(data);
  29. if ( typeof other != 'undefined' && other != "" && other != 'undefined') {
  30. urlT = this.ip + eval('this.' + url) + '/' + other;
  31. } else {
  32. urlT = this.ip + eval('this.' + url);
  33. }
  34. api.showProgress({
  35. });
  36. // console.log(urlT)
  37. // console.log(JSON.stringify(datas))
  38. api.ajax({
  39. url : urlT,
  40. method : 'post',
  41. data : datas,
  42. headers : {
  43. "Content-type" : content
  44. },
  45. }, function(ret, err) {
  46. // console.log(JSON.stringify(ret));
  47. api.hideProgress();
  48. api.refreshHeaderLoadDone();
  49. if (ret) {
  50. callback(ret);
  51. } else {
  52. api.toast({
  53. msg: '当前网络不稳定,请稍后再试'
  54. });
  55. }
  56. });
  57. }
  58. // get方法
  59. $http.prototype.$get = function(url, data, callback, other) {
  60. var urlT = other == 'formdata' ? (this.ip + eval('this.' + url)) : (this.ip + eval('this.' + url) + '?' + data);
  61. api.showProgress({
  62. });
  63. api.ajax({
  64. url : urlT,
  65. method : 'get',
  66. data : {},
  67. headers : {
  68. "Content-type" : "application/json;charset=UTF-8"
  69. },
  70. }, function(ret, err) {
  71. api.hideProgress();
  72. api.refreshHeaderLoadDone();
  73. if (ret) {
  74. callback(ret);
  75. } else {
  76. api.toast({
  77. msg: '当前网络不稳定,请稍后再试'
  78. });
  79. }
  80. });
  81. }
  82. // 对数据进行处理,第一个为values,第二个为file body
  83. $http.prototype.serize = function(data) {
  84. var serizeData;
  85. if ( data instanceof Array) {
  86. if (data.length > 1) {
  87. serizeData = {
  88. values : data[0]
  89. }
  90. } else {
  91. serizeData = {
  92. values : data[0],
  93. files : data[1]
  94. }
  95. }
  96. } else {
  97. if (data.type == 'body') {
  98. delete data.type;
  99. if (data.yy == 'keng') {
  100. delete data.yy
  101. serizeData = {
  102. body : data.id
  103. }
  104. } else {
  105. serizeData = {
  106. body : data
  107. }
  108. }
  109. } else {
  110. serizeData = {
  111. values : data
  112. }
  113. }
  114. }
  115. return serizeData;
  116. }
  117. function alertJson(str) {
  118. alert(JSON.stringify(str));
  119. }