request.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //测试地址
  2. /* const baseURL = 'http://api.dms.66km.com.cn/'
  3. const burl2='http://api.dms.66km.com.cn/' */
  4. /* const baseURL = 'http://192.168.1.18:20187/'
  5. const burl2='http://192.168.1.18:20187/' */
  6. //66正式
  7. /* const baseURL = 'https://apidms.66km.com/'
  8. const burl2='https://apidms.66km.com/' */
  9. //欧洲维修
  10. /* const baseURL = 'https://edms.eurorepar.cn/'
  11. const burl2='https://edms.eurorepar.cn/' */
  12. //京猫虎
  13. /* const baseURL = 'http://apidms.jcatt.cn/'
  14. const burl2='http://apidms.jcatt.cn/' */
  15. //安徒生
  16. /* const baseURL = 'http://dms-api.lhrhy.cn/'
  17. const burl2='http://dms-api.lhrhy.cn/' */
  18. /* const baseURL = 'http://store-api.qdbtl.cn/'
  19. const burl2='http://store-api.qdbtl.cn/' */
  20. /* const baseURL = 'https://store-api.qdbtl.cn/'
  21. const burl2='https://store-api.qdbtl.cn/' */
  22. /* const baseURL = '//store-api.qdbtl.cn/'
  23. const burl2='//store-api.qdbtl.cn/' */
  24. // import md5 from './MD5.js'
  25. //首配
  26. /* const baseURL = 'http://dms.shoupeiyun.com/'
  27. const burl2='http://dms.shoupeiyun.com/' */
  28. //驰湃
  29. /* const baseURL = 'http://dmsapi.chipaioil.com/'
  30. const burl2='http://dmsapi.chipaioil.com/' */
  31. //宝顺
  32. /* const baseURL = 'http://dmsapi.baoshuncar.com/'
  33. const burl2='http://dmsapi.baoshuncar.com/' */
  34. //8. 汇捷
  35. const baseURL = 'http://apidms.dqcarlink.com/'
  36. const burl2='http://apidms.dqcarlink.com/'
  37. // 欧洲维修申请
  38. const europeUrl='https://edms.eurorepar.cn/'
  39. const fetchPost = (url = '', params = {}, header = {
  40. }) => {
  41. return new Promise((resolve, reject) => {
  42. header['Content-Type']='application/x-www-form-urlencoded';
  43. header['code'] = code
  44. params = {
  45. ...params,
  46. _t: new Date().getTime()
  47. }
  48. uni.request({
  49. method: 'POST',
  50. url: baseURL + url,
  51. data: params,
  52. header: header,
  53. dataType: 'json',
  54. }).then((response) => {
  55. setTimeout(function() {
  56. uni.hideLoading();
  57. }, 200);
  58. let [error, res] = response;
  59. if(res.data.code==403){
  60. uni.showToast({
  61. title: res.data.msg,
  62. icon:'none',
  63. duration: 3000,
  64. });
  65. uni.clearStorageSync()
  66. uni.navigateTo({
  67. url:'../login/login'
  68. })
  69. }else if(res.data.code==409){
  70. // getToken(url,date,type,header)
  71. }
  72. resolve(res.data);
  73. }).catch(error => {
  74. let [err, res] = error;
  75. reject(err)
  76. })
  77. });
  78. }
  79. const fetchGet = (url = '', params = {}, header = {
  80. }) => {
  81. return new Promise((resolve, reject) => {
  82. header['Content-Type']='application/x-www-form-urlencoded';
  83. header['code'] = code
  84. params = {
  85. ...params,
  86. _t: new Date().getTime()
  87. }
  88. uni.request({
  89. method: 'GET',
  90. url: baseURL + url,
  91. data: params,
  92. header: header,
  93. dataType: 'json',
  94. }).then((response) => {
  95. setTimeout(function() {
  96. uni.hideLoading();
  97. }, 200);
  98. let [error, res] = response;
  99. resolve(res.data);
  100. }).catch(error => {
  101. let [err, res] = error;
  102. reject(err)
  103. })
  104. });
  105. }
  106. const http = (url = '', date = {}, type = 'POST', header = {
  107. }) => {
  108. return new Promise((resolve, reject) => {
  109. header={};
  110. //header['token']='98A9FED8814B457288166BDF623F33D1';
  111. //header['uid']='795957B6-8F4B-4E7F-96FE-1F26E5BA21A1';
  112. header['Content-Type']='application/x-www-form-urlencoded';
  113. console.log(baseURL + url)
  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==401||res.data.code==403){
  126. uni.showToast({
  127. title: res.data.msg,
  128. icon:'none',
  129. duration: 3000,
  130. });
  131. uni.clearStorageSync()
  132. /* uni.navigateTo({
  133. url:'../login/login'
  134. }) */
  135. }else if(res.data.code==409){
  136. // getToken(url,date,type,header)
  137. }
  138. resolve(res.data);
  139. }).catch(error => {
  140. let [err, res] = error;
  141. reject(err)
  142. })
  143. });
  144. }
  145. function getToken(url,date,type,header){
  146. var header={};
  147. //var userId=uni.getStorageSync("devData").userId;
  148. //var devData=uni.getStorageSync("devData")
  149. header['Content-Type']='application/x-www-form-urlencoded';
  150. uni.request({
  151. method: "POST",
  152. url: baseURL + '/sys/getTokenByUserID',
  153. data: {
  154. userId:userId
  155. },
  156. header: header,
  157. dataType: 'json',
  158. }).then((response) => {
  159. let [error, res] = response;
  160. var accessToken=res.data.data.accessToken.accessToken;
  161. devData.accessToken=accessToken;
  162. uni.setStorage({
  163. key: 'devData',
  164. data:devData,
  165. success: function () {
  166. refresh(url,date,type,header) //刷新接口
  167. }
  168. });
  169. // console.log(accessToken)
  170. }).catch(error => {
  171. })
  172. }
  173. function refresh(url,date,type,header){
  174. uni.request({
  175. method: type,
  176. url: baseURL + url,
  177. data: date,
  178. header: header,
  179. dataType: 'json',
  180. }).then((response) => {
  181. setTimeout(function() {
  182. uni.hideLoading();
  183. }, 200);
  184. let [error, res] = response;
  185. if(res.data.code==403){
  186. uni.showToast({
  187. title: res.data.msg,
  188. icon:'none',
  189. duration: 3000,
  190. });
  191. uni.navigateTo({
  192. url:'../login/login'
  193. })
  194. }
  195. resolve(res.data);
  196. }).catch(error => {
  197. let [err, res] = error;
  198. reject(err)
  199. })
  200. }
  201. const europehttp = (url = '', date = {}, type = 'POST', header = {
  202. }) => {
  203. return new Promise((resolve, reject) => {
  204. header={};
  205. //header['token']='98A9FED8814B457288166BDF623F33D1';
  206. //header['uid']='795957B6-8F4B-4E7F-96FE-1F26E5BA21A1';
  207. header['Content-Type']='application/x-www-form-urlencoded';
  208. console.log(europeUrl + url)
  209. uni.request({
  210. method: type,
  211. url: europeUrl + url,
  212. data: date,
  213. header: header,
  214. dataType: 'json',
  215. }).then((response) => {
  216. /* setTimeout(function() {
  217. uni.hideLoading();
  218. }, 200); */
  219. let [error, res] = response;
  220. if(res.data.code==401||res.data.code==403){
  221. uni.showToast({
  222. title: res.data.msg,
  223. icon:'none',
  224. duration: 3000,
  225. });
  226. uni.clearStorageSync()
  227. /* uni.navigateTo({
  228. url:'../login/login'
  229. }) */
  230. }else if(res.data.code==409){
  231. // getToken(url,date,type,header)
  232. }
  233. resolve(res.data);
  234. }).catch(error => {
  235. let [err, res] = error;
  236. reject(err)
  237. })
  238. });
  239. }
  240. export default {
  241. http,baseURL,fetchGet,fetchPost,europehttp
  242. }