Skip to content

Commit

Permalink
fix(table): fix dateformat no work error
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Sep 16, 2022
1 parent 3491868 commit c30c107
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 228 deletions.
4 changes: 2 additions & 2 deletions packages/field/src/components/DigitRange/index.tsx
Expand Up @@ -87,7 +87,7 @@ const FieldDigitRange: ProFieldFC<FieldDigitRangeProps> = (

const dom = (
<Input.Group compact onBlur={handleGroupBlur}>
<InputNumber
<InputNumber<number>
{...fieldProps}
placeholder={Array.isArray(placeholderValue) ? placeholderValue[0] : placeholderValue}
id={id ?? `${id}-0`}
Expand All @@ -108,7 +108,7 @@ const FieldDigitRange: ProFieldFC<FieldDigitRangeProps> = (
placeholder={separator}
disabled
/>
<InputNumber
<InputNumber<number>
{...fieldProps}
placeholder={Array.isArray(placeholderValue) ? placeholderValue[1] : placeholderValue}
id={id ?? `${id}-1`}
Expand Down
18 changes: 8 additions & 10 deletions packages/form/src/layouts/DrawerForm/index.tsx
Expand Up @@ -197,10 +197,18 @@ function DrawerForm<T = Record<string, any>>({
? {
open: open,
onOpenChange: onVisibleChange,
afterOpenChange: (e: boolean) => {
if (!e) resetFields();
drawerProps?.afterOpenChange?.(e);
},
}
: {
visible: open,
onVisibleChange: onVisibleChange,
afterVisibleChange: (e: boolean) => {
if (!e) resetFields();
drawerProps?.afterOpenChange?.(e);
},
};

return (
Expand All @@ -217,16 +225,6 @@ function DrawerForm<T = Record<string, any>>({
drawerProps?.onClose?.(e);
resetFields();
}}
afterOpenChange={(e) => {
resetFields();
drawerProps?.afterOpenChange?.(e);
}}
//@ts-expect-error
afterVisibleChange={(e) => {
if (!e) resetFields();
//@ts-expect-error
drawerProps?.afterVisibleChange?.(e);
}}
footer={
rest.submitter !== false && (
<div
Expand Down
16 changes: 12 additions & 4 deletions packages/utils/src/conversionMomentValue/index.ts
Expand Up @@ -3,7 +3,6 @@ import dayjs from 'dayjs';
import get from 'rc-util/lib/utils/get';
import { isNil } from '../isNil';
import type { ProFieldValueType } from '../typing';

import quarterOfYear from 'dayjs/plugin/quarterOfYear';

dayjs.extend(quarterOfYear);
Expand Down Expand Up @@ -51,6 +50,13 @@ export function isPlainObject(o: { constructor: any }) {
return true;
}

/**
* 一个比较hack的moment判断工具
* @param value
* @returns
*/
const isMoment = (value: any) => !!value?._isAMomentObject;

/**
* 根据不同的格式转化 dayjs
*
Expand All @@ -66,7 +72,7 @@ export const convertMoment = (
if (!dateFormatter) {
return value;
}
if (dayjs.isDayjs(value)) {
if (dayjs.isDayjs(value) || isMoment(value)) {
if (dateFormatter === 'number') {
return value.valueOf();
}
Expand Down Expand Up @@ -133,15 +139,17 @@ export const conversionMomentValue = <T extends {} = any>(
// 不是数组
!Array.isArray(itemValue) &&
// 不是 dayjs
!dayjs.isDayjs(itemValue)
!dayjs.isDayjs(itemValue) &&
// 不是 moment
!isMoment(itemValue)
) {
tmpValue[key] = conversionMomentValue(itemValue, dateFormatter, valueTypeMap, omitNil, [key]);
return;
}
// 处理 FormList 的 value
if (Array.isArray(itemValue)) {
tmpValue[key] = itemValue.map((arrayValue, index) => {
if (dayjs.isDayjs(arrayValue)) {
if (dayjs.isDayjs(arrayValue) || isMoment(itemValue)) {
return convertMoment(arrayValue, dateFormat || dateFormatter, valueType);
}
return conversionMomentValue(arrayValue, dateFormatter, valueTypeMap, omitNil, [
Expand Down
12 changes: 11 additions & 1 deletion packages/utils/src/parseValueToMoment/index.ts
Expand Up @@ -3,11 +3,21 @@ import { isNil } from '../isNil';

type DateValue = dayjs.Dayjs | dayjs.Dayjs[] | string | string[] | number | number[];

/**
* 一个比较hack的moment判断工具
* @param value
* @returns
*/
const isMoment = (value: any) => !!value?._isAMomentObject;

export const parseValueToDay = (
value: DateValue,
formatter?: string,
): dayjs.Dayjs | dayjs.Dayjs[] | null | undefined => {
if (isNil(value) || dayjs.isDayjs(value)) {
if (isNil(value) || dayjs.isDayjs(value) || isMoment(value)) {
if (isMoment(value)) {
return dayjs(value as dayjs.Dayjs);
}
return value as dayjs.Dayjs | null | undefined;
}
if (Array.isArray(value)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/layout/__snapshots__/demo.test.ts.snap
Expand Up @@ -10999,6 +10999,12 @@ exports[`layout demos 📸 renders ./packages/layout/src/demos/base.tsx correctl
>
一一级列表页面
</span>
<span
class="ant-page-header-heading-sub-title "
title="简单的描述"
>
简单的描述
</span>
</div>
<span
class="ant-page-header-heading-extra "
Expand Down
21 changes: 21 additions & 0 deletions tests/table/__snapshots__/demo.test.ts.snap
Expand Up @@ -35985,6 +35985,27 @@ exports[`table demos 📸 renders ./packages/table/src/demos/lightfilter.tsx cor
</div>
</div>
</div>
<div
class="ant-space-item"
style="margin-right: 16px;"
>
<div
class="ant-space ant-space-horizontal ant-space-align-center"
>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-default"
type="button"
>
<span>
查看日志
</span>
</button>
</div>
</div>
</div>
<div
class="ant-space-item"
>
Expand Down

0 comments on commit c30c107

Please sign in to comment.