httpFunc.js 687 B

123456789101112131415161718192021222324252627282930
  1. function httpError(err) {
  2. console.error(err);
  3. wx.hideLoading();
  4. wx.showToast({
  5. title: '请稍后再试!',
  6. })
  7. }
  8. export function httpCloud(params) {
  9. !params.noLoading && wx.showLoading();
  10. const par = params || {};
  11. wx.cloud.callFunction({
  12. // 云函数名称
  13. name: par.name,
  14. // 传给云函数的参数
  15. data: {
  16. ...(par.data || {}),
  17. type: par.type
  18. },
  19. success: function (res) {
  20. wx.hideLoading();
  21. if(!/ok/g.test(res.errMsg)) return httpError(res);
  22. if(res.result.code != 0) return wx.showToast({
  23. title: '请稍后再试!',
  24. })
  25. par.call && par.call(res.result.data);
  26. },
  27. fail: httpError
  28. })
  29. }