feat: Form useForm 完成

This commit is contained in:
kailong321200875
2023-06-21 11:28:03 +08:00
parent 097b32e1a9
commit 3e4e27c21f
9 changed files with 173 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
import type { Form, FormExpose } from '@/components/Form'
import type { ElForm } from 'element-plus'
import type { ElForm, ElFormItem } from 'element-plus'
import { ref, unref, nextTick } from 'vue'
import { FormSchema, FormSetProps, FormProps } from '@/components/Form'
@@ -74,12 +74,26 @@ export const useForm = () => {
getFormData: async <T = Recordable>(): Promise<T> => {
const form = await getForm()
return form?.formModel as T
},
getComponentExpose: async (field: string) => {
const form = await getForm()
return form?.getComponentExpose(field)
},
getFormItemExpose: async (field: string) => {
const form = await getForm()
return form?.getFormItemExpose(field) as ComponentRef<typeof ElFormItem>
},
getElFormExpose: async () => {
await getForm()
return unref(elFormRef)
}
}
return {
register,
formRef: elFormRef,
methods
}
}