safeArea.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { defineStore } from 'pinia';
  2. /**
  3. * 安全区
  4. * statusBarHeight: 状态栏高度
  5. * capsuleBarHeight: 胶囊按钮高度
  6. * topHeight: 状态栏+胶囊按钮高度
  7. * bottomHeight: 底部安全区高度
  8. * capsuleBarHeight 胶囊按钮栏高度
  9. * capsuleBarLeft 胶囊按钮栏左边距离
  10. * capsuleBarMargin 胶囊按钮栏边距
  11. * capsuleBarMarginTop 胶囊按钮栏上边距
  12. * capsuleBarMarginBottom 胶囊按钮栏下边距
  13. * capsuleBarContentHeight 胶囊按钮内容高度
  14. */
  15. export const useSafeAreaStore = defineStore('safeArea', {
  16. state: () => ({
  17. statusBarHeight: 0,
  18. capsuleBarHeight: 0,
  19. topHeight: 0,
  20. bottomHeight: 0,
  21. capsuleBarLeft: 0,
  22. capsuleBarMargin: 0,
  23. capsuleBarMarginTop: 0,
  24. capsuleBarMarginBottom: 0,
  25. capsuleBarContentHeight: 0
  26. }),
  27. getters: {
  28. /**
  29. * 状态栏样式
  30. */
  31. statusBarStyle: (state) => ({
  32. height: state.statusBarHeight+'px'
  33. }),
  34. /**
  35. * 胶囊区样式
  36. */
  37. capsuleBarStyle: (state) => ({
  38. height: state.capsuleBarHeight+'px',
  39. width: state.capsuleBarLeft+'px',
  40. 'padding-top': state.capsuleBarMarginTop+'px',
  41. 'padding-bottom': state.capsuleBarMarginBottom+'px'
  42. }),
  43. /**
  44. * 图标容器样式
  45. */
  46. iconBoxStyle: (state) => ({
  47. width: state.capsuleBarContentHeight-5+'px',
  48. height: state.capsuleBarContentHeight-5+'px'
  49. }),
  50. /**
  51. * 图标大小
  52. */
  53. iconSize: (state) => state.capsuleBarContentHeight-10,
  54. /**
  55. * 底部填充区样式
  56. */
  57. bottomBoxStyle: (state) => ({
  58. height: state.bottomHeight+'px'
  59. })
  60. }
  61. });