| | |
| | | value = moment(value, format) |
| | | } |
| | | |
| | | let presets = null |
| | | if (mode === 'daterange' && format === 'YYYY-MM-DD' && sessionStorage.getItem('lang') === 'zh-CN') { |
| | | presets = { |
| | | '今天': [moment(), moment()], |
| | | '当月': [moment().startOf('month'), moment().endOf('month')], |
| | | '上月': [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')], |
| | | } |
| | | } |
| | | |
| | | this.state = { |
| | | value, |
| | | mode, |
| | | precision: config.precision || 'day', |
| | | format |
| | | format, |
| | | presets |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { value, mode, format, precision } = this.state |
| | | const { value, mode, format, precision, presets } = this.state |
| | | |
| | | if (mode === 'date') { |
| | | return <DatePicker dropdownClassName={'mk-date-picker ' + precision} value={value} showTime={format !== 'YYYY-MM-DD'} format={format} onChange={this.onChange}/> |
| | |
| | | } else if (mode === 'week') { |
| | | return <WeekPicker value={value} onChange={this.onChange}/> |
| | | } else if (mode === 'daterange') { |
| | | return <RangePicker ranges={format === 'YYYY-MM-DD' ? { |
| | | '今天': [moment(), moment()], |
| | | '当月': [moment().startOf('month'), moment().endOf('month')], |
| | | '上月': [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')], |
| | | } : null} dropdownClassName={'mk-date-picker ' + precision} placeholder={['开始日期', '结束日期']} showTime={format !== 'YYYY-MM-DD'} format={format} value={value} onChange={this.onChange}/> |
| | | return <RangePicker ranges={presets} dropdownClassName={'mk-date-picker ' + precision} showTime={format !== 'YYYY-MM-DD'} format={format} value={value} onChange={this.onChange}/> |
| | | } |
| | | } |
| | | } |