拓恒河湖长制全民护河平台WEB端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 line
1.5KB

  1. import baseurl from '../environment.js'
  2. export const request = function(params) {
  3. return new Promise((resolve, reject) => {
  4. if(params.showLoading) {
  5. wx.showLoading({
  6. title: '加载中',
  7. mask: true
  8. })
  9. }
  10. // 接口api拼接环境地址
  11. params.url = baseurl + params.url
  12. const {tenantId} = wx.getStorageSync('tenant')
  13. if(tenantId && !params?.data?.tenantId) {
  14. params.data = {
  15. ...params.data,
  16. tenantId
  17. }
  18. }
  19. wx.request({
  20. ...params,
  21. success: function(res) {
  22. if(params.showLoading) {
  23. wx.hideLoading()
  24. }
  25. // 处理请求
  26. if(params.url === baseurl+'/aliyunOss/getSecurityToken') {
  27. resolve(res.data)
  28. } else {
  29. if(res.data.code == 0) { // 请求成功状态码
  30. resolve(res.data)
  31. } else {
  32. reject(res.data.msg)
  33. }
  34. }
  35. },
  36. fail: function (error) {
  37. if(params.showLoading) {
  38. wx.hideLoading()
  39. }
  40. reject(error)
  41. }
  42. })
  43. }).catch(e => {
  44. wx.showToast({
  45. icon: "none",
  46. title: e || '系统错误',
  47. duration: 2000
  48. })
  49. })
  50. }