request.js 604 B

1234567891011121314151617181920212223242526272829303132
  1. const BASE_URL = 'http://192.168.3.152:8088/glwork'
  2. export function ApiRequest(config = {}){
  3. let {
  4. url,
  5. data,
  6. method="GET",
  7. header={}
  8. } = config
  9. url = BASE_URL + url
  10. if(uni.getStorageSync('GlWorkPlatform-AccessToken')){
  11. header['Authorization'] = 'Bearer ' + uni.getStorageSync('GlWorkPlatform-AccessToken')
  12. }
  13. return new Promise((resolve, reject)=>{
  14. uni.request({
  15. url: url,
  16. data: data,
  17. method: method,
  18. header: header,
  19. timeout: 60000,
  20. success: (res)=>{
  21. resolve(res.data)
  22. },
  23. fail: (err) => {
  24. reject(err)
  25. },
  26. complete: (event)=>{
  27. }
  28. })
  29. })
  30. }