未验证 提交 d09e998a 编写于 作者: J Joyboo 提交者: GitHub

表单field支持a.b.c的写法 (#1549)

* chore: table size放到settings

* chore(TableAction): 操作确认框增加placement属性支持

* chore(Form): 表单field支持a.b.c嵌套写法
Co-authored-by: Njinmao88 <50581550+jinmao88@users.noreply.github.com>
上级 e0976000
......@@ -2,7 +2,7 @@ import type { ComputedRef, Ref } from 'vue';
import type { FormProps, FormSchema, FormActionType } from '../types/form';
import type { NamePath } from 'ant-design-vue/lib/form/interface';
import { unref, toRaw, nextTick } from 'vue';
import { isArray, isFunction, isNullOrUnDef, isObject, isString } from '/@/utils/is';
import { isArray, isFunction, isObject, isString, isDef } from '/@/utils/is';
import { deepMerge } from '/@/utils';
import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper';
import { dateUtil } from '/@/utils/dateUtil';
......@@ -55,6 +55,10 @@ export function useFormEvents({
.map((item) => item.field)
.filter(Boolean);
// key 支持 a.b.c 的嵌套写法
const delimiter = '.';
const nestKeyArray = fields.filter((item) => item.indexOf(delimiter) >= 0);
const validKeys: string[] = [];
Object.keys(values).forEach((key) => {
const schema = unref(getSchema).find((item) => item.field === key);
......@@ -85,6 +89,21 @@ export function useFormEvents({
formModel[key] = value;
}
validKeys.push(key);
} else {
nestKeyArray.forEach((nestKey: string) => {
try {
const value = eval('values' + delimiter + nestKey);
if (isDef(value)) {
formModel[nestKey] = value;
validKeys.push(nestKey);
}
} catch (e) {
// key not exist
if (isDef(defaultValueRef.value[nestKey])) {
formModel[nestKey] = defaultValueRef.value[nestKey];
}
}
});
}
});
validateFields(validKeys).catch((_) => {});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册