|
@@ -1,7 +1,7 @@
|
|
|
<script lang="ts" setup>
|
|
|
import type { DrawerProps, ExtendedDrawerApi } from './drawer';
|
|
|
|
|
|
-import { computed, provide, ref, useId, watch } from 'vue';
|
|
|
+import { computed, provide, ref, unref, useId, watch } from 'vue';
|
|
|
|
|
|
import {
|
|
|
useIsMobile,
|
|
@@ -35,6 +35,7 @@ interface Props extends DrawerProps {
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
appendToMain: false,
|
|
|
closeIconPlacement: 'right',
|
|
|
+ destroyOnClose: true,
|
|
|
drawerApi: undefined,
|
|
|
submitting: false,
|
|
|
zIndex: 1000,
|
|
@@ -63,6 +64,7 @@ const {
|
|
|
confirmText,
|
|
|
contentClass,
|
|
|
description,
|
|
|
+ destroyOnClose,
|
|
|
footer: showFooter,
|
|
|
footerClass,
|
|
|
header: showHeader,
|
|
@@ -131,6 +133,29 @@ const getAppendTo = computed(() => {
|
|
|
? `#${ELEMENT_ID_MAIN_CONTENT}>div:not(.absolute)>div`
|
|
|
: undefined;
|
|
|
});
|
|
|
+
|
|
|
+/**
|
|
|
+ * destroyOnClose功能完善
|
|
|
+ */
|
|
|
+// 是否打开过
|
|
|
+const hasOpened = ref(false);
|
|
|
+const isClosed = ref(true);
|
|
|
+watch(
|
|
|
+ () => state?.value?.isOpen,
|
|
|
+ (value) => {
|
|
|
+ isClosed.value = false;
|
|
|
+ if (value && !unref(hasOpened)) {
|
|
|
+ hasOpened.value = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+);
|
|
|
+function handleClosed() {
|
|
|
+ isClosed.value = true;
|
|
|
+ props.drawerApi?.onClosed();
|
|
|
+}
|
|
|
+const getForceMount = computed(() => {
|
|
|
+ return !unref(destroyOnClose) && unref(hasOpened);
|
|
|
+});
|
|
|
</script>
|
|
|
<template>
|
|
|
<Sheet
|
|
@@ -144,15 +169,17 @@ const getAppendTo = computed(() => {
|
|
|
cn('flex w-[520px] flex-col', drawerClass, {
|
|
|
'!w-full': isMobile || placement === 'bottom' || placement === 'top',
|
|
|
'max-h-[100vh]': placement === 'bottom' || placement === 'top',
|
|
|
+ hidden: isClosed,
|
|
|
})
|
|
|
"
|
|
|
:modal="modal"
|
|
|
:open="state?.isOpen"
|
|
|
:side="placement"
|
|
|
:z-index="zIndex"
|
|
|
+ :force-mount="getForceMount"
|
|
|
:overlay-blur="overlayBlur"
|
|
|
@close-auto-focus="handleFocusOutside"
|
|
|
- @closed="() => drawerApi?.onClosed()"
|
|
|
+ @closed="handleClosed"
|
|
|
@escape-key-down="escapeKeyDown"
|
|
|
@focus-outside="handleFocusOutside"
|
|
|
@interact-outside="interactOutside"
|