You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
3.8 KiB
JavaScript
63 lines
3.8 KiB
JavaScript
3 years ago
|
import React, {Component} from 'react';
|
||
|
import {Col, DatePicker, Row} from 'antd';
|
||
|
import {observer} from 'mobx-react';
|
||
|
import * as config from "../config";
|
||
|
import moment from "moment";
|
||
|
import {stores_Context} from "../config";
|
||
|
|
||
|
//用于日期选择,计算上一时间段、同比时间等
|
||
|
class DatePickerCharts extends Component {
|
||
|
static contextType = stores_Context;
|
||
|
|
||
|
constructor(props) {
|
||
|
super(props);
|
||
|
}
|
||
|
|
||
|
|
||
|
render() {
|
||
|
const {date_picker_store} = this.context;
|
||
|
return (
|
||
|
<div>
|
||
|
<Row>
|
||
|
<Col span={24}>
|
||
|
<DatePicker.RangePicker format={config.DATE_FORMAT}
|
||
|
allowClear={false}
|
||
|
defaultValue={[date_picker_store.start_date, date_picker_store.end_date]}
|
||
|
onChange={date_picker_store.onChange_dataPicker}
|
||
|
ranges={{
|
||
|
'本周': [moment().startOf('week'), moment().endOf('week')],
|
||
|
'上周': [moment().startOf('week').subtract(7, 'days'), moment().endOf('week').subtract(7, 'days')],
|
||
|
'本月': [moment().startOf('month'), moment().endOf('month')],
|
||
|
'近30天': [moment().subtract(30, 'days'), moment()],
|
||
|
'上个月': [moment().startOf('month').subtract(1, 'month'), moment().endOf('month').subtract(1, 'month')],
|
||
|
'近三个月': [moment().startOf('month').subtract(2, 'month'), moment().endOf('month')],
|
||
|
'今年': [moment().startOf('year').subtract(1, 'month'), moment().endOf('year').subtract(1, 'month')],
|
||
|
'去年': [moment().startOf('year').subtract(1, 'year').subtract(1, 'month'), moment().endOf('year').subtract(1, 'year').subtract(1, 'month')],
|
||
|
}}
|
||
|
/>
|
||
|
</Col>
|
||
|
<Col span={24}>
|
||
|
<DatePicker.RangePicker bordered={false} format={config.DATE_FORMAT}
|
||
|
defaultValue={[date_picker_store.start_date_cp, date_picker_store.end_date_cp]}
|
||
|
placeholder={['对比 Start date', 'End date']}
|
||
|
onChange={date_picker_store.onChange_dataPicker_cp}
|
||
|
ranges={{
|
||
|
'上一时间段': date_picker_store.previous_date(),
|
||
|
'去年同期': date_picker_store.previous_year(),
|
||
|
'上周': [moment().startOf('week').subtract(7, 'days'), moment().endOf('week').subtract(7, 'days')],
|
||
|
'上个月': [moment().startOf('month').subtract(1, 'month'), moment().endOf('month').subtract(1, 'month')],
|
||
|
'前三个月': [moment().startOf('month').subtract(5, 'month'), moment().endOf('month').subtract(3, 'month')],
|
||
|
'去年': [moment().startOf('year').subtract(1, 'year').subtract(1, 'month'), moment().endOf('year').subtract(1, 'year').subtract(1, 'month')]
|
||
|
}}
|
||
|
/>
|
||
|
</Col>
|
||
|
</Row>
|
||
|
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default observer(DatePickerCharts);
|
||
|
|