index.vue
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<script setup lang="ts">
import { computed, unref } from 'vue'
import type { RuleError } from 'ant-design-vue/lib/form/interface'
import { formSchemas } from './config'
import { FormLayoutEnum } from '@/components/Form/src/enum'
import { BasicForm, useForm } from '@/components/Form'
export interface ComponentExposeType {
getFieldsValue: () => any
setFieldsValue: (value: any) => void
validate: () => Promise<RuleError | any>
}
const props = defineProps<{ componentKey?: string }>()
defineEmits(['fieldValueChange'])
const getComponentKey = computed(() => {
return props.componentKey
})
const [registerForm, formActionType] = useForm({
schemas: formSchemas(unref(getComponentKey)),
showActionButtonGroup: false,
layout: FormLayoutEnum.HORIZONTAL,
labelWidth: 70,
})
const getFieldsValue = () => {
return formActionType.getFieldsValue()
}
const validate = async () => {
return await formActionType.validate()
}
const setFieldsValue = (value: Recordable) => {
formActionType.setFieldsValue(value)
formActionType.clearValidate()
}
defineExpose<ComponentExposeType>({
getFieldsValue,
setFieldsValue,
validate,
})
</script>
<template>
<BasicForm @register="registerForm" @field-value-change="$emit('fieldValueChange')" />
</template>