request.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //测试地址
  2. //const baseURL = 'http://192.168.0.122:8002/'
  3. //正式
  4. const baseURL='https://oil.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 http2 = (url = '', date = {}, type = 'POST', header = {
  76. }) => {
  77. return new Promise((resolve, reject) => {
  78. header={};
  79. if(uni.getStorageSync("wxdata")){
  80. //console.log(uni.getStorageSync("wxdata"))
  81. var openId = uni.getStorageSync("wxdata").openid;
  82. }else{
  83. var openId = '';
  84. }
  85. header['openId']=openId;
  86. header['Content-Type']='application/x-www-form-urlencoded';
  87. //console.log(baseURL + url)
  88. uni.request({
  89. method: type,
  90. url: baseURL + url,
  91. data: date,
  92. header: header,
  93. dataType: 'json',
  94. }).then((response) => {
  95. //console.log(response)
  96. //let [error, res] = response;
  97. if(response.data.code!=0){
  98. //console.log('??')
  99. uni.showToast({
  100. title: response.data.msg,
  101. icon:'none',
  102. duration: 4000,
  103. });
  104. }
  105. resolve(response.data);
  106. // resolve(res.data);
  107. }).catch(error => {
  108. let [err, res] = error;
  109. reject(err)
  110. })
  111. });
  112. }
  113. function refresh(url,date,type,header){
  114. uni.request({
  115. method: type,
  116. url: baseURL + url,
  117. data: date,
  118. header: header,
  119. dataType: 'json',
  120. }).then((response) => {
  121. setTimeout(function() {
  122. uni.hideLoading();
  123. }, 200);
  124. let [error, res] = response;
  125. if(res.data.code==403){
  126. uni.showToast({
  127. title: res.data.msg,
  128. icon:'none',
  129. duration: 3000,
  130. });
  131. }
  132. resolve(res.data);
  133. }).catch(error => {
  134. let [err, res] = error;
  135. reject(err)
  136. })
  137. }
  138. export default {
  139. http,baseURL,ajax,http2
  140. }