commom.js 944 B

1234567891011121314151617181920212223242526272829303132333435
  1. // 节流函数
  2. export const throttle = function (func, wait) {
  3. let previousTime = 0;
  4. return function () {
  5. const now = Date.now();
  6. const context = this;
  7. const args = [...arguments];
  8. if (now - previousTime > wait) {
  9. func.apply(context, args);
  10. previousTime = now;
  11. }
  12. };
  13. };
  14. // 获取小程序配置
  15. export const tabBarConfig = function () {
  16. // eslint-disable-next-line no-undef
  17. return __wxConfig;
  18. };
  19. // 当前是否是 tabBar 页面
  20. export const isTabBarPage = function () {
  21. if (!tabBarConfig().tabBar) return false;
  22. const tabBar = tabBarConfig().tabBar.list || [];
  23. const tabBarList = tabBar.map(obj => obj.pagePath);
  24. const currentPage = `${getRoute()}.html`;
  25. return tabBarList.indexOf(currentPage) !== -1;
  26. };
  27. // 获取当前的页面地址
  28. export const getRoute = function () {
  29. const pages = getCurrentPages();
  30. const currentPage = pages[pages.length - 1];
  31. return currentPage.route;
  32. };