From 6781539137ca6218840d70d30b664542ba7eb30f Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 6 Mar 2026 11:26:51 +0800 Subject: [PATCH] feat: Optimize abpStore --- .../vben5/packages/@abp/core/src/store/abp.ts | 1 + .../packages/@abp/core/src/utils/date.ts | 74 +++++++++++++++++-- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/apps/vben5/packages/@abp/core/src/store/abp.ts b/apps/vben5/packages/@abp/core/src/store/abp.ts index 567c8ca95..ee5837697 100644 --- a/apps/vben5/packages/@abp/core/src/store/abp.ts +++ b/apps/vben5/packages/@abp/core/src/store/abp.ts @@ -58,6 +58,7 @@ export const useAbpStore = defineStore( function setApplication(val: ApplicationConfigurationDto) { application.value = val; + setTenantId(val.currentTenant?.id); xsrfToken.value = cookies.get('XSRF-TOKEN'); } diff --git a/apps/vben5/packages/@abp/core/src/utils/date.ts b/apps/vben5/packages/@abp/core/src/utils/date.ts index c388d0834..7a13d5bbf 100644 --- a/apps/vben5/packages/@abp/core/src/utils/date.ts +++ b/apps/vben5/packages/@abp/core/src/utils/date.ts @@ -6,6 +6,12 @@ import dayjs from 'dayjs'; const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'; const DATE_FORMAT = 'YYYY-MM-DD'; +/** + * @zh_CN 格式化时间 + * @param date 需要格式化的时间 + * @param format 格式化字符串,参考dayJs文档 + * @returns 返回格式化后的时间字符串 + */ export function formatToDateTime( date?: dayjs.ConfigType, format = DATE_TIME_FORMAT, @@ -13,6 +19,12 @@ export function formatToDateTime( return dayjs(date).format(format); } +/** + * @zh_CN 格式化日期 + * @param date 需要格式化的日期 + * @param format 格式化字符串,参考dayJs文档 + * @returns 返回格式化后的日期字符串 + */ export function formatToDate( date?: dayjs.ConfigType, format = DATE_FORMAT, @@ -21,7 +33,7 @@ export function formatToDate( return dayjs(date).format(format); } /** - * 获取指定日期 + * @zh_CN 获取指定日期 * @param days 天数 * @returns 返回指定天数之后的日期 */ @@ -36,7 +48,7 @@ export function getAppointDate(days: number): dayjs.Dayjs { } /** - * 获取本周第一天 + * @zh_CN 获取本周第一天 * @returns 返回本周第一天 */ export function firstDayOfWeek(): dayjs.Dayjs { @@ -51,7 +63,15 @@ export function firstDayOfWeek(): dayjs.Dayjs { } /** - * 获取当月第一天 + * @zh_CN 获取本周最后一天 + * @returns 返回本周最后一天 + */ +export function lastDayOfWeek(): dayjs.Dayjs { + return firstDayOfWeek().add(6, 'day'); +} + +/** + * @zh_CN 获取当月第一天 * @returns 返回当月第一天 */ export function firstDayOfMonth(): dayjs.Dayjs { @@ -60,7 +80,7 @@ export function firstDayOfMonth(): dayjs.Dayjs { } /** - * 获取当月最后一天00:00:00 + * @zh_CN 获取当月最后一天00:00:00 * @returns 返回当月最后一天00:00:00 */ export function lastDayOfMonth(): dayjs.Dayjs { @@ -69,7 +89,7 @@ export function lastDayOfMonth(): dayjs.Dayjs { } /** - * 获取当月最后一天23:59:59 + * @zh_CN 获取当月最后一天23:59:59 * @returns 返回当月最后一天23:59:59 */ export function lastDateOfMonth(): dayjs.Dayjs { @@ -80,7 +100,7 @@ export function lastDateOfMonth(): dayjs.Dayjs { } /** - * 获取上个月第一天 + * @zh_CN 获取上个月第一天 * @returns 返回上个月第一天 */ export function firstDayOfLastMonth(): dayjs.Dayjs { @@ -89,7 +109,7 @@ export function firstDayOfLastMonth(): dayjs.Dayjs { } /** - * 获取上个月最后一天23:59:59 + * @zh_CN 获取上个月最后一天23:59:59 * @returns 返回上个月最后一天23:59:59 */ export function lastDateOfLastMonth(): dayjs.Dayjs { @@ -100,7 +120,7 @@ export function lastDateOfLastMonth(): dayjs.Dayjs { } /** - * 获取本年第一天 + * @zh_CN 获取本年第一天 * @returns 返回本年第一天 */ export function firstDayOfYear(): dayjs.Dayjs { @@ -108,4 +128,42 @@ export function firstDayOfYear(): dayjs.Dayjs { return dayjs(new Date(now.getFullYear(), 0, 1)); } +/** + * @zh_CN 获取本年最后一天 + * @returns 返回本年最后一天 + */ +export function lastDayOfYear(): dayjs.Dayjs { + const now = new Date(); + return dayjs(new Date(now.getFullYear(), 11, 31)); +} + +/** + * @zh_CN 获取最近半年第一天 + * @returns 返回最近半年第一天 + */ +export function firstDayOfLastHalfYear(): dayjs.Dayjs { + const now = new Date(); + return dayjs(new Date(now.getFullYear(), now.getMonth() - 6, 1)); +} + +/** + * @zh_CN 获取本季度第一天 + * @returns 返回本季度第一天 + */ +export function firstDayOfQuarter(): dayjs.Dayjs { + const now = new Date(); + const quarter = Math.floor(now.getMonth() / 3) + 1; + return dayjs(new Date(now.getFullYear(), (quarter - 1) * 3, 1)); +} + +/** + * @zh_CN 获取本季度最后一天 + * @returns 返回本季度最后一天 + */ +export function lastDayOfQuarter(): dayjs.Dayjs { + const now = new Date(); + const quarter = Math.floor(now.getMonth() / 3) + 1; + return dayjs(new Date(now.getFullYear(), quarter * 3, 0)); +} + export const dateUtil = dayjs;