Commit f38eec07 authored by 前端-许佳敏's avatar 前端-许佳敏

新增下拉选择时间组件

parent 8e1aba35
import React, { useRef, useEffect, useMemo } from 'react'
import { Select } from 'antd';
import moment from 'moment'
export enum DATE_SELECT_TYPE {
TODAY,
WITHIN_WEEK,
WITHIN_MONTH,
WITHIN_THREE_MONTH,
WITHIN_SIX_MONTH,
WITHIN_YEAR,
A_YEAR_AGO
}
const getPrevTime = (num, flag) => {
return moment().subtract(num, flag).valueOf()
}
const DateSelect = (props) => {
const { value = [], mutators } = props
const todayStartTime = moment().startOf('day').format('x')
const nowTime = moment().format('x').valueOf()
const dateMemo = useMemo(() => [
{ label: '今天', value: `${todayStartTime},${nowTime}`},
{ label: '一周内', value: `${getPrevTime(1, 'week')},${nowTime}`},
{ label: '一月内', value: `${getPrevTime(1, 'month')},${nowTime}`},
{ label: '三月内', value: `${getPrevTime(3, 'month')},${nowTime}`},
{ label: '六月内', value: `${getPrevTime(6, 'month')},${nowTime}`},
{ label: '一年内', value: `${getPrevTime(1, 'year')},${nowTime}`},
{ label: '一年前', value: `0,${getPrevTime(1, 'year')}`},
], [])
const handleChange = (e) => {
mutators.change(e.split(','))
}
const { placeholder, dataSource = dateMemo } = props.props["x-component-props"] || {}
return (
<Select
style={{minWidth: 160}}
placeholder={placeholder}
onChange={handleChange}
value={value.join()}
options={dataSource}
/>
)
}
DateSelect.defaultProps = {}
DateSelect.isFieldComponent = true;
export default DateSelect
\ No newline at end of file
......@@ -23,6 +23,7 @@ import SearchSelect from './components/SearchSelect';
import TableTagList from './components/TableTagList';
import './index.less'
import { Checkbox } from '@formily/antd-components';
import DateSelect from './components/DateSelect';
export interface NiceFormProps extends IAntdSchemaFormProps {}
......@@ -88,6 +89,7 @@ export const componentExport = {
SearchSelect,
DateRangePicker: DatePicker.RangePicker,
TableTagList,
DateSelect
}
const NiceForm: React.FC<NiceFormProps> = props => {
const { children, components, ...reset } = props;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment