utils.js 684 B

123456789101112131415161718192021222324252627282930313233343536
  1. export function getSystemInfoSync() {
  2. let systemInfo = null
  3. if (systemInfo == null) {
  4. systemInfo = wx.getSystemInfoSync();
  5. }
  6. return systemInfo;
  7. }
  8. // 模拟 浏览器 requestAnimationFrame
  9. export function requestAnimationFrame(cb) {
  10. const systemInfo = getSystemInfoSync();
  11. if (systemInfo.platform === 'devtools') {
  12. return setTimeout(() => {
  13. cb();
  14. }, 1000 / 30);
  15. }
  16. return wx
  17. .createSelectorQuery()
  18. .selectViewport()
  19. .boundingClientRect()
  20. .exec(() => {
  21. cb();
  22. });
  23. }
  24. export function isObj(x) {
  25. const type = typeof x;
  26. return x !== null && (type === 'object' || type === 'function');
  27. }