feat: naive adapter form

This commit is contained in:
xingyu4j
2025-10-16 10:20:45 +08:00
parent bc6d0f7dd6
commit 466d0c829e

View File

@@ -7,6 +7,7 @@ import type { ComponentType } from './component';
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui'; import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { isMobile } from '@vben/utils';
async function initSetupVbenForm() { async function initSetupVbenForm() {
setupVbenForm<ComponentType>({ setupVbenForm<ComponentType>({
@@ -33,6 +34,25 @@ async function initSetupVbenForm() {
} }
return true; return true;
}, },
// 手机号非必填
mobile: (value, _params, ctx) => {
if (value === undefined || value === null || value.length === 0) {
return true;
} else if (!isMobile(value)) {
return $t('ui.formRules.mobile', [ctx.label]);
}
return true;
},
// 手机号必填
mobileRequired: (value, _params, ctx) => {
if (value === undefined || value === null || value.length === 0) {
return $t('ui.formRules.required', [ctx.label]);
}
if (!isMobile(value)) {
return $t('ui.formRules.mobile', [ctx.label]);
}
return true;
},
}, },
}); });
} }