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
| import type {
| VbenFormSchema as FormSchema,
| VbenFormProps,
| } from '@vben/common-ui';
|
| import type { ComponentType } from './component';
|
| import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
| import { $t } from '@vben/locales';
|
| import { initComponentAdapter } from './component';
|
| initComponentAdapter();
| setupVbenForm<ComponentType>({
| config: {
| baseModelPropName: 'value',
| // naive-ui组件的空值为null,不能是undefined,否则重置表单时不生效
| emptyStateValue: null,
| modelPropNameMap: {
| Checkbox: 'checked',
| Radio: 'checked',
| Switch: 'checked',
| Upload: 'fileList',
| },
| },
| defineRules: {
| required: (value, _params, ctx) => {
| if (value === undefined || value === null || value.length === 0) {
| return $t('ui.formRules.required', [ctx.label]);
| }
| return true;
| },
| selectRequired: (value, _params, ctx) => {
| if (value === undefined || value === null) {
| return $t('ui.formRules.selectRequired', [ctx.label]);
| }
| return true;
| },
| },
| });
|
| const useVbenForm = useForm<ComponentType>;
|
| export { useVbenForm, z };
|
| export type VbenFormSchema = FormSchema<ComponentType>;
| export type { VbenFormProps };
|
|