api.js 2.8 KB

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