api.js 1.8 KB

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