Commit cb64e5d24c3fcae36773b7517cb965ebf0cd241e
Committed by
GitHub
1 parent
a4e70b9e
From default value (#2913)
* feat: defaultValue赋值后不改动时间相关字段无法格式化问题 * feat: 更新处理方式 * feat: 去除未引用方法 --------- Co-authored-by: zhangshujun <zhangsj01@51cto.com>
Showing
1 changed file
with
6 additions
and
3 deletions
src/components/Form/src/BasicForm.vue
... | ... | @@ -117,15 +117,18 @@ |
117 | 117 | const getSchema = computed((): FormSchema[] => { |
118 | 118 | const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); |
119 | 119 | for (const schema of schemas) { |
120 | - const { defaultValue, component, isHandleDateDefaultValue = true } = schema; | |
120 | + const { defaultValue, component, componentProps,isHandleDateDefaultValue = true } = schema; | |
121 | 121 | // handle date type |
122 | 122 | if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) { |
123 | + const valueFormat =componentProps ? componentProps['valueFormat'] : null; | |
123 | 124 | if (!Array.isArray(defaultValue)) { |
124 | - schema.defaultValue = dateUtil(defaultValue); | |
125 | + schema.defaultValue = valueFormat | |
126 | + ? dateUtil(defaultValue).format(valueFormat) | |
127 | + : dateUtil(defaultValue); | |
125 | 128 | } else { |
126 | 129 | const def: any[] = []; |
127 | 130 | defaultValue.forEach((item) => { |
128 | - def.push(dateUtil(item)); | |
131 | + def.push(valueFormat ? dateUtil(item).format(valueFormat) : dateUtil(item)); | |
129 | 132 | }); |
130 | 133 | schema.defaultValue = def; |
131 | 134 | } | ... | ... |