request.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. console.log('当前请求地址:', url, '当前请求返回:', response.data);
  24. if (response.statusCode !== 200) {
  25. wx.showToast({
  26. title: response.errMsg || '请求错误',
  27. icon:'none',
  28. duration: 2500,
  29. mask: true
  30. })
  31. } else {
  32. if (response.data.code !== '000') {
  33. wx.showToast({
  34. title: response.data.msg || '请求错误',
  35. icon:'none',
  36. duration: 2500,
  37. mask: true
  38. })
  39. } else {
  40. resolve(response.data)
  41. }
  42. }
  43. },
  44. fail (e) {
  45. wx.showToast({
  46. title: '网络错误',
  47. icon: 'error',
  48. duration: 2500,
  49. mask: true
  50. })
  51. reject(e)
  52. },
  53. complete () {
  54. wx.hideLoading()
  55. }
  56. })
  57. })
  58. }