PageLayer.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <el-container style="box-sizing: border-box">
  3. <el-header v-if="useSlots().header" ref="headerRef" class="header">
  4. <slot name="header"></slot>
  5. </el-header>
  6. <el-header v-if="useSlots().headerBlock" ref="headerRef" class="header" style="display: block">
  7. <slot name="headerBlock"></slot>
  8. </el-header>
  9. <el-container>
  10. <slot name="arbitrarily"/>
  11. <el-aside v-if="useSlots().aside" class="aside" :style="mainStyleSize" ref="asideRef">
  12. <slot name="aside" :size="{height:heightRef,width:asideRef?.$el?.clientWidth}"></slot>
  13. </el-aside>
  14. <el-main :style="mainStyleSize" class="page_main" ref="mainRef" v-if="useSlots().main">
  15. <slot name="main" :size="{height:heightRef,width:mainRef?.$el?.clientWidth}"></slot>
  16. </el-main>
  17. <el-main class="page_main" style="height: max-content;" ref="mainRef" v-if="useSlots().mainMaxContentHeight">
  18. <slot name="mainMaxContentHeight"></slot>
  19. </el-main>
  20. </el-container>
  21. </el-container>
  22. </template>
  23. <script setup name='PageLayer' lang="ts">
  24. import {nextTick, onMounted, Ref, ref, useSlots} from "vue";
  25. import {getVisibleSize, visibleWindowSize} from "@/utils/window-size"
  26. const mainStyleSize: object = ref({})
  27. const headerRef: Ref<HTMLElement> = ref(null)
  28. const asideRef: Ref<HTMLElement> = ref(null)
  29. const mainRef: Ref<HTMLElement> = ref(null)
  30. const heightRef = ref<number>(0)
  31. getVisibleSize((val) => {
  32. let clientHeight = (val.height - headerRef.value?.$el.clientHeight) + 'px'
  33. mainStyleSize.value = {
  34. maxHeight: clientHeight,
  35. minHeight: clientHeight,
  36. }
  37. heightRef.value = val.height - headerRef.value?.$el?.clientHeight
  38. })
  39. onMounted(async () => {
  40. await nextTick()
  41. let val = visibleWindowSize.value
  42. let clientHeight = (val.height - headerRef.value?.$el.clientHeight) + 'px'
  43. mainStyleSize.value = {
  44. maxHeight: clientHeight,
  45. minHeight: clientHeight,
  46. }
  47. heightRef.value = val.height - headerRef.value?.$el?.clientHeight
  48. })
  49. </script>
  50. <style scoped lang="scss">
  51. .header {
  52. border-radius: 4px;
  53. background-color: white;
  54. margin-bottom: 4px;
  55. padding: 6px;
  56. height: max-content;
  57. box-shadow: var(--el-box-shadow-light);
  58. }
  59. .aside {
  60. border-radius: 4px;
  61. background-color: white;
  62. margin-right: 4px;
  63. overflow: auto;
  64. width: max-content;
  65. max-width: 300px;
  66. }
  67. .page_main {
  68. overflow: auto;
  69. border-radius: 4px;
  70. padding: 4px;
  71. background-color: white;
  72. box-sizing: border-box;
  73. }
  74. </style>