59 lines
1.1 KiB
Vue
59 lines
1.1 KiB
Vue
![]() |
<script lang="ts" setup>
|
||
|
import { useVbenModal } from '@vben/common-ui';
|
||
|
|
||
|
import { useVbenForm } from '#/adapter';
|
||
|
|
||
|
defineOptions({
|
||
|
name: 'FormModelDemo',
|
||
|
});
|
||
|
|
||
|
const [Form, formApi] = useVbenForm({
|
||
|
schema: [
|
||
|
{
|
||
|
component: 'Input',
|
||
|
componentProps: {
|
||
|
placeholder: '请输入',
|
||
|
},
|
||
|
fieldName: 'field1',
|
||
|
label: '字段1',
|
||
|
rules: 'required',
|
||
|
},
|
||
|
{
|
||
|
component: 'Input',
|
||
|
componentProps: {
|
||
|
placeholder: '请输入',
|
||
|
},
|
||
|
fieldName: 'field2',
|
||
|
label: '字段2',
|
||
|
rules: 'required',
|
||
|
},
|
||
|
],
|
||
|
showDefaultActions: false,
|
||
|
});
|
||
|
|
||
|
const [Modal, modalApi] = useVbenModal({
|
||
|
fullscreenButton: false,
|
||
|
onCancel() {
|
||
|
modalApi.close();
|
||
|
},
|
||
|
onConfirm: async () => {
|
||
|
await formApi.submitForm();
|
||
|
modalApi.close();
|
||
|
},
|
||
|
onOpenChange(isOpen: boolean) {
|
||
|
if (isOpen) {
|
||
|
const { values } = modalApi.getData<Record<string, any>>();
|
||
|
if (values) {
|
||
|
formApi.setValues(values);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
title: '内嵌表单示例',
|
||
|
});
|
||
|
</script>
|
||
|
<template>
|
||
|
<Modal>
|
||
|
<Form />
|
||
|
</Modal>
|
||
|
</template>
|