layout-content.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. interface Props {
  6. /**
  7. * 内容区域定宽
  8. * @default 'wide'
  9. */
  10. contentCompact?: ContentCompactType;
  11. /**
  12. * 定宽布局宽度
  13. * @default 1200
  14. */
  15. contentCompactWidth?: number;
  16. /**
  17. * padding
  18. * @default 16
  19. */
  20. padding?: number;
  21. /**
  22. * paddingBottom
  23. * @default 16
  24. */
  25. paddingBottom?: number;
  26. /**
  27. * paddingLeft
  28. * @default 16
  29. */
  30. paddingLeft?: number;
  31. /**
  32. * paddingRight
  33. * @default 16
  34. */
  35. paddingRight?: number;
  36. /**
  37. * paddingTop
  38. * @default 16
  39. */
  40. paddingTop?: number;
  41. }
  42. defineOptions({ name: 'LayoutContent' });
  43. const props = withDefaults(defineProps<Props>(), {
  44. contentCompact: 'wide',
  45. contentCompactWidth: 1200,
  46. padding: 16,
  47. paddingBottom: 16,
  48. paddingLeft: 16,
  49. paddingRight: 16,
  50. paddingTop: 16,
  51. });
  52. const style = computed((): CSSProperties => {
  53. const {
  54. contentCompact,
  55. padding,
  56. paddingBottom,
  57. paddingLeft,
  58. paddingRight,
  59. paddingTop,
  60. } = props;
  61. const compactStyle: CSSProperties =
  62. contentCompact === 'compact' ? { margin: '0 auto', width: `1200px` } : {};
  63. return {
  64. ...compactStyle,
  65. flex: 1,
  66. padding: `${padding}px`,
  67. paddingBottom: `${paddingBottom}px`,
  68. paddingLeft: `${paddingLeft}px`,
  69. paddingRight: `${paddingRight}px`,
  70. paddingTop: `${paddingTop}px`,
  71. };
  72. });
  73. </script>
  74. <template>
  75. <main :style="style">
  76. <slot></slot>
  77. </main>
  78. </template>