http.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // const base_url = 'https://api.xyyxt.net' //release
  2. // const base_url = 'http://42.192.164.187:19005' //test
  3. export const base_url = 'http://api.xyyxt.net:19009' //预发布
  4. // const base_url = 'http://192.168.1.222:5055' //dev
  5. // export const BASE_IMG_URL = 'https://file.xyyxt.net/' //release
  6. export const BASE_IMG_URL = 'https://file-dev.xyyxt.net/' //test
  7. const tenantId = '867735392558919680'
  8. export const http = (option) => {
  9. if(option.loading) {
  10. uni.showLoading({
  11. mask:true,
  12. title: '拼命加载中...'
  13. })
  14. }
  15. return new Promise((resolve,reject) => {
  16. let token = uni.getStorageSync('token')
  17. uni.request({
  18. url:base_url + option.url,
  19. data:option.data,
  20. method:option.method || 'get',
  21. header: {
  22. TenantId:tenantId,
  23. // 'Content-Type': 'application/json',
  24. AuthorizationToken: token ? 'WX '+ token : '',
  25. },
  26. success: (res) => {
  27. if (res.data.code == 401) {
  28. uni.removeStorageSync('user_account')
  29. }
  30. resolve(res)
  31. },
  32. fail: (err) => {
  33. uni.showToast({
  34. title: "请求接口失败",
  35. icon: 'none'
  36. })
  37. reject(JSON.stringify(err))
  38. },
  39. complete: () => {
  40. uni.hideLoading()
  41. }
  42. })
  43. })
  44. }