common.js 714 B

123456789101112131415161718192021222324252627282930
  1. export function debounce(func, wait = 3000, immediate = true) {
  2. let timeout;
  3. return function () {
  4. const context = this;
  5. const args = [...arguments];
  6. if (timeout) clearTimeout(timeout);
  7. if (immediate) {
  8. const callNow = !timeout;
  9. timeout = setTimeout(() => {
  10. timeout = null;
  11. }, wait);
  12. if (callNow) func.apply(context, args);
  13. } else {
  14. timeout = setTimeout(() => {
  15. func.apply(context, args);
  16. }, wait);
  17. }
  18. };
  19. }
  20. export function reload(option = {}) {
  21. // #ifdef H5
  22. location.reload();
  23. // #endif
  24. // #ifdef MP-WEIXIN
  25. const pages = getCurrentPages();
  26. const perpage = pages[pages.length - 1];
  27. perpage.onLoad(option);
  28. // #endif
  29. }