跳到正文

FaDrawer 抽屉 ​

使用与 FaDialog 相同的业务生命周期和 Footer 约定,通过返回 Promise 的 Expose open(function?)、close(function?) 控制显示;v-model 只接收内部状态回写。四个方向均支持拖动边缘改变尺寸,打开和关闭保留滑入、滑出动画,size 在所有响应式断点均由调用方控制。

异步打开、关闭与业务 Loading

可操作示例
查看代码
Vue
<template>
	<ElButton type="primary" @click="drawerRef?.open(wait)">异步打开 Drawer</ElButton>
	<FaDrawer ref="drawerRef" title="项目详情" size="42%" :before-close="wait" @confirm-click="confirm">
		<template #default="{ loading }">
			<ElAlert :closable="false" :title="loading ? '正在执行业务钩子…' : '内容已就绪'" type="success" />
		</template>
	</FaDrawer>
</template>

<script setup lang="ts">
import { useTemplateRef } from "vue";

interface DrawerExpose {
	close: (callback?: () => void | Promise<void>) => Promise<void>;
	open: (callback?: () => void | Promise<void>) => Promise<void>;
}

const drawerRef = useTemplateRef<DrawerExpose>("drawerRef");
const wait = async (): Promise<void> => {
	await new Promise<void>((resolve) => {
		window.setTimeout(resolve, 600);
	});
};
const confirm = (): void => {
	drawerRef.value?.close(wait);
};
</script>

四个打开方向与拖动调整尺寸

可操作示例
查看代码
Vue
<template>
	<div class="demo-row">
		<ElButton @click="open('ltr')">从左侧打开</ElButton>
		<ElButton type="primary" @click="open('rtl')">从右侧打开</ElButton>
		<ElButton @click="open('ttb')">从顶部打开</ElButton>
		<ElButton @click="open('btt')">从底部打开</ElButton>
	</div>
	<FaDrawer ref="drawerRef" :direction="direction" :size="direction === 'rtl' || direction === 'ltr' ? '42%' : '45%'" title="可拖动 Drawer">
		<div class="demo-stack">
			<ElAlert :closable="false" title="拖动内容边缘可改变 Drawer 尺寸" type="info" />
			<p>当前方向:{{ direction }}</p>
		</div>
	</FaDrawer>
</template>

<script setup lang="ts">
import { nextTick, ref, useTemplateRef } from "vue";
import type { DrawerProps } from "element-plus";

const drawerRef = useTemplateRef<{ open: () => Promise<void> }>("drawerRef");
const direction = ref<DrawerProps["direction"]>("rtl");

const open = async (value: DrawerProps["direction"]): Promise<void> => {
	direction.value = value;
	await nextTick();
	await drawerRef.value?.open();
};
</script>

FaDrawer 完整 API

Props 属性

EL 默认值取自导入 Fast 前的 Element Plus。 2.14.7

