公用日历插件
parent
8e40919f18
commit
d8f93bb428
@ -0,0 +1,62 @@
|
|||||||
|
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);
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
import {makeAutoObservable} from "mobx"
|
||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
class DatePickerStore {
|
||||||
|
|
||||||
|
constructor(rootStore) {
|
||||||
|
this.rootStore = rootStore;
|
||||||
|
makeAutoObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
start_date = moment().startOf('week').subtract(7, 'days');
|
||||||
|
end_date = moment().endOf('week').subtract(7, 'days');
|
||||||
|
start_date_cp = false;
|
||||||
|
end_date_cp = false;
|
||||||
|
|
||||||
|
onChange_dataPicker = (dates) => {
|
||||||
|
this.start_date = dates[0];
|
||||||
|
this.end_date = dates[1];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange_dataPicker_cp = (dates) => {
|
||||||
|
if (dates) {
|
||||||
|
this.start_date_cp = dates[0];
|
||||||
|
this.end_date_cp = dates[1];
|
||||||
|
} else {
|
||||||
|
this.start_date_cp = false;
|
||||||
|
this.end_date_cp = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//计算上一个时间段
|
||||||
|
previous_date() {
|
||||||
|
return [moment(this.start_date).subtract(this.end_date.diff(this.start_date, 'days') + 1, 'days'), moment(this.start_date).subtract(1, 'days')];
|
||||||
|
}
|
||||||
|
|
||||||
|
//去年同期
|
||||||
|
previous_year() {
|
||||||
|
return [moment(this.start_date).subtract(1, 'year'), moment(this.end_date).subtract(1, 'year')];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default DatePickerStore;
|
||||||
|
|
@ -1,19 +1,23 @@
|
|||||||
import {makeAutoObservable} from "mobx"
|
import {makeAutoObservable} from "mobx"
|
||||||
import OrdersStore from "./OrdersStore";
|
import OrdersStore from "./OrdersStore";
|
||||||
import DashboardStore from "./DashboardStore";
|
import DashboardStore from "./DashboardStore";
|
||||||
import moment from "moment";
|
import DatePickerStore from "./DatePickerStore";
|
||||||
|
|
||||||
|
|
||||||
class Index {
|
class Index {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.dashboard_store = new DashboardStore(this);
|
this.dashboard_store = new DashboardStore(this);
|
||||||
this.orders_store = new OrdersStore(this);
|
this.orders_store = new OrdersStore(this);
|
||||||
makeAutoObservable(this)
|
this.date_picker_store = new DatePickerStore(this);
|
||||||
|
makeAutoObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
goBack() {
|
goBack() {
|
||||||
this.history.goBack();
|
this.history.goBack();
|
||||||
}
|
}
|
||||||
|
dashboard_store={}
|
||||||
|
orders_store={}
|
||||||
|
date_picker_store={}
|
||||||
animating = false;
|
animating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue