From 6fd499f03a0c36a7cd0911108bc70330577d3291 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 29 Dec 2020 15:12:49 +0800 Subject: [PATCH] fix: date/time filter value format --- .../components/form.fields/filter/index.tsx | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/app/src/components/form.fields/filter/index.tsx b/packages/app/src/components/form.fields/filter/index.tsx index adf2575af8..e5ef09753b 100644 --- a/packages/app/src/components/form.fields/filter/index.tsx +++ b/packages/app/src/components/form.fields/filter/index.tsx @@ -142,7 +142,7 @@ const OP_MAP = { {label: '大于等于', value: 'gte'}, {label: '小于', value: 'lt'}, {label: '小于等于', value: 'lte'}, - {label: '介于', value: 'between'}, + // {label: '介于', value: 'between'}, {label: '非空', value: '$notNull'}, {label: '为空', value: '$null'}, ], @@ -177,7 +177,7 @@ const OP_MAP = { {label: '大于等于', value: 'gte'}, {label: '小于', value: 'lt'}, {label: '小于等于', value: 'lte'}, - {label: '介于', value: 'between'}, + // {label: '介于', value: 'between'}, {label: '非空', value: '$notNull'}, {label: '为空', value: '$null'}, // {label: '是今天', value: 'now'}, @@ -191,7 +191,7 @@ const OP_MAP = { {label: '大于等于', value: 'gte'}, {label: '小于', value: 'lt'}, {label: '小于等于', value: 'lte'}, - {label: '介于', value: 'between'}, + // {label: '介于', value: 'between'}, {label: '非空', value: '$notNull'}, {label: '为空', value: '$null'}, // {label: '是今天', value: 'now'}, @@ -250,23 +250,35 @@ const controls = { radio: OptionControl, checkboxes: OptionControl, multipleSelect: OptionControl, - time: TimePicker, + time: TimeControl, date: DateControl, }; function DateControl(props: any) { - const { value, onChange, ...restProps } = props; - const m = moment(value, 'YYYY-MM-DD HH:mm:ss'); + const { field, value, onChange, ...restProps } = props; + let format = field.dateFormat; + if (field.showTime) { + format += ` ${field.timeFormat}`; + } + const m = moment(value, format); return ( - { - onChange(value ? value.format('YYYY-MM-DD HH:mm:ss') : null) - console.log(value.format('YYYY-MM-DD HH:mm:ss')); + { + onChange(value ? value.format(field.showTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD') : null) }}/> ); } function TimeControl(props: any) { - return + const { field, value, onChange, ...restProps } = props; + let format = field.timeFormat; + const m = moment(value, format); + return { + onChange(value ? value.format('HH:mm:ss') : null) + }} + /> } function OptionControl(props) { @@ -347,7 +359,7 @@ export function FilterItem(props: FilterItemProps) { {field.title} ))} - - { + { onChange({...dataSource, value: value}); }} style={{ width: 180 }}