Commit bc499744c0ec9b8b1030fe0b398817ba36d888aa

Authored by sevth
Committed by GitHub
1 parent c8b16949

feat(Form): 支持`filedMapToTime`分别格式化时间,支持配置时间相关组件默认值处理开关,当组件配置`valueFormat`时,默认值绑…

…定不再是`moment`对象,此时应关闭默认值的转换处理 (#2305)

* fix: 修复使用 extendSlots 时插槽参数未传递的问题。

* feat(Form): `fieldMapToTime`additional time formatting support separately.

* fix(Form): Add `isHandleDateDefaultValue` property.

Co-authored-by: sevth <pengqiang@vastweb>
src/components/Form/src/BasicForm.vue
@@ -118,9 +118,9 @@ @@ -118,9 +118,9 @@
118 const getSchema = computed((): FormSchema[] => { 118 const getSchema = computed((): FormSchema[] => {
119 const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); 119 const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
120 for (const schema of schemas) { 120 for (const schema of schemas) {
121 - const { defaultValue, component } = schema; 121 + const { defaultValue, component, isHandleDateDefaultValue = true } = schema;
122 // handle date type 122 // handle date type
123 - if (defaultValue && dateItemType.includes(component)) { 123 + if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) {
124 if (!Array.isArray(defaultValue)) { 124 if (!Array.isArray(defaultValue)) {
125 schema.defaultValue = dateUtil(defaultValue); 125 schema.defaultValue = dateUtil(defaultValue);
126 } else { 126 } else {
src/components/Form/src/hooks/useFormValues.ts
@@ -108,8 +108,10 @@ export function useFormValues({ @@ -108,8 +108,10 @@ export function useFormValues({
108 108
109 const [startTime, endTime]: string[] = values[field]; 109 const [startTime, endTime]: string[] = values[field];
110 110
111 - values[startTimeKey] = dateUtil(startTime).format(format);  
112 - values[endTimeKey] = dateUtil(endTime).format(format); 111 + const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format];
  112 +
  113 + values[startTimeKey] = dateUtil(startTime).format(startTimeFormat);
  114 + values[endTimeKey] = dateUtil(endTime).format(endTimeFormat);
113 Reflect.deleteProperty(values, field); 115 Reflect.deleteProperty(values, field);
114 } 116 }
115 117
src/components/Form/src/types/form.ts
@@ -7,7 +7,7 @@ import type { TableActionType } from &#39;/@/components/Table/src/types/table&#39;; @@ -7,7 +7,7 @@ import type { TableActionType } from &#39;/@/components/Table/src/types/table&#39;;
7 import type { CSSProperties } from 'vue'; 7 import type { CSSProperties } from 'vue';
8 import type { RowProps } from 'ant-design-vue/lib/grid/Row'; 8 import type { RowProps } from 'ant-design-vue/lib/grid/Row';
9 9
10 -export type FieldMapToTime = [string, [string, string], string?][]; 10 +export type FieldMapToTime = [string, [string, string], (string | [string, string])?][];
11 11
12 export type Rule = RuleObject & { 12 export type Rule = RuleObject & {
13 trigger?: 'blur' | 'change' | ['change', 'blur']; 13 trigger?: 'blur' | 'change' | ['change', 'blur'];
@@ -175,6 +175,10 @@ export interface FormSchema { @@ -175,6 +175,10 @@ export interface FormSchema {
175 175
176 // 默认值 176 // 默认值
177 defaultValue?: any; 177 defaultValue?: any;
  178 +
  179 + // 是否自动处理与时间相关组件的默认值
  180 + isHandleDateDefaultValue?: boolean;
  181 +
178 isAdvanced?: boolean; 182 isAdvanced?: boolean;
179 183
180 // Matching details components 184 // Matching details components