Skip to content

Commit

Permalink
fix: 修复BasicForm使用componentProps函数返回valueFormat时DatePicker无法正确格式化的问题 (#…
Browse files Browse the repository at this point in the history
…3357)

* 修复BasicForm使用componentProps函数返回valueFormat时DatePicker无法正确格式化的问题

* chore: resolve prettier error

---------

Co-authored-by: invalid w <wangjuesix@gmail.com>
  • Loading branch information
SunsetSail and wangjue666 authored Nov 29, 2023
1 parent b0e8154 commit beee351
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import { basicProps } from './props';
import { useDesign } from '@/hooks/web/useDesign';
import { cloneDeep } from 'lodash-es';
import { TableActionType } from '@/components/Table';
defineOptions({ name: 'BasicForm' });
Expand Down Expand Up @@ -124,15 +125,30 @@
const getSchema = computed((): FormSchema[] => {
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
for (const schema of schemas) {
const { defaultValue, component, componentProps, isHandleDateDefaultValue = true } = schema;
const {
defaultValue,
component,
componentProps = {},
isHandleDateDefaultValue = true,
} = schema;
// handle date type
if (
isHandleDateDefaultValue &&
defaultValue &&
component &&
dateItemType.includes(component)
) {
const valueFormat = componentProps ? componentProps['valueFormat'] : null;
const opt = {
schema,
tableAction: props.tableAction ?? ({} as TableActionType),
formModel,
formActionType: {} as FormActionType,
};
const valueFormat = componentProps
? typeof componentProps === 'function'
? componentProps(opt)['valueFormat']
: componentProps['valueFormat']
: null;
if (!Array.isArray(defaultValue)) {
schema.defaultValue = valueFormat
? dateUtil(defaultValue).format(valueFormat)
Expand Down

0 comments on commit beee351

Please sign in to comment.