From d09e998ae78d2fbe3d0537c6fca932a2ac484629 Mon Sep 17 00:00:00 2001 From: Joyboo Date: Sat, 30 Apr 2022 19:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E5=8D=95field=E6=94=AF=E6=8C=81a.b.c?= =?UTF-8?q?=E7=9A=84=E5=86=99=E6=B3=95=20(#1549)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: table size放到settings * chore(TableAction): 操作确认框增加placement属性支持 * chore(Form): 表单field支持a.b.c嵌套写法 Co-authored-by: jinmao88 <50581550+jinmao88@users.noreply.github.com> --- .../Form/src/hooks/useFormEvents.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/Form/src/hooks/useFormEvents.ts b/src/components/Form/src/hooks/useFormEvents.ts index ac10f32a3..86946b445 100644 --- a/src/components/Form/src/hooks/useFormEvents.ts +++ b/src/components/Form/src/hooks/useFormEvents.ts @@ -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((_) => {});