api.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 = 'https://wx.hnyfwlw.com';
  6. // let BASE_URL = 'http://218.28.198.186:10508';
  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.errorCode == 403) {
  47. uni.removeStorageSync('session_key');
  48. uni.showToast({
  49. title: '登录已过期,请重新登录!',
  50. icon: 'none',
  51. });
  52. if (uni.getStorageSync('isLink')) {
  53. return false;
  54. } else {
  55. uni.setStorageSync('isLink', true);
  56. return uni.navigateTo({
  57. url: '/pages/login/login',
  58. });
  59. }
  60. }
  61. if (res.data.message) {
  62. if (
  63. res.data.message !== '识别无结果' &&
  64. res.data.message !== '该设备未绑定SIM'
  65. ) {
  66. return uni.showToast({
  67. title: res.data.message,
  68. icon: 'none',
  69. });
  70. } else {
  71. resolve(res.data.data);
  72. }
  73. }
  74. if (options.header) {
  75. resolve(res.data);
  76. return;
  77. }
  78. if (res.data.data) {
  79. resolve(res.data.data);
  80. } else {
  81. resolve(res.data);
  82. }
  83. },
  84. fail: (err) => {
  85. uni.showToast({
  86. title: '请求接口失败',
  87. icon: 'none',
  88. });
  89. reject(err);
  90. },
  91. });
  92. });
  93. };