feat(editor): 增加FloatBox的beforeClose函数

This commit is contained in:
moonszhang 2024-03-13 10:49:11 +08:00 committed by roymondchen
parent cae928f7f9
commit 7ce60b223e

View File

@ -33,12 +33,21 @@ interface Rect {
height: number | string;
}
const props = withDefaults(defineProps<{ visible: boolean; position?: Position; rect?: Rect; title?: string }>(), {
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 closeHandler = () => {
const hide = (cancel?: boolean) => {
if (cancel !== false) {
emit('update:visible', false);
}
};
const closeHandler = () => {
if (typeof props.beforeClose === 'function') {
props.beforeClose(hide);
} else {
hide();
}
};
const nextZIndex = () => {