page-container.behavior.ts 841 B

123456789101112131415161718192021222324
  1. export default Behavior({
  2. data: {},
  3. lifetimes: {
  4. attached() {
  5. const { windowWidth, windowHeight, safeArea } = wx.getWindowInfo();
  6. const { top, bottom, right } = wx.getMenuButtonBoundingClientRect();
  7. const offsetTop = Math.max(0, top - safeArea.top);
  8. const bleeding = windowWidth - right;
  9. const container = {
  10. width: windowWidth,
  11. height: windowHeight - bottom - offsetTop,
  12. maxHeight: windowHeight - bottom,
  13. safeWidth: safeArea.right - safeArea.left,
  14. safeHeight: safeArea.bottom - bottom - offsetTop,
  15. safeBottomOffset: windowHeight - safeArea.bottom,
  16. bleeding,
  17. }
  18. this.setData({
  19. container,
  20. containerStyle: Object.entries(container).map(([key, value]) => `--page-container-${key}:${value}px;`).join('')
  21. })
  22. }
  23. }
  24. })