api.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if (BASE_URL == '') {
  6. // BASE_URL = 'http://8.136.98.49:8002'//线上
  7. BASE_URL = process.env.NODE_ENV === 'development' ? "http://114.115.147.140:8002" : "http://8.136.98.49:8002"
  8. // BASE_URL = 'http://192.168.1.77:8002'
  9. }
  10. // BASE_URL = 'http://192.168.1.52:8002'
  11. console.log(BASE_URL,'my request',process.env.NODE_ENV)
  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. console.log(data,'request data')
  42. return new Promise((resolve, reject) => {
  43. uni.request({
  44. url: BASE_URL + options.url,
  45. method: options.method || 'POST',
  46. header: {
  47. "Content-Type": "application/x-www-form-urlencoded",
  48. },
  49. data: data,
  50. success: (res) => {
  51. console.log(res.data,'http response')
  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. }