api.js 2.3 KB

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