request.js 1.5 KB

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