feat: 封装手机号校验,mobile 非必填校验,mobileRequired 必填校验

This commit is contained in:
xingyu4j
2025-04-23 17:51:43 +08:00
parent 26c2638146
commit c867f93e0a
6 changed files with 42 additions and 8 deletions

View File

@@ -110,7 +110,9 @@ const shouldRequired = computed(() => {
}
if (isString(currentRules.value)) {
return ['required', 'selectRequired'].includes(currentRules.value);
return ['mobileRequired', 'required', 'selectRequired'].includes(
currentRules.value,
);
}
let isOptional = currentRules?.value?.isOptional?.();

View File

@@ -68,6 +68,8 @@ export type FormActions = FormContext<GenericObject>;
export type CustomRenderType = (() => Component | string) | string;
export type FormSchemaRuleType =
| 'mobile'
| 'mobileRequired'
| 'required'
| 'selectRequired'
| null
@@ -428,6 +430,16 @@ export interface VbenFormAdapterOptions<
modelPropNameMap?: Partial<Record<T, string>>;
};
defineRules?: {
mobile?: (
value: any,
params: any,
ctx: Record<string, any>,
) => boolean | string;
mobileRequired?: (
value: any,
params: any,
ctx: Record<string, any>,
) => boolean | string;
required?: (
value: any,
params: any,

View File

@@ -7,7 +7,8 @@
"length": "{0} must be {1} characters long",
"alreadyExists": "{0} `{1}` already exists",
"startWith": "{0} must start with `{1}`",
"invalidURL": "Please input a valid URL"
"invalidURL": "Please input a valid URL",
"mobile": "Please input a valid {0}"
},
"actionTitle": {
"edit": "Modify {0}",

View File

@@ -7,7 +7,8 @@
"length": "{0}长度必须为{1}个字符",
"alreadyExists": "{0} `{1}` 已存在",
"startWith": "{0}必须以 {1} 开头",
"invalidURL": "请输入有效的链接"
"invalidURL": "请输入有效的链接",
"mobile": "请输入正确的{0}"
},
"actionTitle": {
"edit": "修改{0}",