From 466d0c829ecd4fbfd011c5812c692de4f2d23c3d Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Thu, 16 Oct 2025 10:20:45 +0800 Subject: [PATCH] feat: naive adapter form --- apps/web-naive/src/adapter/form.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/apps/web-naive/src/adapter/form.ts b/apps/web-naive/src/adapter/form.ts index 9de44a01d..c782f5f47 100644 --- a/apps/web-naive/src/adapter/form.ts +++ b/apps/web-naive/src/adapter/form.ts @@ -7,6 +7,7 @@ import type { ComponentType } from './component'; import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui'; import { $t } from '@vben/locales'; +import { isMobile } from '@vben/utils'; async function initSetupVbenForm() { setupVbenForm({ @@ -33,6 +34,25 @@ async function initSetupVbenForm() { } 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; + }, }, }); }