mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-24 12:20:18 +08:00
feat(from): add required in schema
This commit is contained in:
parent
b6d5e5c96f
commit
2859067621
@ -102,13 +102,19 @@ export default defineComponent({
|
|||||||
rulesMessageJoinLabel,
|
rulesMessageJoinLabel,
|
||||||
label,
|
label,
|
||||||
dynamicRules,
|
dynamicRules,
|
||||||
|
required,
|
||||||
} = props.schema;
|
} = props.schema;
|
||||||
|
|
||||||
if (isFunction(dynamicRules)) {
|
if (isFunction(dynamicRules)) {
|
||||||
return dynamicRules(unref(getValuesRef));
|
return dynamicRules(unref(getValuesRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
const rules: ValidationRule[] = cloneDeep(defRules);
|
let rules: ValidationRule[] = cloneDeep(defRules);
|
||||||
|
|
||||||
|
if ((!rules || rules.length === 0) && required) {
|
||||||
|
rules = [{ required }];
|
||||||
|
}
|
||||||
|
|
||||||
const requiredRuleIndex: number = rules.findIndex(
|
const requiredRuleIndex: number = rules.findIndex(
|
||||||
(rule) => Reflect.has(rule, 'required') && !Reflect.has(rule, 'validator')
|
(rule) => Reflect.has(rule, 'required') && !Reflect.has(rule, 'validator')
|
||||||
);
|
);
|
||||||
|
@ -112,6 +112,8 @@ export interface FormSchema {
|
|||||||
component: ComponentType;
|
component: ComponentType;
|
||||||
// 组件参数
|
// 组件参数
|
||||||
componentProps?: any;
|
componentProps?: any;
|
||||||
|
// 必填
|
||||||
|
required?: boolean;
|
||||||
|
|
||||||
// 校验规则
|
// 校验规则
|
||||||
rules?: RuleObject[];
|
rules?: RuleObject[];
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
colProps: {
|
colProps: {
|
||||||
span: 8,
|
span: 8,
|
||||||
},
|
},
|
||||||
rules: [{ required: true }],
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'field2',
|
field: 'field2',
|
||||||
@ -33,7 +33,7 @@
|
|||||||
colProps: {
|
colProps: {
|
||||||
span: 8,
|
span: 8,
|
||||||
},
|
},
|
||||||
rules: [{ required: true }],
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'field3',
|
field: 'field3',
|
||||||
@ -42,7 +42,7 @@
|
|||||||
colProps: {
|
colProps: {
|
||||||
span: 8,
|
span: 8,
|
||||||
},
|
},
|
||||||
rules: [{ required: true }],
|
required: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'field4',
|
field: 'field4',
|
||||||
@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
rules: [{ required: true }],
|
rules: [{ required: true, message: '请输入aa' }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'field5',
|
field: 'field5',
|
||||||
|
Loading…
Reference in New Issue
Block a user