cl-safe-area.uvue 822 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view
  3. class="cl-safe-area"
  4. :class="[{ 'is-dark': isDark }, pt.className]"
  5. :style="{
  6. height: height + 'px'
  7. }"
  8. >
  9. <slot></slot>
  10. </view>
  11. </template>
  12. <script setup lang="ts">
  13. import { isDark, page, parsePt } from "@/cool";
  14. import { computed, type PropType } from "vue";
  15. defineOptions({
  16. name: "cl-safe-area"
  17. });
  18. const props = defineProps({
  19. pt: {
  20. type: Object,
  21. default: () => ({})
  22. },
  23. type: {
  24. type: String as PropType<"top" | "bottom">,
  25. default: "top"
  26. }
  27. });
  28. type PassThrough = {
  29. className?: string;
  30. };
  31. const pt = computed(() => parsePt<PassThrough>(props.pt));
  32. // 高度
  33. const height = computed(() => {
  34. return page.getSafeAreaHeight(props.type) + "px";
  35. });
  36. </script>
  37. <style lang="scss" scoped>
  38. .cl-safe-area {
  39. @apply bg-white;
  40. &.is-dark {
  41. @apply bg-surface-900;
  42. }
  43. }
  44. </style>