From 7ce60b223e124ac21d8da56480a35dcca97231d9 Mon Sep 17 00:00:00 2001 From: moonszhang Date: Wed, 13 Mar 2024 10:49:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(editor):=20=E5=A2=9E=E5=8A=A0FloatBox?= =?UTF-8?q?=E7=9A=84beforeClose=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/src/components/FloatingBox.vue | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/editor/src/components/FloatingBox.vue b/packages/editor/src/components/FloatingBox.vue index 384e61b4..53c2ad20 100644 --- a/packages/editor/src/components/FloatingBox.vue +++ b/packages/editor/src/components/FloatingBox.vue @@ -33,12 +33,21 @@ interface Rect { height: number | string; } -const props = withDefaults(defineProps<{ visible: boolean; position?: Position; rect?: Rect; title?: string }>(), { - visible: false, - title: '', - position: () => ({ left: 0, top: 0 }), - rect: () => ({ width: 'auto', height: 'auto' }), -}); +const props = withDefaults( + defineProps<{ + visible: boolean; + position?: Position; + rect?: Rect; + title?: string; + beforeClose?: (done: (cancel?: boolean) => void) => void; + }>(), + { + visible: false, + title: '', + position: () => ({ left: 0, top: 0 }), + rect: () => ({ width: 'auto', height: 'auto' }), + }, +); const emit = defineEmits<{ 'update:visible': [boolean]; @@ -125,8 +134,18 @@ onBeforeUnmount(() => { destroyMoveable(); }); +const hide = (cancel?: boolean) => { + if (cancel !== false) { + emit('update:visible', false); + } +}; + const closeHandler = () => { - emit('update:visible', false); + if (typeof props.beforeClose === 'function') { + props.beforeClose(hide); + } else { + hide(); + } }; const nextZIndex = () => {