api.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // const BASE_URL = 'https://chtech.ncjti.edu.cn/carstop/carBuy'
  2. const BASE_URL = 'https://car.meiyishuoo.com/ride-sharing/carBuy'
  3. export function myRequest(options : any) {
  4. uni.showLoading({
  5. title: '加载中',
  6. mask: true,
  7. })
  8. // 当前时间
  9. const timestamp = new Date().getTime()
  10. // 将时间戳添加到URL中
  11. options.url += `${options.url.includes('?') ? '&' : '?'}timestamp=${timestamp}`
  12. return new Promise((resolve, reject) => {
  13. uni.request({
  14. url: BASE_URL + options.url,
  15. method: options.method || 'GET',
  16. data: options.data || {},
  17. header: options.header || {
  18. // token: uni.getStorageSync('auth').token || '',
  19. },
  20. success: (res : any) => {
  21. // console.log(res);
  22. uni.hideLoading()
  23. if (res.data.code === 200) {
  24. resolve(res.data)
  25. }
  26. else {
  27. uni.showToast({
  28. title: res.data.message || "接口报错",
  29. icon: 'none',
  30. })
  31. }
  32. },
  33. fail: (err) => {
  34. uni.hideLoading()
  35. uni.showToast({
  36. title: '请求数据失败',
  37. icon: 'none',
  38. })
  39. reject(err)
  40. },
  41. })
  42. })
  43. }