
* refactor: global components can be customized * refactor: remove use Toast and reconstruct the form adapter
39 lines
940 B
TypeScript
39 lines
940 B
TypeScript
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';
|
|
|
|
setupVbenForm<ComponentType>({
|
|
config: {
|
|
modelPropNameMap: {
|
|
Upload: 'fileList',
|
|
},
|
|
},
|
|
defineRules: {
|
|
required: (value, _params, ctx) => {
|
|
if (value === undefined || value === null || value.length === 0) {
|
|
return $t('formRules.required', [ctx.label]);
|
|
}
|
|
return true;
|
|
},
|
|
selectRequired: (value, _params, ctx) => {
|
|
if (value === undefined || value === null) {
|
|
return $t('formRules.selectRequired', [ctx.label]);
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
});
|
|
|
|
const useVbenForm = useForm<ComponentType>;
|
|
|
|
export { useVbenForm, z };
|
|
|
|
export type VbenFormSchema = FormSchema<ComponentType>;
|
|
export type { VbenFormProps };
|