feat: 改造setValues方法
This commit is contained in:
parent
1d6047c70b
commit
600bfc7aaf
@ -17,6 +17,8 @@ import {
|
||||
StateHandler,
|
||||
} from '@vben-core/shared/utils';
|
||||
|
||||
import { objectPick } from '@vueuse/core';
|
||||
|
||||
const merge = createMerge((originObj, key, updates) => {
|
||||
if (Array.isArray(originObj[key]) && Array.isArray(updates)) {
|
||||
originObj[key] = updates;
|
||||
@ -182,12 +184,25 @@ export class FormApi {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表单值
|
||||
* @param fields record
|
||||
* @param filterFields 过滤不在schema中定义的字段 默认为true
|
||||
* @param shouldValidate
|
||||
*/
|
||||
async setValues(
|
||||
fields: Record<string, any>,
|
||||
filterFields: boolean = true,
|
||||
shouldValidate: boolean = false,
|
||||
) {
|
||||
const form = await this.getForm();
|
||||
if (!filterFields) {
|
||||
form.setValues(fields, shouldValidate);
|
||||
return;
|
||||
}
|
||||
const fieldNames = this.state?.schema?.map((item) => item.fieldName) ?? [];
|
||||
const filteredFields = objectPick(fields, fieldNames);
|
||||
form.setValues(filteredFields, shouldValidate);
|
||||
}
|
||||
|
||||
async submitForm(e?: Event) {
|
||||
|
Loading…
Reference in New Issue
Block a user