feat: 添加DatetimeRange的快捷方式
This commit is contained in:
parent
7957e60319
commit
a4f7b7c057
@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { monthRange } from '@/utils/common';
|
import { dayRange, monthRange } from '@/utils/common';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'DatetimeRange'
|
name: 'DatetimeRange'
|
||||||
@ -13,6 +13,9 @@ const modelValue = defineModel<[string, string] | null>('value');
|
|||||||
|
|
||||||
const createShortcuts = () => {
|
const createShortcuts = () => {
|
||||||
const shortcuts: any = {};
|
const shortcuts: any = {};
|
||||||
|
shortcuts[$t('common.today')] = dayRange(1);
|
||||||
|
shortcuts[$t('common.lastWeek')] = dayRange(7);
|
||||||
|
shortcuts[$t('common.lastMonth')] = monthRange(1, 'month');
|
||||||
shortcuts[$t('common.currentMonth')] = monthRange(0, 'month');
|
shortcuts[$t('common.currentMonth')] = monthRange(0, 'month');
|
||||||
shortcuts[$t('common.lastMonth')] = monthRange(1, 'month');
|
shortcuts[$t('common.lastMonth')] = monthRange(1, 'month');
|
||||||
shortcuts[$t('common.lastTwoMonth')] = monthRange(2, 'month');
|
shortcuts[$t('common.lastTwoMonth')] = monthRange(2, 'month');
|
||||||
|
@ -210,6 +210,8 @@ const local: App.I18n.Schema = {
|
|||||||
},
|
},
|
||||||
updateDt: 'Updated Time',
|
updateDt: 'Updated Time',
|
||||||
createDt: 'Created Time',
|
createDt: 'Created Time',
|
||||||
|
today: 'Today',
|
||||||
|
lastWeek: 'Last Week',
|
||||||
currentMonth: 'Current Month',
|
currentMonth: 'Current Month',
|
||||||
lastMonth: 'Last Month',
|
lastMonth: 'Last Month',
|
||||||
lastTwoMonth: 'Last 2 Month'
|
lastTwoMonth: 'Last 2 Month'
|
||||||
|
@ -210,6 +210,8 @@ const local: App.I18n.Schema = {
|
|||||||
},
|
},
|
||||||
updateDt: '更新时间',
|
updateDt: '更新时间',
|
||||||
createDt: '创建时间',
|
createDt: '创建时间',
|
||||||
|
today: '今天',
|
||||||
|
lastWeek: '最近一周',
|
||||||
currentMonth: '当月',
|
currentMonth: '当月',
|
||||||
lastMonth: '最近一月',
|
lastMonth: '最近一月',
|
||||||
lastTwoMonth: '最近两月'
|
lastTwoMonth: '最近两月'
|
||||||
|
2
src/typings/app.d.ts
vendored
2
src/typings/app.d.ts
vendored
@ -491,6 +491,8 @@ declare namespace App {
|
|||||||
};
|
};
|
||||||
updateDt: string;
|
updateDt: string;
|
||||||
createDt: string;
|
createDt: string;
|
||||||
|
today: string;
|
||||||
|
lastWeek: string;
|
||||||
currentMonth: string;
|
currentMonth: string;
|
||||||
lastMonth: string;
|
lastMonth: string;
|
||||||
lastTwoMonth: string;
|
lastTwoMonth: string;
|
||||||
|
@ -120,7 +120,7 @@ export function toggleHtmlClass(className: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 `最近n个自然月` timestamp时间区间
|
* 创建 `最近n个自然月` timestamp 时间区间
|
||||||
*
|
*
|
||||||
* @param months 月数
|
* @param months 月数
|
||||||
* @param startOf 时间的开始类型
|
* @param startOf 时间的开始类型
|
||||||
@ -133,6 +133,23 @@ export function monthRange(months: number = 1, startOf: dayjs.OpUnitType = 'day'
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 `最近n个自然月` timestamp 时间区间
|
||||||
|
*
|
||||||
|
* @param days 日数
|
||||||
|
* @param startOf 时间的开始类型
|
||||||
|
* @returns timestamp时间区间
|
||||||
|
*/
|
||||||
|
export function dayRange(days: number = 1) {
|
||||||
|
return [
|
||||||
|
dayjs()
|
||||||
|
.subtract(days - 1, 'day')
|
||||||
|
.startOf('day')
|
||||||
|
.valueOf(),
|
||||||
|
dayjs().endOf('day').valueOf()
|
||||||
|
] as [number, number];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 `最近n个自然月` 字符串时间区间
|
* 创建 `最近n个自然月` 字符串时间区间
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user