throttle.js 676 B

1234567891011121314151617181920212223242526
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. const throttle = function(func, duration, show = true) {
  4. let start = 0;
  5. return function() {
  6. let that = this;
  7. let now = Date.now();
  8. if (now - start > duration) {
  9. func.apply(that, arguments);
  10. start = now;
  11. } else {
  12. if(!show) {
  13. return
  14. }
  15. wx.showToast({
  16. title: `您的操作太频繁啦,请在${Math.ceil(
  17. duration / 1000
  18. )}秒后再试哦~`,
  19. icon: "none"
  20. });
  21. }
  22. };
  23. };
  24. module.exports = {
  25. throttle
  26. };