118 lines
3.8 KiB
Vue
118 lines
3.8 KiB
Vue
<script setup lang="ts">
|
||
import { NButton, NDrawer, NDrawerContent } from 'naive-ui'
|
||
|
||
/** 全屏抽屉共用标题、说明和保存期间的关闭锁定。 */
|
||
withDefaults(
|
||
defineProps<{
|
||
/** 抽屉标题,同时作为可访问名称。 */
|
||
title: string
|
||
/** 标题下的说明,可使用同名插槽覆盖。 */
|
||
description?: string
|
||
/** 提交期间禁止关闭抽屉。 */
|
||
busy?: boolean
|
||
}>(),
|
||
{ description: '', busy: false }
|
||
)
|
||
/** 全屏抽屉显隐状态,由调用方保留业务草稿。 */
|
||
const open = defineModel<boolean>('open', { default: false })
|
||
/** 关闭动画结束后通知调用方,便于交接焦点。 */
|
||
const emit = defineEmits<{ closed: [] }>()
|
||
</script>
|
||
|
||
<template>
|
||
<!-- 以下是从右侧展开、内容同步铺满视口的公共全屏抽屉模块 -->
|
||
<NDrawer
|
||
v-model:show="open"
|
||
placement="right"
|
||
width="100vw"
|
||
:auto-focus="false"
|
||
:mask-closable="!busy"
|
||
:close-on-esc="!busy"
|
||
class="app-drawer"
|
||
:aria-label="title"
|
||
@after-leave="emit('closed')"
|
||
>
|
||
<NDrawerContent :closable="!busy" :native-scrollbar="false">
|
||
<!-- 以下是固定标题与说明模块,与正文共用左右边界 -->
|
||
<template #header>
|
||
<div class="app-drawer-heading">
|
||
<div class="text-lg font-semibold">{{ title }}</div>
|
||
<div v-if="description || $slots.description" class="mt-2 text-sm font-normal leading-6 text-muted">
|
||
<slot name="description">{{ description }}</slot>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<!-- 以下是独立滚动的正文模块 -->
|
||
<slot />
|
||
<!-- 以下是固定底部操作模块,未自定义底栏时默认显示关闭按钮 -->
|
||
<template #footer>
|
||
<div class="app-drawer-footer">
|
||
<slot name="footer"
|
||
><NButton type="default" :disabled="busy" @click="open = false">关闭</NButton></slot
|
||
>
|
||
</div>
|
||
</template>
|
||
</NDrawerContent>
|
||
</NDrawer>
|
||
</template>
|
||
|
||
<style>
|
||
/* 全屏抽屉沿用项目表面和输入底色,不对正文设置最大宽度。 */
|
||
.app-drawer.n-drawer {
|
||
--app-field: var(--app-control);
|
||
--app-field-hover: var(--app-control-hover);
|
||
max-width: 100vw;
|
||
background: var(--app-surface);
|
||
}
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-header {
|
||
position: relative;
|
||
padding: 24px;
|
||
}
|
||
/* 关闭入口独立定位,避免占据标题列后造成正文边界错位。 */
|
||
.app-drawer .n-drawer-header__close {
|
||
position: absolute;
|
||
top: 24px;
|
||
right: 24px;
|
||
}
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-header__main {
|
||
width: 100%;
|
||
min-width: 0;
|
||
}
|
||
.app-drawer-heading {
|
||
box-sizing: border-box;
|
||
width: 100%;
|
||
padding-right: 40px;
|
||
}
|
||
/* 正文顶部不再叠加留白,保留左右边界和滚动到底部时的间距。 */
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-body-content-wrapper {
|
||
padding: 0 24px 32px;
|
||
}
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-footer {
|
||
display: block;
|
||
padding: 20px 24px max(20px, env(safe-area-inset-bottom));
|
||
}
|
||
.app-drawer-footer {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
gap: 8px;
|
||
width: 100%;
|
||
}
|
||
|
||
/* 窄屏缩小外层留白,正文布局由各业务表单控制。 */
|
||
@media (max-width: 639px) {
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-header {
|
||
padding: 20px 16px;
|
||
}
|
||
.app-drawer .n-drawer-header__close {
|
||
top: 20px;
|
||
right: 16px;
|
||
}
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-body-content-wrapper {
|
||
padding: 0 16px 24px;
|
||
}
|
||
.app-drawer.n-drawer .n-drawer-content .n-drawer-footer {
|
||
padding-inline: 16px;
|
||
}
|
||
}
|
||
</style>
|