http.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // export const base_url = 'https://test.xyyxt.net' //预发布
  5. // const base_url = 'http://192.168.1.24:5055' //dev
  6. // export const base_url = 'http://120.79.166.78:19012' // 测试环境
  7. export const BASE_IMG_URL = 'https://file.xyyxt.net/' //release
  8. // export const BASE_IMG_URL = 'https://file-dev.xyyxt.net/' //test
  9. const tenantId = uni.getStorageSync('tid') // 祥粤云学堂:867735392558919680,祥粤学堂:667735392758919630,中建云学堂-567735392758918520,中正-141250585240548145,山西-471722209971055962
  10. export const http = (option) => {
  11. if (option.loading) {
  12. uni.showLoading({
  13. mask: true,
  14. title: '拼命加载中...'
  15. })
  16. }
  17. return new Promise((resolve, reject) => {
  18. let token = uni.getStorageSync('token')
  19. uni.request({
  20. url: base_url + option.url,
  21. data: option.data,
  22. method: option.method || 'get',
  23. header: {
  24. TenantId: option.tenantIdHide ? '' : uni.getStorageSync('tid'),
  25. // 'Content-Type': 'application/json',
  26. AuthorizationToken: token ? 'WX ' + token : '',
  27. },
  28. success: (res) => {
  29. if (res.data.code == 401) {
  30. uni.removeStorageSync('user_account')
  31. }
  32. resolve(res)
  33. },
  34. fail: (err) => {
  35. uni.showToast({
  36. title: "请求接口失败",
  37. icon: 'none'
  38. })
  39. reject(JSON.stringify(err))
  40. },
  41. complete: () => {
  42. uni.hideLoading()
  43. }
  44. })
  45. })
  46. }