api.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // let BASE_URL = 'http://114.55.0.7:8002'
  2. // const BASE_URL='http://8.136.98.49:8002'
  3. // let BASE_URL = 'http://192.168.2.183:8006'
  4. // let BASE_URL = 'https://wx.hnyfwlw.com'
  5. let BASE_URL = 'https://wx.hnyfwlw.com'
  6. // let BASE_URL = 'http://192.168.2.163:8003'
  7. export const myRequest=(options)=>{
  8. // BASE_URL=uni.getStorageSync('http')
  9. // if(BASE_URL==''){
  10. // BASE_URL = 'https://wx.hnyfwlw.com/'
  11. // }
  12. // console.log(BASE_URL)
  13. var session_key="";
  14. session_key=uni.getStorageSync('session_key');
  15. let url=options.url
  16. let data=options.data||{}
  17. if (url != 'user.login.login_user' && url != 'pest.pests.insect_discern' &&
  18. url != 'pest.pests.plant_discern' &&
  19. url != 'pest.pests.pests_contrast' && url != 'pest.pests.pests_expert_img' &&
  20. url != 'pest.pests.pests_img' && url != 'recognizationSys' &&
  21. url != 'base.bases.base_photo' && url != 'pest.warning_record.rolemanage_img' &&
  22. url != 'home.homes.personal_photo' && url != 'ascend.ascend_manage.product_info' &&
  23. url != 'ascend.ascend_manage.quality_info' && url != 'ascend.ascend_manage.grow_info' &&
  24. url != 'ascend.ascend_manage.all_ascend' && url != 'after_sale.after_sale_manage.device_check' &&
  25. url != 'after_sale.after_sale_manage.aftersale_apply') {
  26. data.token=session_key
  27. }
  28. return new Promise((resolve,reject)=>{
  29. uni.request({
  30. url:BASE_URL+options.url,
  31. method:options.method||'POST',
  32. header:{
  33. "Content-Type": "application/x-www-form-urlencoded",
  34. },
  35. data:data,
  36. success:(res)=>{
  37. if(res.data.errorCode == 403) {
  38. uni.removeStorageSync('session_key');
  39. uni.showToast({
  40. title: '登录已过期,请重新登录!',
  41. icon: "none"
  42. })
  43. if(uni.getStorageSync('isLink')) {
  44. return false
  45. } else {
  46. uni.setStorageSync('isLink', true);
  47. return uni.navigateTo({
  48. url: '/pages/login/login'
  49. });
  50. }
  51. }
  52. if (res.data.message) {
  53. if(res.data.message !== "识别无结果" && res.data.message !== "该设备未绑定SIM"){
  54. return uni.showToast({
  55. title: res.data.message,
  56. icon: "none"
  57. })
  58. }else{
  59. resolve(res.data.data)
  60. }
  61. }
  62. resolve(res.data.data)
  63. },
  64. fail:(err)=>{
  65. uni.showToast({
  66. title:'请求接口失败',
  67. icon:"none"
  68. })
  69. reject(err)
  70. }
  71. })
  72. })
  73. }