| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- const n = `<template>
- <div :class="['s-panel-layout', { 'is-panel': isPanelMode }]" :style="rootStyle">
- <div
- v-if="showHeader"
- class="s-panel-layout-header"
- :style="{ position: props.headerSticky ? 'sticky' : '' }"
- >
- <div class="s-panel-layout-title">
- <slot name="title">{{ title }}</slot>
- </div>
- <div v-if="$slots.extra" class="s-panel-layout-extra">
- <slot name="extra" />
- </div>
- </div>
- <div class="s-panel-layout-content">
- <div class="s-panel-scroll-view" :style="{ width: contentWidth }">
- <slot />
- </div>
- </div>
- <div v-if="$slots.footer" class="s-panel-layout-footer">
- <a-space :size="spaceSize">
- <slot name="footer" />
- </a-space>
- </div>
- </div>
- </template>
- <script setup>
- import { computed, useSlots, ref } from 'vue'
- defineOptions({ name: 'SPanelLayout' })
- const props = defineProps({
- // 面板标题
- title: {
- type: String,
- default: ''
- },
- // 是否显示标题栏(传了 #extra 插槽时也会显示)
- showTitle: {
- type: Boolean,
- default: true
- },
- // 面板高度:默认占满父容器,可传 '100vh' / 'calc(100vh - 60px)' / 具体像素值
- height: {
- type: [String, Number],
- default: '100%'
- },
- // 内容区滚动时标题栏是否吸顶
- headerSticky: {
- type: Boolean,
- default: false
- },
- // 内容区宽度,默认 100%;传固定宽度(如 1200px)后居中显示
- width: {
- type: [Number, String],
- default: '100%'
- }
- })
- const slots = useSlots()
- const spaceSize = ref(8)
- // 是否启用完整面板骨架:有标题或独占插槽时才启用,否则退化为纯容器
- const isPanelMode = computed(() => !!(props.title || slots.title || slots.extra || slots.footer))
- const showHeader = computed(() => props.showTitle && !!(props.title || slots.title || slots.extra))
- const rootStyle = computed(() => {
- if (!isPanelMode.value) return null
- if (props.height === null || props.height === undefined || props.height === '') return null
- // 默认 100% 交给样式表(纯 CSS 撑满),只有显式传了自定义高度才落内联 style
- if (props.height === '100%') return null
- const h = typeof props.height === 'number' ? \`\${props.height}px\` : props.height
- return {
- height: h
- }
- })
- const contentWidth = computed(() => {
- return window.$utils.isNumber(props.width) ? props.width + 'px' : props.width
- })
- <\/script>
- <style lang="less" scoped>
- // 只有面板模式才施加骨架布局,纯容器模式不产生任何副作用
- .s-panel-layout.is-panel {
- // 高度默认吃满父容器(父级须有确定高度);自定义 height 时由内联 style 覆盖
- height: 100%;
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- width: 100%;
- min-height: 0;
- overflow: hidden;
- box-sizing: border-box;
- background-color: var(--s-bg-color-container);
- }
- .s-panel-layout-header {
- flex: none;
- display: flex;
- align-items: center;
- justify-content: space-between;
- height: 60px;
- padding: 0 10px;
- box-sizing: border-box;
- border-bottom: 1px solid var(--s-bg-color);
- position: static;
- top: 0;
- left: 0;
- }
- .s-panel-layout-title {
- flex: 1;
- min-width: 0;
- font-size: 20px;
- font-weight: 500;
- color: var(--s-text-color);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .s-panel-layout-extra {
- flex: none;
- display: flex;
- align-items: center;
- gap: 10px;
- margin-left: 10px;
- }
- .s-panel-layout-content {
- flex: 1;
- min-height: 0;
- overflow: hidden auto;
- display: flex;
- justify-content: center;
- align-items: flex-start;
- }
- .s-panel-layout-footer {
- flex: none;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 14px 10px;
- box-sizing: border-box;
- background-color: var(--s-bg-color-container);
- border-top: 1px solid var(--s-bg-color);
- }
- </style>
- `;
- export {
- n as default
- };
|