属性来源说明类型默认值
draggableFast 修改是否允许拖动。BooleanFasttrueELfalse
appendToBodyFast 修改是否挂载到 body。BooleanFasttrueELfalse
beforeCloseFast 修改关闭前回调。FunctionFast—EL—
destroyOnCloseFast 修改关闭后是否销毁弹层内容。BooleanFasttrueELfalse
modelValueFast 修改v-model 绑定值。BooleanFastfalseELfalse
resizableFast 修改是否允许调整 Drawer 尺寸。BooleanFastfalseELfalse
showRefreshFast 新增是否显示刷新按钮。Booleantrue
showFullscreenFast 新增是否显示全屏按钮。Booleantrue
showCloseButtonFast 新增是否显示底部关闭按钮。Booleantrue
showConfirmButtonFast 新增是否显示底部确认按钮。Booleantrue
disabledConfirmButtonFast 新增是否禁用 Fast 底部确认按钮。Booleanfalse
closeButtonTextFast 新增底部关闭按钮文本。String取消
confirmButtonTextFast 新增底部确认按钮文本。String确认
hideFooterFast 新增是否隐藏底部操作区。Booleanfalse
showBeforeCloseFast 新增是否在关闭前显示团队确认提示。Booleanfalse
afterOpenFast 新增Fast 打开业务钩子,支持异步函数。Function—
centerEL 原生是否让 Dialog 头部和底部内容水平居中。Booleanfalse
alignCenterEL 原生是否让 Dialog 在页面中垂直居中。Booleanfalse
closeIconEL 原生关闭按钮使用的图标组件。String / Object / Function—
overflowEL 原生拖动 Dialog 时是否允许超出可视区域。Booleanfalse
fullscreenEL 原生是否让 Dialog 占满可视区域。Booleanfalse
headerClassEL 原生头部容器的自定义类名。String / Array / Object / Booleanfalse
bodyClassEL 原生正文容器的自定义类名。String / Array / Object / Booleanfalse
footerClassEL 原生底部容器的自定义类名。String / Array / Object / Booleanfalse
showCloseEL 原生是否显示关闭按钮。Booleantrue
titleEL 原生组件标题文本。String""
ariaLevelEL 原生弹层标题在可访问性树中的标题层级。String2
appendToEL 原生浮层挂载目标。String / Objectbody
closeOnClickModalEL 原生是否允许点击遮罩关闭。Booleantrue
closeOnPressEscapeEL 原生是否允许按 Esc 关闭。Booleantrue
lockScrollEL 原生打开期间是否禁止页面滚动。Booleantrue
modalEL 原生是否显示遮罩层。Booleantrue
modalPenetrableEL 原生是否允许点击穿透遮罩,需将 modal 设为 false。Booleanfalse
openDelayEL 原生打开前的延迟,单位为毫秒。Number0
closeDelayEL 原生关闭前的延迟,单位为毫秒。Number0
topEL 原生Dialog 距离页面顶部的偏移。String—
modalClassEL 原生遮罩层的自定义类名。String / Array / Object / Booleanfalse
widthEL 原生组件宽度。String / Number—
zIndexEL 原生弹层的堆叠顺序,对应 CSS z-index。Number—
trapFocusEL 原生弹层打开时是否将键盘焦点限制在弹层内部。Booleanfalse
headerAriaLevelEL 原生头部标题的 aria-level,用于辅助技术识别标题层级。String2
transitionEL 原生弹层打开和关闭使用的过渡名称。String / Object—
directionEL 原生抽屉的打开方向。Stringrtl
sizeEL 原生组件尺寸。String / Number30%
withHeaderEL 原生是否渲染抽屉头部。关闭后,title 属性和 title 插槽均不生效。Booleantrue
modalFadeEL 原生Drawer 遮罩层是否使用淡入淡出动画。Booleantrue

Events 事件

名称来源说明参数 / 类型
openEL 原生Fast 打开业务流程完成时触发。—
openedEL 原生打开动画完成时触发。—
closeEL 原生关闭流程完成时触发。—
closedEL 原生关闭动画完成时触发。—
update:modelValueEL 原生更新 v-model。—
openAutoFocusEL 原生弹层打开并完成自动聚焦时触发。—
closeAutoFocusEL 原生弹层关闭并完成焦点恢复时触发。—
resize-startEL 原生Drawer 开始拖动调整尺寸时触发。—
resizeEL 原生Drawer 拖动过程中尺寸变化时持续触发。—
resize-endEL 原生Drawer 拖动调整尺寸结束时触发。—
confirmClickFast 新增点击 Fast 确认按钮时触发。—

Slots 插槽

名称来源说明参数 / 类型
default({ loading })EL 原生组件默认内容插槽。({ loading })
header({ loading, close })EL 原生自定义头部内容或表格头部业务区域。({ loading, close })
titleEL 原生自定义 Dialog 或 Drawer 标题。—
footer({ loading, close })EL 原生自定义底部操作区域;弹层中可获得 loading 和 close。({ loading, close })

