feat(design): drawer增加handleClose方法

This commit is contained in:
roymondchen 2023-09-15 15:06:55 +08:00
parent 75b0d9cdf3
commit a9c5004f4d
2 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,7 @@
<template>
<component
class="tmagic-design-drawer"
ref="drawer"
:is="uiComponent"
v-bind="uiProps"
@open="openHandler"
@ -22,7 +23,7 @@
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { computed, ref } from 'vue';
import { getConfig } from './config';
import type { DrawerProps } from './types';
@ -41,6 +42,8 @@ const uiComponent = ui?.component || 'el-drawer';
const uiProps = computed(() => ui?.props(props) || props);
const drawer = ref<any>();
const openHandler = (...args: any[]) => {
emit('open', ...args);
};
@ -56,4 +59,13 @@ const closedHandler = (...args: any[]) => {
const updateModelValue = (v: any) => {
emit('update:modelValue', v);
};
defineExpose({
handleClose: () => {
if (typeof drawer.value?.handleClose === 'function') {
return drawer.value.handleClose();
}
updateModelValue(false);
},
});
</script>

View File

@ -481,7 +481,15 @@ export interface Components {
};
drawer: {
component: DefineComponent<DrawerProps, {}, any> | string;
component:
| DefineComponent<
DrawerProps,
{
handleClose: () => void;
},
any
>
| string;
props: (props: DrawerProps) => DrawerProps;
};