api.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // let BASE_URL = 'http://114.55.0.7:8002';
  2. // const BASE_URL='http://8.136.98.49:8002'
  3. let BASE_URL = 'https://wx.hnyfwlw.com'
  4. // let BASE_URL = 'http://192.168.1.107:8000';
  5. // let BASE_URL = 'http://218.28.198.186:10508';
  6. // let BASE_URL = 'https://uat.hnyfwlw.com'
  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 (
  18. url != 'user.login.login_user' &&
  19. url != 'pest.pests.insect_discern' &&
  20. url != 'pest.pests.plant_discern' &&
  21. url != 'pest.pests.pests_contrast' &&
  22. url != 'pest.pests.pests_expert_img' &&
  23. url != 'pest.pests.pests_img' &&
  24. url != 'recognizationSys' &&
  25. url != 'base.bases.base_photo' &&
  26. url != 'pest.warning_record.rolemanage_img' &&
  27. url != 'home.homes.personal_photo' &&
  28. url != 'ascend.ascend_manage.product_info' &&
  29. url != 'ascend.ascend_manage.quality_info' &&
  30. url != 'ascend.ascend_manage.grow_info' &&
  31. url != 'ascend.ascend_manage.all_ascend' &&
  32. url != 'after_sale.after_sale_manage.device_check' &&
  33. url != 'after_sale.after_sale_manage.aftersale_apply'
  34. ) {
  35. data.token = session_key;
  36. }
  37. return new Promise((resolve, reject) => {
  38. uni.request({
  39. url: BASE_URL + options.url,
  40. method: options.method || 'POST',
  41. header: options.header || {
  42. 'Content-Type': 'application/x-www-form-urlencoded',
  43. },
  44. data: data,
  45. success: (res) => {
  46. if(res.data.code == 200){
  47. resolve(res.data.data);
  48. return
  49. }
  50. if (res.data.errorCode == 403) {
  51. uni.removeStorageSync('session_key');
  52. uni.showToast({
  53. title: '登录已过期,请重新登录!',
  54. icon: 'none',
  55. });
  56. if (uni.getStorageSync('isLink')) {
  57. return false;
  58. } else {
  59. uni.setStorageSync('isLink', true);
  60. return uni.navigateTo({
  61. url: '/pages/login/login',
  62. });
  63. }
  64. }
  65. if (res.data.message) {
  66. if (
  67. res.data.message !== '识别无结果' &&
  68. res.data.message !== '该设备未绑定SIM'
  69. ) {
  70. uni.showToast({
  71. title: res.data.message,
  72. icon: 'none',
  73. });
  74. return reject(res)
  75. } else {
  76. resolve(res.data.data);
  77. }
  78. }
  79. if (options.header) {
  80. resolve(res.data);
  81. return;
  82. }
  83. if (res.data.data) {
  84. resolve(res.data.data);
  85. } else {
  86. resolve(res.data);
  87. }
  88. },
  89. fail: (err) => {
  90. uni.showToast({
  91. title: '请求接口失败',
  92. icon: 'none',
  93. });
  94. reject(err);
  95. },
  96. });
  97. });
  98. };