utils.js 981B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. export function isDef(value) {
  2. return value !== undefined && value !== null;
  3. }
  4. export function isObj(x) {
  5. const type = typeof x;
  6. return x !== null && (type === 'object' || type === 'function');
  7. }
  8. export function isNumber(value) {
  9. return /^\d+$/.test(value);
  10. }
  11. export function range(num, min, max) {
  12. return Math.min(Math.max(num, min), max);
  13. }
  14. export function nextTick(fn) {
  15. setTimeout(() => {
  16. fn();
  17. }, 1000 / 30);
  18. }
  19. let systemInfo = null;
  20. export function getSystemInfoSync() {
  21. if (systemInfo == null) {
  22. systemInfo = wx.getSystemInfoSync();
  23. }
  24. return systemInfo;
  25. }
  26. export function requestAnimationFrame(cb) {
  27. const systemInfo = getSystemInfoSync();
  28. if (systemInfo.platform === 'devtools') {
  29. return setTimeout(() => {
  30. cb();
  31. }, 1000 / 30);
  32. }
  33. return wx
  34. .createSelectorQuery()
  35. .selectViewport()
  36. .boundingClientRect()
  37. .exec(() => {
  38. cb();
  39. });
  40. }