初始化
This commit is contained in:
41
easyflow-ui-usercenter/app/src/adapter/form.ts
Normal file
41
easyflow-ui-usercenter/app/src/adapter/form.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type {
|
||||
EasyFlowFormSchema as FormSchema,
|
||||
EasyFlowFormProps,
|
||||
} from '@easyflow/common-ui';
|
||||
|
||||
import type { ComponentType } from './component';
|
||||
|
||||
import { setupEasyFlowForm, useEasyFlowForm as useForm, z } from '@easyflow/common-ui';
|
||||
import { $t } from '@easyflow/locales';
|
||||
|
||||
async function initSetupEasyFlowForm() {
|
||||
setupEasyFlowForm<ComponentType>({
|
||||
config: {
|
||||
modelPropNameMap: {
|
||||
Upload: 'fileList',
|
||||
CheckboxGroup: 'model-value',
|
||||
},
|
||||
},
|
||||
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 useEasyFlowForm = useForm<ComponentType>;
|
||||
|
||||
export { initSetupEasyFlowForm, useEasyFlowForm, z };
|
||||
|
||||
export type EasyFlowFormSchema = FormSchema<ComponentType>;
|
||||
export type { EasyFlowFormProps };
|
||||
Reference in New Issue
Block a user