|
@@ -1,6 +1,6 @@
|
|
|
import moment from "moment";
|
|
|
|
|
|
-export const RangePicker = {
|
|
|
+export const picker = {
|
|
|
today: [moment(), moment()],
|
|
|
week: [moment().subtract(7, "days"), moment()],
|
|
|
month: [moment().subtract(30, "days"), moment()],
|
|
@@ -12,9 +12,42 @@ export const RangePicker = {
|
|
|
],
|
|
|
};
|
|
|
|
|
|
-export const RangePickerText = {
|
|
|
+export const pickerText = {
|
|
|
today: "今天",
|
|
|
week: "一周前",
|
|
|
month: "一月前",
|
|
|
three_month: "3个月前",
|
|
|
};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 日期picker range可自定义添加
|
|
|
+ * @methods add("本周", [moment(), moment()])
|
|
|
+ * @methods pick(["today", "week"])
|
|
|
+ */
|
|
|
+class RangePicker implements RangePickerClass {
|
|
|
+ private config: Record<string, moment.Moment[]>;
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ this.config = Object.create({});
|
|
|
+ }
|
|
|
+
|
|
|
+ add(text: string, range: moment.Moment[]) {
|
|
|
+ this.config[text] = range;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ pick(range: string[]) {
|
|
|
+ range.forEach((r: string) => {
|
|
|
+ const text = (<Record<string, string>>pickerText)[r];
|
|
|
+ this.config[text] = (picker as Record<string, moment.Moment[]>)[r];
|
|
|
+ });
|
|
|
+
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ getRange() {
|
|
|
+ return this.config;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default new RangePicker();
|