优化数据统计的传参以及部分展示字段以优化
This commit is contained in:
50
src/views/data/utils/index.js
Normal file
50
src/views/data/utils/index.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
// 格式化日期范围
|
||||
export function formatDateRange(range, format = "YYYY-MM-DD") {
|
||||
let arr = []
|
||||
switch (range) {
|
||||
case "today":
|
||||
// 今天
|
||||
arr = [dayjs().format(format), dayjs().format(format)];
|
||||
break;
|
||||
case "yesterday":
|
||||
// 昨天
|
||||
arr = [
|
||||
dayjs().add(-1, "d").format(format),
|
||||
dayjs().add(-1, "d").format(format),
|
||||
];
|
||||
break;
|
||||
case "last_7_days":
|
||||
// 最近7天
|
||||
arr = [
|
||||
dayjs().add(-6, "d").format(format),
|
||||
dayjs().format(format),
|
||||
];
|
||||
break;
|
||||
case "last_30_days":
|
||||
// 最近7天
|
||||
arr = [
|
||||
dayjs().add(-29, "d").format(format),
|
||||
dayjs().format(format),
|
||||
];
|
||||
break;
|
||||
case "this_week":
|
||||
// 本周
|
||||
arr = [
|
||||
dayjs().startOf("week").format(format),
|
||||
dayjs().endOf("week").format(format),
|
||||
];
|
||||
break;
|
||||
case "this_month":
|
||||
// 本周
|
||||
arr = [
|
||||
dayjs().startOf("month").format(format),
|
||||
dayjs().endOf("month").format(format),
|
||||
];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
Reference in New Issue
Block a user