api.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // const BASE_URL='http://8.136.98.49:8002'
  2. // let BASE_URL = 'http://192.168.1.112:8002'
  3. export const myRequest = (options) => {
  4. let BASE_URL = uni.getStorageSync('http');
  5. if (BASE_URL == '') {
  6. // BASE_URL = 'http://8.136.98.49:8002'//线上
  7. BASE_URL =
  8. process.env.NODE_ENV === 'development'
  9. ? 'http://114.115.147.140:8002'
  10. : 'http://8.136.98.49:8002';
  11. // BASE_URL = 'http://192.168.1.77:8002'
  12. }
  13. // BASE_URL = 'http://121.41.98.97:8002'
  14. console.log(BASE_URL, 'my request', process.env.NODE_ENV);
  15. // console.log(BASE_URL)
  16. var session_key = '';
  17. session_key = uni.getStorageSync('session_key');
  18. let url = '';
  19. let data = options.data || {};
  20. if (options.url.split('=')[1]) {
  21. url = options.url.split('=')[1];
  22. } else {
  23. url = options.url.split('api/')[1];
  24. }
  25. // console.log(url)
  26. if (
  27. url != 'user.login.login_user' &&
  28. url != 'pest.pests.insect_discern' &&
  29. url != 'pest.pests.plant_discern' &&
  30. url != 'pest.pests.pests_contrast' &&
  31. url != 'pest.pests.pests_expert_img' &&
  32. url != 'pest.pests.pests_img' &&
  33. url != 'recognizationSys' &&
  34. url != 'base.bases.base_photo' &&
  35. url != 'pest.warning_record.rolemanage_img' &&
  36. url != 'home.homes.personal_photo' &&
  37. url != 'ascend.ascend_manage.product_info' &&
  38. url != 'ascend.ascend_manage.quality_info' &&
  39. url != 'ascend.ascend_manage.grow_info' &&
  40. url != 'ascend.ascend_manage.all_ascend' &&
  41. url != 'after_sale.after_sale_manage.device_check' &&
  42. url != 'after_sale.after_sale_manage.aftersale_apply'
  43. ) {
  44. data.token = session_key;
  45. }
  46. console.log(data, 'request data');
  47. return new Promise((resolve, reject) => {
  48. uni.request({
  49. url: BASE_URL + options.url,
  50. method: options.method || 'POST',
  51. header: {
  52. 'Content-Type': 'application/x-www-form-urlencoded',
  53. },
  54. data: data,
  55. success: (res) => {
  56. console.log(res.data, 'http response');
  57. if (res.data.message != '') {
  58. if (
  59. res.data.message == '识别无结果' ||
  60. res.data.message == '该设备未绑定SIM'
  61. ) {
  62. resolve(res.data.data);
  63. } else {
  64. return uni.showToast({
  65. title: res.data.message,
  66. icon: 'none',
  67. });
  68. }
  69. }
  70. resolve(res.data.data);
  71. },
  72. fail: (err) => {
  73. uni.showToast({
  74. title: '请求接口失败',
  75. });
  76. reject(err);
  77. },
  78. });
  79. });
  80. };