From bc499744c0ec9b8b1030fe0b398817ba36d888aa Mon Sep 17 00:00:00 2001 From: sevth <50509571+tt-sevth@users.noreply.github.com> Date: Tue, 25 Oct 2022 08:48:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(Form):=20=E6=94=AF=E6=8C=81`filedMapToTime?= =?UTF-8?q?`=E5=88=86=E5=88=AB=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=97=B6?= =?UTF-8?q?=E9=97=B4,=E6=94=AF=E6=8C=81=E9=85=8D=E7=BD=AE=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=9B=B8=E5=85=B3=E7=BB=84=E4=BB=B6=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=E5=A4=84=E7=90=86=E5=BC=80=E5=85=B3,=E5=BD=93?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=85=8D=E7=BD=AE`valueFormat`=E6=97=B6,?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC=E7=BB=91=E5=AE=9A=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E6=98=AF`moment`=E5=AF=B9=E8=B1=A1,=E6=AD=A4=E6=97=B6=E5=BA=94?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E9=BB=98=E8=AE=A4=E5=80=BC=E7=9A=84=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=A4=84=E7=90=86=20(#2305)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复使用 extendSlots 时插槽参数未传递的问题。 * feat(Form): `fieldMapToTime`additional time formatting support separately. * fix(Form): Add `isHandleDateDefaultValue` property. Co-authored-by: sevth --- src/components/Form/src/BasicForm.vue | 4 ++-- src/components/Form/src/hooks/useFormValues.ts | 6 ++++-- src/components/Form/src/types/form.ts | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/Form/src/BasicForm.vue b/src/components/Form/src/BasicForm.vue index 8e4b6292..d512eb36 100644 --- a/src/components/Form/src/BasicForm.vue +++ b/src/components/Form/src/BasicForm.vue @@ -118,9 +118,9 @@ const getSchema = computed((): FormSchema[] => { const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); for (const schema of schemas) { - const { defaultValue, component } = schema; + const { defaultValue, component, isHandleDateDefaultValue = true } = schema; // handle date type - if (defaultValue && dateItemType.includes(component)) { + if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) { if (!Array.isArray(defaultValue)) { schema.defaultValue = dateUtil(defaultValue); } else { diff --git a/src/components/Form/src/hooks/useFormValues.ts b/src/components/Form/src/hooks/useFormValues.ts index de30db99..a4865993 100644 --- a/src/components/Form/src/hooks/useFormValues.ts +++ b/src/components/Form/src/hooks/useFormValues.ts @@ -108,8 +108,10 @@ export function useFormValues({ const [startTime, endTime]: string[] = values[field]; - values[startTimeKey] = dateUtil(startTime).format(format); - values[endTimeKey] = dateUtil(endTime).format(format); + const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format]; + + values[startTimeKey] = dateUtil(startTime).format(startTimeFormat); + values[endTimeKey] = dateUtil(endTime).format(endTimeFormat); Reflect.deleteProperty(values, field); } diff --git a/src/components/Form/src/types/form.ts b/src/components/Form/src/types/form.ts index 31e32603..f54b1894 100644 --- a/src/components/Form/src/types/form.ts +++ b/src/components/Form/src/types/form.ts @@ -7,7 +7,7 @@ import type { TableActionType } from '/@/components/Table/src/types/table'; import type { CSSProperties } from 'vue'; import type { RowProps } from 'ant-design-vue/lib/grid/Row'; -export type FieldMapToTime = [string, [string, string], string?][]; +export type FieldMapToTime = [string, [string, string], (string | [string, string])?][]; export type Rule = RuleObject & { trigger?: 'blur' | 'change' | ['change', 'blur']; @@ -175,6 +175,10 @@ export interface FormSchema { // 默认值 defaultValue?: any; + + // 是否自动处理与时间相关组件的默认值 + isHandleDateDefaultValue?: boolean; + isAdvanced?: boolean; // Matching details components