request.js 7.1 KB

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