From beee35173b84dfb4c27bcd403df689e102379303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=BE=E9=BC=A0?= <52393675+SunsetSail@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:56:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DBasicForm=E4=BD=BF?= =?UTF-8?q?=E7=94=A8componentProps=E5=87=BD=E6=95=B0=E8=BF=94=E5=9B=9Evalu?= =?UTF-8?q?eFormat=E6=97=B6DatePicker=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E7=9A=84=E9=97=AE=E9=A2=98=20=20(#3?= =?UTF-8?q?357)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复BasicForm使用componentProps函数返回valueFormat时DatePicker无法正确格式化的问题 * chore: resolve prettier error --------- Co-authored-by: invalid w --- src/components/Form/src/BasicForm.vue | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index ea340b94..97c4cf3b 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -63,6 +63,7 @@ import { basicProps } from './props'; import { useDesign } from '@/hooks/web/useDesign'; import { cloneDeep } from 'lodash-es'; + import { TableActionType } from '@/components/Table'; defineOptions({ name: 'BasicForm' }); @@ -124,7 +125,12 @@ const getSchema = computed((): FormSchema[] => { const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); for (const schema of schemas) { - const { defaultValue, component, componentProps, isHandleDateDefaultValue = true } = schema; + const { + defaultValue, + component, + componentProps = {}, + isHandleDateDefaultValue = true, + } = schema; // handle date type if ( isHandleDateDefaultValue && @@ -132,7 +138,17 @@ component && dateItemType.includes(component) ) { - const valueFormat = componentProps ? componentProps['valueFormat'] : null; + const opt = { + schema, + tableAction: props.tableAction ?? ({} as TableActionType), + formModel, + formActionType: {} as FormActionType, + }; + const valueFormat = componentProps + ? typeof componentProps === 'function' + ? componentProps(opt)['valueFormat'] + : componentProps['valueFormat'] + : null; if (!Array.isArray(defaultValue)) { schema.defaultValue = valueFormat ? dateUtil(defaultValue).format(valueFormat)