mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-01-23 11:50:20 +08:00
表单field支持a.b.c的写法 (#1549)
* chore: table size放到settings * chore(TableAction): 操作确认框增加placement属性支持 * chore(Form): 表单field支持a.b.c嵌套写法 Co-authored-by: jinmao88 <50581550+jinmao88@users.noreply.github.com>
This commit is contained in:
parent
e097600003
commit
d09e998ae7
@ -2,7 +2,7 @@ import type { ComputedRef, Ref } from 'vue';
|
|||||||
import type { FormProps, FormSchema, FormActionType } from '../types/form';
|
import type { FormProps, FormSchema, FormActionType } from '../types/form';
|
||||||
import type { NamePath } from 'ant-design-vue/lib/form/interface';
|
import type { NamePath } from 'ant-design-vue/lib/form/interface';
|
||||||
import { unref, toRaw, nextTick } from 'vue';
|
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 { deepMerge } from '/@/utils';
|
||||||
import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper';
|
import { dateItemType, handleInputNumberValue, defaultValueComponents } from '../helper';
|
||||||
import { dateUtil } from '/@/utils/dateUtil';
|
import { dateUtil } from '/@/utils/dateUtil';
|
||||||
@ -55,6 +55,10 @@ export function useFormEvents({
|
|||||||
.map((item) => item.field)
|
.map((item) => item.field)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
|
// key 支持 a.b.c 的嵌套写法
|
||||||
|
const delimiter = '.';
|
||||||
|
const nestKeyArray = fields.filter((item) => item.indexOf(delimiter) >= 0);
|
||||||
|
|
||||||
const validKeys: string[] = [];
|
const validKeys: string[] = [];
|
||||||
Object.keys(values).forEach((key) => {
|
Object.keys(values).forEach((key) => {
|
||||||
const schema = unref(getSchema).find((item) => item.field === key);
|
const schema = unref(getSchema).find((item) => item.field === key);
|
||||||
@ -85,6 +89,21 @@ export function useFormEvents({
|
|||||||
formModel[key] = value;
|
formModel[key] = value;
|
||||||
}
|
}
|
||||||
validKeys.push(key);
|
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((_) => {});
|
validateFields(validKeys).catch((_) => {});
|
||||||
|
Loading…
Reference in New Issue
Block a user