SPanelLayout2.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. const n = `<template>
  2. <div :class="['s-panel-layout', { 'is-panel': isPanelMode }]" :style="rootStyle">
  3. <div
  4. v-if="showHeader"
  5. class="s-panel-layout-header"
  6. :style="{ position: props.headerSticky ? 'sticky' : '' }"
  7. >
  8. <div class="s-panel-layout-title">
  9. <slot name="title">{{ title }}</slot>
  10. </div>
  11. <div v-if="$slots.extra" class="s-panel-layout-extra">
  12. <slot name="extra" />
  13. </div>
  14. </div>
  15. <div class="s-panel-layout-content">
  16. <div class="s-panel-scroll-view" :style="{ width: contentWidth }">
  17. <slot />
  18. </div>
  19. </div>
  20. <div v-if="$slots.footer" class="s-panel-layout-footer">
  21. <a-space :size="spaceSize">
  22. <slot name="footer" />
  23. </a-space>
  24. </div>
  25. </div>
  26. </template>
  27. <script setup>
  28. import { computed, useSlots, ref } from 'vue'
  29. defineOptions({ name: 'SPanelLayout' })
  30. const props = defineProps({
  31. // 面板标题
  32. title: {
  33. type: String,
  34. default: ''
  35. },
  36. // 是否显示标题栏(传了 #extra 插槽时也会显示)
  37. showTitle: {
  38. type: Boolean,
  39. default: true
  40. },
  41. // 面板高度:默认占满父容器,可传 '100vh' / 'calc(100vh - 60px)' / 具体像素值
  42. height: {
  43. type: [String, Number],
  44. default: '100%'
  45. },
  46. // 内容区滚动时标题栏是否吸顶
  47. headerSticky: {
  48. type: Boolean,
  49. default: false
  50. },
  51. // 内容区宽度,默认 100%;传固定宽度(如 1200px)后居中显示
  52. width: {
  53. type: [Number, String],
  54. default: '100%'
  55. }
  56. })
  57. const slots = useSlots()
  58. const spaceSize = ref(8)
  59. // 是否启用完整面板骨架:有标题或独占插槽时才启用,否则退化为纯容器
  60. const isPanelMode = computed(() => !!(props.title || slots.title || slots.extra || slots.footer))
  61. const showHeader = computed(() => props.showTitle && !!(props.title || slots.title || slots.extra))
  62. const rootStyle = computed(() => {
  63. if (!isPanelMode.value) return null
  64. if (props.height === null || props.height === undefined || props.height === '') return null
  65. // 默认 100% 交给样式表(纯 CSS 撑满),只有显式传了自定义高度才落内联 style
  66. if (props.height === '100%') return null
  67. const h = typeof props.height === 'number' ? \`\${props.height}px\` : props.height
  68. return {
  69. height: h
  70. }
  71. })
  72. const contentWidth = computed(() => {
  73. return window.$utils.isNumber(props.width) ? props.width + 'px' : props.width
  74. })
  75. <\/script>
  76. <style lang="less" scoped>
  77. // 只有面板模式才施加骨架布局,纯容器模式不产生任何副作用
  78. .s-panel-layout.is-panel {
  79. // 高度默认吃满父容器(父级须有确定高度);自定义 height 时由内联 style 覆盖
  80. height: 100%;
  81. box-sizing: border-box;
  82. display: flex;
  83. flex-direction: column;
  84. width: 100%;
  85. min-height: 0;
  86. overflow: hidden;
  87. box-sizing: border-box;
  88. background-color: var(--s-bg-color-container);
  89. }
  90. .s-panel-layout-header {
  91. flex: none;
  92. display: flex;
  93. align-items: center;
  94. justify-content: space-between;
  95. height: 60px;
  96. padding: 0 10px;
  97. box-sizing: border-box;
  98. border-bottom: 1px solid var(--s-bg-color);
  99. position: static;
  100. top: 0;
  101. left: 0;
  102. }
  103. .s-panel-layout-title {
  104. flex: 1;
  105. min-width: 0;
  106. font-size: 20px;
  107. font-weight: 500;
  108. color: var(--s-text-color);
  109. overflow: hidden;
  110. text-overflow: ellipsis;
  111. white-space: nowrap;
  112. }
  113. .s-panel-layout-extra {
  114. flex: none;
  115. display: flex;
  116. align-items: center;
  117. gap: 10px;
  118. margin-left: 10px;
  119. }
  120. .s-panel-layout-content {
  121. flex: 1;
  122. min-height: 0;
  123. overflow: hidden auto;
  124. display: flex;
  125. justify-content: center;
  126. align-items: flex-start;
  127. }
  128. .s-panel-layout-footer {
  129. flex: none;
  130. display: flex;
  131. align-items: center;
  132. justify-content: center;
  133. padding: 14px 10px;
  134. box-sizing: border-box;
  135. background-color: var(--s-bg-color-container);
  136. border-top: 1px solid var(--s-bg-color);
  137. }
  138. </style>
  139. `;
  140. export {
  141. n as default
  142. };