request.js 1011 B

1234567891011121314151617181920212223242526272829303132333435
  1. const baseUrl = "https://pdjh.shizhi.tv/prod-api"
  2. // const baseUrl = "http://192.168.1.24:8080"
  3. const request = function (datas) {
  4. let url = datas.url.indexOf('http') != -1 ? datas.url : baseUrl + datas.url
  5. let method = datas.method || "GET"
  6. let header = datas.header || {}
  7. let data = datas.data || ""
  8. return new Promise((resolve, rejects) => {
  9. wx.request({
  10. url: url,
  11. method: method,
  12. data: data,
  13. header: header,
  14. success: (res) => {
  15. if (res.statusCode === 200) {
  16. resolve(res.data)
  17. } else {
  18. resolve({
  19. code: res.statusCode,
  20. msg: res.errMsg
  21. })
  22. }
  23. },
  24. fail: (err) => {
  25. resolve({
  26. code: 1000,
  27. msg: "服务器未响应"
  28. })
  29. }
  30. })
  31. })
  32. }
  33. export default request