api.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // const BASE_URL='http://8.136.98.49:8002'
  2. let BASE_URL = ''
  3. export const myRequest = (options) => {
  4. // BASE_URL = uni.getStorageSync('http')
  5. BASE_URL = 'http://182.92.193.64:8002'
  6. // BASE_URL = 'http://192.168.1.17:8000'
  7. if (BASE_URL == '') {
  8. BASE_URL = 'http://8.136.98.49:8002'
  9. }
  10. console.log(BASE_URL)
  11. var session_key = ""
  12. session_key = uni.getStorageSync('session_key')
  13. let url = options.url
  14. let data = options.data || {}
  15. if (url != 'back_source.production.operator_login') {
  16. data.token = session_key
  17. }
  18. return new Promise((resolve, reject) => {
  19. uni.request({
  20. url: BASE_URL + options.url,
  21. method: options.method || 'POST',
  22. timeout:30000,
  23. header: {
  24. "Content-Type": "application/x-www-form-urlencoded",
  25. },
  26. data: data,
  27. success: (res) => {
  28. if (res.data.message != "") {
  29. return uni.showToast({
  30. title: res.data.message,
  31. icon: "none",
  32. })
  33. }
  34. resolve(res.data.data)
  35. },
  36. fail: (err) => {
  37. uni.showToast({
  38. title: '请求接口失败',
  39. icon:'none',
  40. })
  41. reject(err)
  42. }
  43. })
  44. })
  45. }