systemInfo.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* eslint-disable import/no-mutable-exports */
  2. // 获取屏幕边界到安全区域距离
  3. let systemInfo
  4. let safeAreaInsets
  5. // #ifdef MP-WEIXIN
  6. // 微信小程序使用新的API
  7. systemInfo = uni.getWindowInfo()
  8. safeAreaInsets = systemInfo.safeArea
  9. ? {
  10. top: systemInfo.safeArea.top,
  11. right: systemInfo.windowWidth - systemInfo.safeArea.right,
  12. bottom: systemInfo.windowHeight - systemInfo.safeArea.bottom,
  13. left: systemInfo.safeArea.left,
  14. }
  15. : null
  16. // #endif
  17. // #ifndef MP-WEIXIN
  18. // 其他平台继续使用uni API
  19. systemInfo = uni.getSystemInfoSync()
  20. safeAreaInsets = systemInfo.safeAreaInsets
  21. // #endif
  22. console.log('systemInfo', systemInfo)
  23. // 微信里面打印
  24. // pixelRatio: 3
  25. // safeArea: {top: 47, left: 0, right: 390, bottom: 810, width: 390, …}
  26. // safeAreaInsets: {top: 47, left: 0, right: 0, bottom: 34}
  27. // screenHeight: 844
  28. // screenTop: 91
  29. // screenWidth: 390
  30. // statusBarHeight: 47
  31. // windowBottom: 0
  32. // windowHeight: 753
  33. // windowTop: 0
  34. // windowWidth: 390
  35. export { safeAreaInsets, systemInfo }