request.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* wx.request */
  2. const BASE_API = 'https://itt-worker.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.request({
  9. url: BASE_API + url + BASE_VERSION,
  10. data: data,
  11. header: {
  12. systemData:JSON.stringify({
  13. requestId: itt.getUUID(),
  14. loginToken: app.globalData.accessToken,
  15. timestamp: new Date().getTime()
  16. })
  17. },
  18. method: 'POST',
  19. success (response) {
  20. console.log('当前请求地址:', url);
  21. console.log('当前请求参数:', data);
  22. console.log('当前请求返回:', response.data);
  23. if (response.statusCode !== 200) {
  24. reject(response.data.msg || '请求错误')
  25. } else {
  26. if (response.data.code !== '000') {
  27. reject(response.data)
  28. } else {
  29. resolve(response.data)
  30. }
  31. }
  32. },
  33. fail (e) {
  34. reject('网络错误')
  35. }
  36. })
  37. })
  38. }