فهرست منبع

📦 add(helper/config/range): date-picker ranges配置

晓晓晓晓丶vv 4 سال پیش
والد
کامیت
0899eb3fab
2فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 20 0
      src/helper/config/range.ts
  2. 16 0
      src/helper/index.ts

+ 20 - 0
src/helper/config/range.ts

@@ -0,0 +1,20 @@
+import moment from "moment";
+
+export const RangePicker = {
+  today: [moment(), moment()],
+  week: [moment().subtract(7, "days"), moment()],
+  month: [moment().subtract(30, "days"), moment()],
+  three_month: [
+    moment()
+      .subtract(3, "month")
+      .startOf("month"),
+    moment(),
+  ],
+};
+
+export const RangePickerText = {
+  today: "今天",
+  week: "一周前",
+  month: "一月前",
+  three_month: "3个月前",
+};

+ 16 - 0
src/helper/index.ts

@@ -1,4 +1,5 @@
 const path = require("path");
+import { RangePicker, RangePickerText } from "./config/range";
 
 /**
  * json字符串格式化
@@ -74,3 +75,18 @@ export const formatSelectOptions = <T>(
     };
   });
 };
+
+/**
+ * 获取需要筛选的时间区间
+ * @param range eg: ["today", "month", "week", "three_month"]
+ */
+export const rangePicker = (range: string[]) => {
+  let rangeConfig: Record<string, moment.Moment[]> = Object.create({});
+
+  range.forEach((r: string) => {
+    const text = (<Record<string, string>>RangePickerText)[r];
+    rangeConfig[text] = (RangePicker as Record<string, moment.Moment[]>)[r];
+  });
+
+  return rangeConfig;
+};