api.js 2.9 KB

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