Commit cb64e5d24c3fcae36773b7517cb965ebf0cd241e

Authored by zhangshujun
Committed by GitHub
1 parent a4e70b9e

From default value (#2913)

* feat: defaultValue赋值后不改动时间相关字段无法格式化问题

* feat: 更新处理方式

* feat: 去除未引用方法

---------

Co-authored-by: zhangshujun <zhangsj01@51cto.com>
src/components/Form/src/BasicForm.vue
@@ -117,15 +117,18 @@ @@ -117,15 +117,18 @@
117 const getSchema = computed((): FormSchema[] => { 117 const getSchema = computed((): FormSchema[] => {
118 const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); 118 const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
119 for (const schema of schemas) { 119 for (const schema of schemas) {
120 - const { defaultValue, component, isHandleDateDefaultValue = true } = schema; 120 + const { defaultValue, component, componentProps,isHandleDateDefaultValue = true } = schema;
121 // handle date type 121 // handle date type
122 if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) { 122 if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) {
  123 + const valueFormat =componentProps ? componentProps['valueFormat'] : null;
123 if (!Array.isArray(defaultValue)) { 124 if (!Array.isArray(defaultValue)) {
124 - schema.defaultValue = dateUtil(defaultValue); 125 + schema.defaultValue = valueFormat
  126 + ? dateUtil(defaultValue).format(valueFormat)
  127 + : dateUtil(defaultValue);
125 } else { 128 } else {
126 const def: any[] = []; 129 const def: any[] = [];
127 defaultValue.forEach((item) => { 130 defaultValue.forEach((item) => {
128 - def.push(dateUtil(item)); 131 + def.push(valueFormat ? dateUtil(item).format(valueFormat) : dateUtil(item));
129 }); 132 });
130 schema.defaultValue = def; 133 schema.defaultValue = def;
131 } 134 }