Skip to content

Commit cb64e5d

Browse files
makeiteasezhangshujun
andauthored
From default value (#2913)
* feat: defaultValue赋值后不改动时间相关字段无法格式化问题 * feat: 更新处理方式 * feat: 去除未引用方法 --------- Co-authored-by: zhangshujun <[email protected]>
1 parent a4e70b9 commit cb64e5d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/components/Form/src/BasicForm.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,18 @@
117117
const getSchema = computed((): FormSchema[] => {
118118
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
119119
for (const schema of schemas) {
120-
const { defaultValue, component, isHandleDateDefaultValue = true } = schema;
120+
const { defaultValue, component, componentProps,isHandleDateDefaultValue = true } = schema;
121121
// handle date type
122122
if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) {
123+
const valueFormat =componentProps ? componentProps['valueFormat'] : null;
123124
if (!Array.isArray(defaultValue)) {
124-
schema.defaultValue = dateUtil(defaultValue);
125+
schema.defaultValue = valueFormat
126+
? dateUtil(defaultValue).format(valueFormat)
127+
: dateUtil(defaultValue);
125128
} else {
126129
const def: any[] = [];
127130
defaultValue.forEach((item) => {
128-
def.push(dateUtil(item));
131+
def.push(valueFormat ? dateUtil(item).format(valueFormat) : dateUtil(item));
129132
});
130133
schema.defaultValue = def;
131134
}

0 commit comments

Comments
 (0)