mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 19:29:04 +08:00
refactor(form): code optimization and reconstruction
This commit is contained in:
@@ -1,16 +1,68 @@
|
||||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="register" title="Modal Title">
|
||||
<p class="h-20">外部传递数据: {{ receiveModalDataRef }}</p>
|
||||
<BasicForm @register="registerForm" :model="model" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { defineComponent, nextTick, ref } from 'vue';
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
||||
const schemas: FormSchema[] = [
|
||||
{
|
||||
field: 'field1',
|
||||
component: 'Input',
|
||||
label: '字段1',
|
||||
colProps: {
|
||||
span: 12,
|
||||
},
|
||||
defaultValue: '111',
|
||||
},
|
||||
{
|
||||
field: 'field2',
|
||||
component: 'Input',
|
||||
label: '字段2',
|
||||
colProps: {
|
||||
span: 12,
|
||||
},
|
||||
},
|
||||
];
|
||||
export default defineComponent({
|
||||
components: { BasicModal },
|
||||
components: { BasicModal, BasicForm },
|
||||
setup() {
|
||||
const [register, { receiveModalDataRef }] = useModalInner();
|
||||
return { register, receiveModalDataRef };
|
||||
const modelRef = ref({});
|
||||
const [
|
||||
registerForm,
|
||||
{
|
||||
// setFieldsValue,
|
||||
// setProps
|
||||
},
|
||||
] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas,
|
||||
showActionButtonGroup: false,
|
||||
actionColOptions: {
|
||||
span: 24,
|
||||
},
|
||||
});
|
||||
|
||||
const [register, { receiveModalDataRef }] = useModalInner((data) => {
|
||||
nextTick(() => {
|
||||
// 方式1
|
||||
// setFieldsValue({
|
||||
// field2: data.data,
|
||||
// field1: data.info,
|
||||
// });
|
||||
|
||||
// 方式2
|
||||
modelRef.value = { field2: data.data, field1: data.info };
|
||||
|
||||
// setProps({
|
||||
// model:{ field2: data.data, field1: data.info }
|
||||
// })
|
||||
});
|
||||
});
|
||||
return { register, receiveModalDataRef, schemas, registerForm, model: modelRef };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@@ -48,6 +48,12 @@
|
||||
data: 'content',
|
||||
info: 'Info',
|
||||
});
|
||||
// setTimeout(() => {
|
||||
// transferModalData({
|
||||
// data: 'content1',
|
||||
// info: 'Info1',
|
||||
// });
|
||||
// }, 3000);
|
||||
openModal4(true);
|
||||
}
|
||||
function openModalLoading() {
|
||||
|
Reference in New Issue
Block a user