request.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 baseURL = 'http://dmsapi.cnjla.com/'
  39. const burl2='http://dmsapi.cnjla.com/' */
  40. // 欧洲维修申请
  41. const europeUrl='https://edms.eurorepar.cn/'
  42. const fetchPost = (url = '', params = {}, header = {
  43. }) => {
  44. return new Promise((resolve, reject) => {
  45. header['Content-Type']='application/x-www-form-urlencoded';
  46. header['code'] = code
  47. params = {
  48. ...params,
  49. _t: new Date().getTime()
  50. }
  51. uni.request({
  52. method: 'POST',
  53. url: baseURL + url,
  54. data: params,
  55. header: header,
  56. dataType: 'json',
  57. }).then((response) => {
  58. setTimeout(function() {
  59. uni.hideLoading();
  60. }, 200);
  61. let [error, res] = response;
  62. if(res.data.code==403){
  63. uni.showToast({
  64. title: res.data.msg,
  65. icon:'none',
  66. duration: 3000,
  67. });
  68. uni.clearStorageSync()
  69. uni.navigateTo({
  70. url:'../login/login'
  71. })
  72. }else if(res.data.code==409){
  73. // getToken(url,date,type,header)
  74. }
  75. resolve(res.data);
  76. }).catch(error => {
  77. let [err, res] = error;
  78. reject(err)
  79. })
  80. });
  81. }
  82. const fetchGet = (url = '', params = {}, header = {
  83. }) => {
  84. return new Promise((resolve, reject) => {
  85. header['Content-Type']='application/x-www-form-urlencoded';
  86. header['code'] = code
  87. params = {
  88. ...params,
  89. _t: new Date().getTime()
  90. }
  91. uni.request({
  92. method: 'GET',
  93. url: baseURL + url,
  94. data: params,
  95. header: header,
  96. dataType: 'json',
  97. }).then((response) => {
  98. setTimeout(function() {
  99. uni.hideLoading();
  100. }, 200);
  101. let [error, res] = response;
  102. resolve(res.data);
  103. }).catch(error => {
  104. let [err, res] = error;
  105. reject(err)
  106. })
  107. });
  108. }
  109. const http = (url = '', date = {}, type = 'POST', header = {
  110. }) => {
  111. return new Promise((resolve, reject) => {
  112. header={};
  113. //header['token']='98A9FED8814B457288166BDF623F33D1';
  114. //header['uid']='795957B6-8F4B-4E7F-96FE-1F26E5BA21A1';
  115. header['Content-Type']='application/x-www-form-urlencoded';
  116. console.log(baseURL + url)
  117. uni.request({
  118. method: type,
  119. url: baseURL + url,
  120. data: date,
  121. header: header,
  122. dataType: 'json',
  123. }).then((response) => {
  124. /* setTimeout(function() {
  125. uni.hideLoading();
  126. }, 200); */
  127. let [error, res] = response;
  128. if(res.data.code==401||res.data.code==403){
  129. uni.showToast({
  130. title: res.data.msg,
  131. icon:'none',
  132. duration: 3000,
  133. });
  134. uni.clearStorageSync()
  135. /* uni.navigateTo({
  136. url:'../login/login'
  137. }) */
  138. }else if(res.data.code==409){
  139. // getToken(url,date,type,header)
  140. }
  141. resolve(res.data);
  142. }).catch(error => {
  143. let [err, res] = error;
  144. reject(err)
  145. })
  146. });
  147. }
  148. function getToken(url,date,type,header){
  149. var header={};
  150. //var userId=uni.getStorageSync("devData").userId;
  151. //var devData=uni.getStorageSync("devData")
  152. header['Content-Type']='application/x-www-form-urlencoded';
  153. uni.request({
  154. method: "POST",
  155. url: baseURL + '/sys/getTokenByUserID',
  156. data: {
  157. userId:userId
  158. },
  159. header: header,
  160. dataType: 'json',
  161. }).then((response) => {
  162. let [error, res] = response;
  163. var accessToken=res.data.data.accessToken.accessToken;
  164. devData.accessToken=accessToken;
  165. uni.setStorage({
  166. key: 'devData',
  167. data:devData,
  168. success: function () {
  169. refresh(url,date,type,header) //刷新接口
  170. }
  171. });
  172. // console.log(accessToken)
  173. }).catch(error => {
  174. })
  175. }
  176. function refresh(url,date,type,header){
  177. uni.request({
  178. method: type,
  179. url: baseURL + url,
  180. data: date,
  181. header: header,
  182. dataType: 'json',
  183. }).then((response) => {
  184. setTimeout(function() {
  185. uni.hideLoading();
  186. }, 200);
  187. let [error, res] = response;
  188. if(res.data.code==403){
  189. uni.showToast({
  190. title: res.data.msg,
  191. icon:'none',
  192. duration: 3000,
  193. });
  194. uni.navigateTo({
  195. url:'../login/login'
  196. })
  197. }
  198. resolve(res.data);
  199. }).catch(error => {
  200. let [err, res] = error;
  201. reject(err)
  202. })
  203. }
  204. const europehttp = (url = '', date = {}, type = 'POST', header = {
  205. }) => {
  206. return new Promise((resolve, reject) => {
  207. header={};
  208. //header['token']='98A9FED8814B457288166BDF623F33D1';
  209. //header['uid']='795957B6-8F4B-4E7F-96FE-1F26E5BA21A1';
  210. header['Content-Type']='application/x-www-form-urlencoded';
  211. console.log(europeUrl + url)
  212. uni.request({
  213. method: type,
  214. url: europeUrl + url,
  215. data: date,
  216. header: header,
  217. dataType: 'json',
  218. }).then((response) => {
  219. /* setTimeout(function() {
  220. uni.hideLoading();
  221. }, 200); */
  222. let [error, res] = response;
  223. if(res.data.code==401||res.data.code==403){
  224. uni.showToast({
  225. title: res.data.msg,
  226. icon:'none',
  227. duration: 3000,
  228. });
  229. uni.clearStorageSync()
  230. /* uni.navigateTo({
  231. url:'../login/login'
  232. }) */
  233. }else if(res.data.code==409){
  234. // getToken(url,date,type,header)
  235. }
  236. resolve(res.data);
  237. }).catch(error => {
  238. let [err, res] = error;
  239. reject(err)
  240. })
  241. });
  242. }
  243. export default {
  244. http,baseURL,fetchGet,fetchPost,europehttp
  245. }