layout-content.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <script setup lang="ts">
  2. import type { ContentCompactType } from '@vben-core/typings';
  3. import type { CSSProperties } from 'vue';
  4. import { computed } from 'vue';
  5. import { useContentStyle } from '@vben-core/composables';
  6. interface Props {
  7. /**
  8. * 内容区域定宽
  9. */
  10. contentCompact: ContentCompactType;
  11. /**
  12. * 定宽布局宽度
  13. */
  14. contentCompactWidth: number;
  15. padding: number;
  16. paddingBottom: number;
  17. paddingLeft: number;
  18. paddingRight: number;
  19. paddingTop: number;
  20. }
  21. const props = withDefaults(defineProps<Props>(), {});
  22. const { contentElement, overlayStyle } = useContentStyle();
  23. const style = computed((): CSSProperties => {
  24. const {
  25. contentCompact,
  26. padding,
  27. paddingBottom,
  28. paddingLeft,
  29. paddingRight,
  30. paddingTop,
  31. } = props;
  32. const compactStyle: CSSProperties =
  33. contentCompact === 'compact'
  34. ? { margin: '0 auto', width: `${props.contentCompactWidth}px` }
  35. : {};
  36. return {
  37. ...compactStyle,
  38. flex: 1,
  39. padding: `${padding}px`,
  40. paddingBottom: `${paddingBottom}px`,
  41. paddingLeft: `${paddingLeft}px`,
  42. paddingRight: `${paddingRight}px`,
  43. paddingTop: `${paddingTop}px`,
  44. };
  45. });
  46. </script>
  47. <template>
  48. <main ref="contentElement" :style="style" class="bg-background-deep relative">
  49. <slot :overlay-style="overlayStyle" name="overlay"></slot>
  50. <slot></slot>
  51. </main>
  52. </template>