request.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //测试地址
  2. //const baseURL2 = 'http://192.168.0.125:20134/'
  3. //const baseURL='http://wiper.66km.com.cn/'
  4. const baseURL='https://wiper.66km.com.cn/'
  5. //66正式
  6. /* const baseURL = 'https://apidms.66km.com/'
  7. const burl2='https://apidms.66km.com/' */
  8. //欧洲维修
  9. //const baseURL = 'http://oil.66km.com.cn/'
  10. // const burl2='http://edms.eurorepar.cn/ '
  11. // import md5 from './MD5.js'
  12. const ajax = (url = '', date = {}, type = 'POST', header = {
  13. }) => {
  14. return new Promise((resolve, reject) => {
  15. header={};
  16. header['Content-Type']='application/x-www-form-urlencoded';
  17. //console.log(header)
  18. uni.request({
  19. method: type,
  20. url: 'http://api.dms.66km.com.cn/' + url,
  21. data: date,
  22. header: header,
  23. dataType: 'json',
  24. }).then((response) => {
  25. console.log(response)
  26. //let [error, res] = response;
  27. resolve(response.data);
  28. }).catch(error => {
  29. let [err, res] = error;
  30. reject(err)
  31. })
  32. });
  33. }
  34. var that=this;
  35. const http = (url = '', date = {}, type = 'POST', header = {
  36. }) => {
  37. return new Promise((resolve, reject) => {
  38. header={};
  39. if(uni.getStorageSync("wxdata")){
  40. //console.log(uni.getStorageSync("wxdata"))
  41. var openId = uni.getStorageSync("wxdata").openid;
  42. }else{
  43. var openId = '';
  44. }
  45. //console.log(that.$store)
  46. //header['token']='98A9FED8814B457288166BDF623F33D1';
  47. header['openId']=openId;
  48. header['Content-Type']='application/x-www-form-urlencoded';
  49. console.log(baseURL + url)
  50. uni.request({
  51. method: type,
  52. url: baseURL+'search?action=' + url,
  53. data: date,
  54. header: header,
  55. dataType: 'json',
  56. }).then((response) => {
  57. //console.log(response)
  58. //let [error, res] = response;
  59. if(response.data.code!=0){
  60. //console.log('??')
  61. uni.showToast({
  62. title: response.data.msg,
  63. icon:'none',
  64. duration: 4000,
  65. });
  66. }
  67. resolve(response.data);
  68. // resolve(res.data);
  69. }).catch(error => {
  70. let [err, res] = error;
  71. reject(err)
  72. })
  73. });
  74. }
  75. const http3 = (url = '', date = {}, type = 'POST', header = {
  76. }) => {
  77. return new Promise((resolve, reject) => {
  78. header={};
  79. if(uni.getStorageSync("wxdata")){
  80. var openId = uni.getStorageSync("wxdata").openid;
  81. }else{
  82. var openId = '';
  83. }
  84. header['openId']=openId;
  85. header['Content-Type']='application/x-www-form-urlencoded';
  86. console.log(baseURL + url)
  87. uni.request({
  88. method: type,
  89. //url: baseURL2+'search?action=' + url,
  90. url: baseURL + url,
  91. data: date,
  92. header: header,
  93. dataType: 'json',
  94. }).then((response) => {
  95. if(response.data.code!=0){
  96. uni.showToast({
  97. title: response.data.msg,
  98. icon:'none',
  99. duration: 4000,
  100. });
  101. }
  102. resolve(response.data);
  103. }).catch(error => {
  104. let [err, res] = error;
  105. reject(err)
  106. })
  107. });
  108. }
  109. const http2 = (url = '', date = {}, type = 'POST', header = {
  110. }) => {
  111. return new Promise((resolve, reject) => {
  112. header={};
  113. if(uni.getStorageSync("wxdata")){
  114. //console.log(uni.getStorageSync("wxdata"))
  115. var openId = uni.getStorageSync("wxdata").openid;
  116. }else{
  117. var openId = '';
  118. }
  119. header['openId']=openId;
  120. header['Content-Type']='application/x-www-form-urlencoded';
  121. //console.log(baseURL + url)
  122. uni.request({
  123. method: type,
  124. url: baseURL + url,
  125. data: date,
  126. header: header,
  127. dataType: 'json',
  128. }).then((response) => {
  129. //console.log(response)
  130. //let [error, res] = response;
  131. if(response.data.code!=0){
  132. //console.log('??')
  133. uni.showToast({
  134. title: response.data.msg,
  135. icon:'none',
  136. duration: 4000,
  137. });
  138. }
  139. resolve(response.data);
  140. // resolve(res.data);
  141. }).catch(error => {
  142. let [err, res] = error;
  143. reject(err)
  144. })
  145. });
  146. }
  147. function refresh(url,date,type,header){
  148. uni.request({
  149. method: type,
  150. url: baseURL + url,
  151. data: date,
  152. header: header,
  153. dataType: 'json',
  154. }).then((response) => {
  155. setTimeout(function() {
  156. uni.hideLoading();
  157. }, 200);
  158. let [error, res] = response;
  159. if(res.data.code==403){
  160. uni.showToast({
  161. title: res.data.msg,
  162. icon:'none',
  163. duration: 3000,
  164. });
  165. }
  166. resolve(res.data);
  167. }).catch(error => {
  168. let [err, res] = error;
  169. reject(err)
  170. })
  171. }
  172. export default {
  173. http,baseURL,ajax,http2,http3
  174. }