Browse Source

feat: Optimize abpStore

pull/1438/head
colin 3 weeks ago
parent
commit
6781539137
  1. 1
      apps/vben5/packages/@abp/core/src/store/abp.ts
  2. 74
      apps/vben5/packages/@abp/core/src/utils/date.ts

1
apps/vben5/packages/@abp/core/src/store/abp.ts

@ -58,6 +58,7 @@ export const useAbpStore = defineStore(
function setApplication(val: ApplicationConfigurationDto) { function setApplication(val: ApplicationConfigurationDto) {
application.value = val; application.value = val;
setTenantId(val.currentTenant?.id);
xsrfToken.value = cookies.get('XSRF-TOKEN'); xsrfToken.value = cookies.get('XSRF-TOKEN');
} }

74
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_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD'; const DATE_FORMAT = 'YYYY-MM-DD';
/**
* @zh_CN
* @param date
* @param format ,dayJs文档
* @returns
*/
export function formatToDateTime( export function formatToDateTime(
date?: dayjs.ConfigType, date?: dayjs.ConfigType,
format = DATE_TIME_FORMAT, format = DATE_TIME_FORMAT,
@ -13,6 +19,12 @@ export function formatToDateTime(
return dayjs(date).format(format); return dayjs(date).format(format);
} }
/**
* @zh_CN
* @param date
* @param format ,dayJs文档
* @returns
*/
export function formatToDate( export function formatToDate(
date?: dayjs.ConfigType, date?: dayjs.ConfigType,
format = DATE_FORMAT, format = DATE_FORMAT,
@ -21,7 +33,7 @@ export function formatToDate(
return dayjs(date).format(format); return dayjs(date).format(format);
} }
/** /**
* * @zh_CN
* @param days * @param days
* @returns * @returns
*/ */
@ -36,7 +48,7 @@ export function getAppointDate(days: number): dayjs.Dayjs {
} }
/** /**
* * @zh_CN
* @returns * @returns
*/ */
export function firstDayOfWeek(): dayjs.Dayjs { 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 * @returns
*/ */
export function firstDayOfMonth(): dayjs.Dayjs { 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 * @returns 返回当月最后一天00:00:00
*/ */
export function lastDayOfMonth(): dayjs.Dayjs { 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 * @returns 返回当月最后一天23:59:59
*/ */
export function lastDateOfMonth(): dayjs.Dayjs { export function lastDateOfMonth(): dayjs.Dayjs {
@ -80,7 +100,7 @@ export function lastDateOfMonth(): dayjs.Dayjs {
} }
/** /**
* * @zh_CN
* @returns * @returns
*/ */
export function firstDayOfLastMonth(): dayjs.Dayjs { 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 * @returns 返回上个月最后一天23:59:59
*/ */
export function lastDateOfLastMonth(): dayjs.Dayjs { export function lastDateOfLastMonth(): dayjs.Dayjs {
@ -100,7 +120,7 @@ export function lastDateOfLastMonth(): dayjs.Dayjs {
} }
/** /**
* * @zh_CN
* @returns * @returns
*/ */
export function firstDayOfYear(): dayjs.Dayjs { export function firstDayOfYear(): dayjs.Dayjs {
@ -108,4 +128,42 @@ export function firstDayOfYear(): dayjs.Dayjs {
return dayjs(new Date(now.getFullYear(), 0, 1)); 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; export const dateUtil = dayjs;

Loading…
Cancel
Save