api.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // const BASE_URL='http://8.136.98.49:8002'
  2. // let BASE_URL = 'http://192.168.1.112:8002'
  3. export const myRequest = (options) => {
  4. let BASE_URL = uni.getStorageSync('http')
  5. console.log(BASE_URL,'my request',process.env.NODE_ENV)
  6. if (BASE_URL == '') {
  7. // BASE_URL = 'http://8.136.98.49:8002'//线上
  8. BASE_URL = process.env.NODE_ENV === 'development' ? "http://192.168.0.36:8003" : "http://8.136.98.49:8002"
  9. // BASE_URL = 'http://192.168.1.77:8002'
  10. }
  11. // BASE_URL = 'http://192.168.1.52:8003'
  12. // console.log(BASE_URL)
  13. var session_key = ""
  14. session_key = uni.getStorageSync('session_key')
  15. let url = ""
  16. let data = options.data || {}
  17. if (options.url.split('=')[1]) {
  18. url = options.url.split('=')[1]
  19. } else {
  20. url = options.url.split('api/')[1]
  21. }
  22. // console.log(url)
  23. if (url != 'user.login.login_user' &&
  24. url != 'pest.pests.insect_discern' &&
  25. url != 'pest.pests.plant_discern' &&
  26. url != 'pest.pests.pests_contrast' &&
  27. url != 'pest.pests.pests_expert_img' &&
  28. url != 'pest.pests.pests_img' &&
  29. url != 'recognizationSys' &&
  30. url != 'base.bases.base_photo' &&
  31. url != 'pest.warning_record.rolemanage_img' &&
  32. url != 'home.homes.personal_photo' &&
  33. url != 'ascend.ascend_manage.product_info' &&
  34. url != 'ascend.ascend_manage.quality_info' &&
  35. url != 'ascend.ascend_manage.grow_info' &&
  36. url != 'ascend.ascend_manage.all_ascend' &&
  37. url != 'after_sale.after_sale_manage.device_check' &&
  38. url != 'after_sale.after_sale_manage.aftersale_apply') {
  39. data.token = session_key
  40. }
  41. return new Promise((resolve, reject) => {
  42. uni.request({
  43. url: BASE_URL + options.url,
  44. method: options.method || 'POST',
  45. header: {
  46. "Content-Type": "application/x-www-form-urlencoded",
  47. },
  48. data: data,
  49. success: (res) => {
  50. if (res.data.message) {
  51. if (res.data.message == "识别无结果" ||res.data.message == "该设备未绑定SIM") {
  52. resolve(res.data.data)
  53. } else {
  54. return uni.showToast({
  55. title: res.data.message,
  56. icon: "none"
  57. })
  58. }
  59. }
  60. resolve(res.data.data)
  61. },
  62. fail: (err) => {
  63. uni.showToast({
  64. title: '请求接口失败'
  65. })
  66. reject(err)
  67. }
  68. })
  69. })
  70. }