mp.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. export default {
  2. data() {
  3. return {
  4. windowInfo: getWindowInfo(),
  5. }
  6. },
  7. computed: {
  8. /**
  9. * 小程序和H5的标题
  10. */
  11. navbarStyle() {
  12. let windowInfo = getWindowInfo();
  13. return {
  14. statusBarHeightPx: windowInfo.system.statusBarHeight + 'px',
  15. navbarHeightPx: windowInfo.navbar.bodyHeightPx + 'px',
  16. }
  17. },
  18. },
  19. methods: {
  20. back() {
  21. uni.navigateBack()
  22. }
  23. }
  24. }
  25. /**
  26. * 获取当前窗口数据
  27. *
  28. */
  29. function getWindowInfo() {
  30. let systemInfo = uni.getSystemInfoSync();
  31. systemInfo.pixelRatio = Math.round(systemInfo.pixelRatio * 100) / 100;
  32. let windowInfo = {
  33. system: systemInfo,
  34. capsule: {
  35. bottom: 78,
  36. height: 30,
  37. left: 283,
  38. right: 363,
  39. top: 48,
  40. width: 0,
  41. },
  42. navbar: {
  43. heightPx: uni.upx2px(100) + systemInfo.statusBarHeight,
  44. bodyHeightPx: uni.upx2px(100),
  45. bodyWidthPx: systemInfo.windowWidth,
  46. capsuleWidthPx: 0,
  47. capsuleRightPx: 0,
  48. },
  49. height: systemInfo.windowHeight * (750 / systemInfo.windowWidth),
  50. width: 750,
  51. statusBarHeight: systemInfo.statusBarHeight * (750 / systemInfo.windowWidth),
  52. safeBottom: systemInfo.windowHeight - systemInfo.safeArea.bottom,
  53. safeBottomRpx: (systemInfo.windowHeight - systemInfo.safeArea.bottom) * (750 / systemInfo.windowWidth),
  54. /**
  55. * 原生端 底部导航栏高度
  56. */
  57. footNavbarHeight: uni.upx2px(100) + (systemInfo.windowHeight - systemInfo.safeArea.bottom),
  58. }
  59. // #ifdef MP-QQ || MP-WEIXIN
  60. let capsuleInfo = uni.getMenuButtonBoundingClientRect();
  61. windowInfo.capsule = capsuleInfo;
  62. let capsuleToStatusBarPx = capsuleInfo.top - systemInfo.statusBarHeight; //胶囊和状态栏之间的高度
  63. windowInfo.navbar.bodyHeightPx = capsuleInfo.height + (capsuleToStatusBarPx * 2);
  64. windowInfo.navbar.heightPx = windowInfo.navbar.bodyHeightPx + systemInfo.statusBarHeight;
  65. let capsuleWidthPx = (systemInfo.windowWidth - capsuleInfo.right) * 2 + capsuleInfo.width;
  66. windowInfo.navbar.bodyWidthPx = systemInfo.windowWidth - capsuleWidthPx;
  67. windowInfo.navbar.capsuleWidthPx = capsuleWidthPx;
  68. windowInfo.navbar.capsuleRightPx = capsuleWidthPx - (systemInfo.windowWidth - capsuleInfo.right);
  69. // #endif
  70. return windowInfo;
  71. }