loading.ts 789 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. interface ShowLoadingOptions {
  2. /**
  3. * 提示的内容
  4. */
  5. title?: string;
  6. /**
  7. * 是否显示透明蒙层,防止触摸穿透,默认:false
  8. */
  9. mask?: boolean;
  10. /**
  11. * 接口调用成功的回调函数
  12. */
  13. success?: (result: any) => void;
  14. /**
  15. * 接口调用失败的回调函数
  16. */
  17. fail?: (result: any) => void;
  18. /**
  19. * 接口调用结束的回调函数(调用成功、失败都会执行)
  20. */
  21. complete?: (result: any) => void;
  22. }
  23. let loadingCount = 0;
  24. export function showLoading(option: ShowLoadingOptions = {}) {
  25. loadingCount++;
  26. uni.showLoading({
  27. title: option.title || '加载中',
  28. ...option
  29. });
  30. }
  31. export function hideLoading() {
  32. loadingCount = loadingCount - 1;
  33. if (loadingCount === 0) {
  34. uni.hideLoading();
  35. }
  36. }