实例成员

名称来源说明参数 / 类型
handleCloseEL 原生调用 Element Plus 内部关闭处理。—
loadingFast 新增Fast 业务加载状态。—
visibleFast 新增弹层或右键菜单当前是否可见。—
openFast 新增执行 Fast 异步打开流程。—
closeFast 新增执行 Fast 异步关闭流程。—
refreshFast 新增重新执行组件数据请求或刷新业务内容。—
doLoadingFast 新增在统一 Loading 和遮罩状态下执行同步或异步函数。—

FaDrawer 实例方法 ​

以下代码为调用片段。行、选项和字段应对应实际数据。

handleClose 关闭 ​

用于关闭 Drawer, 该方法会调用传入的 before-close 方法

签名 ​

ts
handleClose(): void;

示例 ​

vue
<template>
	<FaDrawer ref="componentRef" />
	<button type="button" @click="handleExample">调用方法</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDrawer } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDrawer>>();
function handleExample() {
	componentRef.value?.handleClose();
}
</script>

输入: 无参数。

返回: void。

open 打开 ​

打开弹窗

签名 ​

ts
open(openFunction?: () => void | Promise<void>): Promise<void>;

示例 ​

vue
<template>
	<FaDrawer ref="componentRef" />
	<button type="button" @click="handleExample">调用方法</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDrawer } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDrawer>>();
const saveData = async () => Promise.resolve();
async function handleExample() {
	const result = await componentRef.value?.open(async () => saveData());
	console.log(result);
}
</script>

输入 ​

输入值输入值类型必填/默认值输入值说明
openFunction(() => void | Promise<void>) | undefined否打开动画前执行的可选同步或异步任务。

返回 ​

返回值返回值类型返回值说明
resultPromise<void>异步完成后的结果;Promise 拒绝时由调用方处理。

close 关闭 ​

关闭弹窗

签名 ​

ts
close(closeFunction?: () => void | Promise<void>): Promise<void>;

示例 ​

vue
<template>
	<FaDrawer ref="componentRef" />
	<button type="button" @click="handleExample">调用方法</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDrawer } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDrawer>>();
const saveData = async () => Promise.resolve();
async function handleExample() {
	const result = await componentRef.value?.close(async () => saveData());
	console.log(result);
}
</script>

输入 ​

输入值输入值类型必填/默认值输入值说明
closeFunction(() => void | Promise<void>) | undefined否关闭动画前执行的可选同步或异步任务。

返回 ​

返回值返回值类型返回值说明
resultPromise<void>异步完成后的结果;Promise 拒绝时由调用方处理。

refresh 刷新 ​

刷新弹窗

签名 ​

ts
refresh(): Promise<void>;

示例 ​

vue
<template>
	<FaDrawer ref="componentRef" />
	<button type="button" @click="handleExample">调用方法</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDrawer } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDrawer>>();
async function handleExample() {
	const result = await componentRef.value?.refresh();
	console.log(result);
}
</script>

输入 ​

该方法没有输入参数。

返回 ​

返回值返回值类型返回值说明
resultPromise<void>异步完成后的结果;Promise 拒绝时由调用方处理。

doLoading 加载 ​

弹窗加载

签名 ​

ts
doLoading(loadingFunction: () => void | Promise<void>): Promise<void>;

示例 ​

vue
<template>
	<FaDrawer ref="componentRef" />
	<button type="button" @click="handleExample">调用方法</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaDrawer } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaDrawer>>();
const saveData = async () => Promise.resolve();
async function handleExample() {
	const result = await componentRef.value?.doLoading(async () => saveData());
	console.log(result);
}
</script>

输入 ​

输入值输入值类型必填/默认值输入值说明
loadingFunction() => void | Promise<void>是需要在加载状态中执行的同步或异步任务。

返回 ​

返回值返回值类型返回值说明
resultPromise<void>异步完成后的结果;Promise 拒绝时由调用方处理。