request.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* wx.request */
  2. const BASE_API = 'https://itt.chl6zk.store/api'
  3. import itt from '../utils/util'
  4. const app = getApp()
  5. export const wxRequest = (url,data) => {
  6. return new Promise((resolve, reject) => {
  7. wx.showLoading({
  8. title: '加载中...',
  9. mask: true
  10. })
  11. wx.request({
  12. url: BASE_API + url,
  13. data: data,
  14. header: {
  15. systemData:JSON.stringify({
  16. requestId: itt.getUUID(),
  17. loginToken: app.globalData.accessToken,
  18. timestamp: new Date().getTime()
  19. })
  20. },
  21. method: 'POST',
  22. success (response) {
  23. if (response.statusCode !== 200) {
  24. wx.showToast({
  25. title: response.errMsg || '请求错误',
  26. icon: 'error',
  27. duration: 2500,
  28. mask: true
  29. })
  30. } else {
  31. if (response.data.code !== '000') {
  32. wx.showToast({
  33. title: response.data.msg || '请求错误',
  34. icon: 'error',
  35. duration: 2500,
  36. mask: true
  37. })
  38. } else {
  39. resolve(response.data)
  40. }
  41. }
  42. },
  43. fail (e) {
  44. wx.showToast({
  45. title: '网络错误',
  46. icon: 'error',
  47. duration: 2500,
  48. mask: true
  49. })
  50. reject(e)
  51. },
  52. complete () {
  53. wx.hideLoading()
  54. }
  55. })
  56. })
  57. }