2024-09-10 13:48:51 +00:00
|
|
|
|
import type {
|
|
|
|
|
VbenFormSchema as FormSchema,
|
|
|
|
|
VbenFormProps,
|
|
|
|
|
} from '@vben/common-ui';
|
|
|
|
|
|
2024-10-13 10:33:43 +00:00
|
|
|
|
import type { ComponentType } from './component';
|
2024-09-10 13:48:51 +00:00
|
|
|
|
|
|
|
|
|
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
|
|
|
|
|
import { $t } from '@vben/locales';
|
|
|
|
|
|
2024-10-13 10:33:43 +00:00
|
|
|
|
setupVbenForm<ComponentType>({
|
2024-09-10 13:48:51 +00:00
|
|
|
|
config: {
|
2024-10-05 09:09:42 +00:00
|
|
|
|
// naive-ui组件不接受onChang事件,所以需要禁用
|
2024-10-03 06:22:18 +00:00
|
|
|
|
disabledOnChangeListener: true,
|
2024-10-05 09:09:42 +00:00
|
|
|
|
// naive-ui组件的空值为null,不能是undefined,否则重置表单时不生效
|
|
|
|
|
emptyStateValue: null,
|
2024-09-10 13:48:51 +00:00
|
|
|
|
baseModelPropName: 'value',
|
|
|
|
|
modelPropNameMap: {
|
|
|
|
|
Checkbox: 'checked',
|
|
|
|
|
Radio: 'checked',
|
|
|
|
|
Upload: 'fileList',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
defineRules: {
|
|
|
|
|
required: (value, _params, ctx) => {
|
2024-09-22 06:16:06 +00:00
|
|
|
|
if (value === undefined || value === null || value.length === 0) {
|
2024-10-19 06:28:21 +00:00
|
|
|
|
return $t('ui.formRules.required', [ctx.label]);
|
2024-09-10 13:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
2024-09-20 01:46:03 +00:00
|
|
|
|
selectRequired: (value, _params, ctx) => {
|
|
|
|
|
if (value === undefined || value === null) {
|
2024-10-19 06:28:21 +00:00
|
|
|
|
return $t('ui.formRules.selectRequired', [ctx.label]);
|
2024-09-20 01:46:03 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
2024-09-10 13:48:51 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-10-13 10:33:43 +00:00
|
|
|
|
const useVbenForm = useForm<ComponentType>;
|
2024-09-10 13:48:51 +00:00
|
|
|
|
|
|
|
|
|
export { useVbenForm, z };
|
|
|
|
|
|
2024-10-13 10:33:43 +00:00
|
|
|
|
export type VbenFormSchema = FormSchema<ComponentType>;
|
2024-09-10 13:48:51 +00:00
|
|
|
|
export type { VbenFormProps };
|