refactor(@vben/web-naive): type modal shared data
This commit is contained in:
@@ -7,6 +7,10 @@ defineOptions({
|
|||||||
name: 'FormModelDemo',
|
name: 'FormModelDemo',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface FormModalData {
|
||||||
|
values?: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
schema: [
|
schema: [
|
||||||
{
|
{
|
||||||
@@ -44,7 +48,7 @@ const [Form, formApi] = useVbenForm({
|
|||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal<FormModalData>({
|
||||||
fullscreenButton: false,
|
fullscreenButton: false,
|
||||||
onCancel() {
|
onCancel() {
|
||||||
modalApi.close();
|
modalApi.close();
|
||||||
@@ -55,14 +59,16 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
},
|
},
|
||||||
onOpenChange(isOpen: boolean) {
|
onOpenChange(isOpen: boolean) {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
const { values } = modalApi.getData<Record<string, any>>();
|
const data = modalApi.getData();
|
||||||
if (values) {
|
if (data?.values) {
|
||||||
formApi.setValues(values);
|
formApi.setValues(data.values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title: '内嵌表单示例',
|
title: '内嵌表单示例',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
defineExpose({ modalApi });
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Modal>
|
<Modal>
|
||||||
|
|||||||
Reference in New Issue
Block a user