mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-17 08:14:25 +08:00
code refactor
This commit is contained in:
@@ -52,11 +52,11 @@ export interface CommonAccountBalanceTrendsChartProps {
|
||||
|
||||
export function useAccountBalanceTrendsChartBase(props: CommonAccountBalanceTrendsChartProps) {
|
||||
const {
|
||||
getCalendarShortYearFromUnixTime,
|
||||
getCalendarShortYearMonthFromUnixTime,
|
||||
getCalendarYearQuarterFromUnixTime,
|
||||
getCalendarFiscalYearFromUnixTime,
|
||||
formatUnixTimeToShortDate
|
||||
formatUnixTimeToShortDate,
|
||||
formatUnixTimeToGregorianLikeShortYear,
|
||||
formatUnixTimeToGregorianLikeShortYearMonth,
|
||||
formatUnixTimeToGregorianLikeYearQuarter,
|
||||
formatUnixTimeToGregorianLikeFiscalYear
|
||||
} = useI18n();
|
||||
|
||||
const dataDateRange = computed<AccountBalanceUnixTimeAndBalanceRange | null>(() => {
|
||||
@@ -156,13 +156,13 @@ export function useAccountBalanceTrendsChartBase(props: CommonAccountBalanceTren
|
||||
let displayDate = '';
|
||||
|
||||
if (props.dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
displayDate = getCalendarShortYearFromUnixTime(dateRange.minUnixTime);
|
||||
displayDate = formatUnixTimeToGregorianLikeShortYear(dateRange.minUnixTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type) {
|
||||
displayDate = getCalendarFiscalYearFromUnixTime(dateRange.minUnixTime);
|
||||
displayDate = formatUnixTimeToGregorianLikeFiscalYear(dateRange.minUnixTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type) {
|
||||
displayDate = getCalendarYearQuarterFromUnixTime(dateRange.minUnixTime);
|
||||
displayDate = formatUnixTimeToGregorianLikeYearQuarter(dateRange.minUnixTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
displayDate = getCalendarShortYearMonthFromUnixTime(dateRange.minUnixTime);
|
||||
displayDate = formatUnixTimeToGregorianLikeShortYearMonth(dateRange.minUnixTime);
|
||||
} else {
|
||||
displayDate = formatUnixTimeToShortDate(dateRange.minUnixTime);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ function getFiscalYearStartFromProps(props: CommonFiscalYearStartSelectionProps)
|
||||
}
|
||||
|
||||
export function useFiscalYearStartSelectionBase(props: CommonFiscalYearStartSelectionProps) {
|
||||
const { getCalendarLongMonthDayFromGregorianCalendarTextualMonthDay } = useI18n();
|
||||
const { formatGregorianTextualMonthDayToGregorianLikeLongMonthDay } = useI18n();
|
||||
|
||||
const disabledDates = (date: Date) => {
|
||||
// Disable February 29 (leap day)
|
||||
@@ -71,7 +71,7 @@ export function useFiscalYearStartSelectionBase(props: CommonFiscalYearStartSele
|
||||
fiscalYearStart = FiscalYearStart.Default;
|
||||
}
|
||||
|
||||
return getCalendarLongMonthDayFromGregorianCalendarTextualMonthDay(fiscalYearStart.toMonthDashDayString());
|
||||
return formatGregorianTextualMonthDayToGregorianLikeLongMonthDay(fiscalYearStart.toMonthDashDayString());
|
||||
});
|
||||
|
||||
const allowedMinDate = computed<Date>(() => getLocalDatetimeFromUnixTime(getThisYearFirstUnixTime()));
|
||||
|
||||
@@ -49,7 +49,7 @@ function getMonthRangeFromProps(props: CommonMonthRangeSelectionProps): { minDat
|
||||
}
|
||||
|
||||
export function useMonthRangeSelectionBase(props: CommonMonthRangeSelectionProps) {
|
||||
const { getCalendarLongYearMonthFromUnixTime } = useI18n();
|
||||
const { formatUnixTimeToGregorianLikeLongYearMonth } = useI18n();
|
||||
const { minDate, maxDate } = getMonthRangeFromProps(props);
|
||||
|
||||
const dateRange = ref<Year0BasedMonth[]>([
|
||||
@@ -57,8 +57,8 @@ export function useMonthRangeSelectionBase(props: CommonMonthRangeSelectionProps
|
||||
maxDate
|
||||
]);
|
||||
|
||||
const beginDateTime = computed<string>(() => getCalendarLongYearMonthFromUnixTime(getYearMonthFirstUnixTime(dateRange.value[0])));
|
||||
const endDateTime = computed<string>(() => getCalendarLongYearMonthFromUnixTime(getYearMonthLastUnixTime(dateRange.value[1])));
|
||||
const beginDateTime = computed<string>(() => formatUnixTimeToGregorianLikeLongYearMonth(getYearMonthFirstUnixTime(dateRange.value[0])));
|
||||
const endDateTime = computed<string>(() => formatUnixTimeToGregorianLikeLongYearMonth(getYearMonthLastUnixTime(dateRange.value[1])));
|
||||
|
||||
function getFinalMonthRange(): { minYearMonth: TextualYearMonth | '', maxYearMonth: TextualYearMonth | '' } | null {
|
||||
if (!dateRange.value[0] || !dateRange.value[1]) {
|
||||
|
||||
@@ -88,9 +88,9 @@ const {
|
||||
getCurrentCalendarDisplayType,
|
||||
isLongDateMonthAfterYear,
|
||||
isLongTime24HourFormat,
|
||||
getCalendarShortYearFromUnixTime,
|
||||
getCalendarShortMonthFromUnixTime,
|
||||
getCalendarDayOfMonthFromUnixTime,
|
||||
getCalendarDisplayShortYearFromUnixTime,
|
||||
getCalendarDisplayShortMonthFromUnixTime,
|
||||
getCalendarDisplayDayOfMonthFromUnixTime,
|
||||
getCalendarAlternateDate
|
||||
} = useI18n();
|
||||
|
||||
@@ -130,21 +130,21 @@ function switchView(viewType: MenuView): void {
|
||||
}
|
||||
|
||||
function getDisplayYear(year: number): string {
|
||||
return getCalendarShortYearFromUnixTime(getYearMonthDayDateTime(year, 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortYearFromUnixTime(getYearMonthDayDateTime(year, 1, 1).getUnixTime());
|
||||
}
|
||||
|
||||
function getDisplayMonth(month: number): string {
|
||||
if (isArray(dateTime.value)) {
|
||||
return getCalendarShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value[0].getFullYear(), month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value[0].getFullYear(), month + 1, 1).getUnixTime());
|
||||
} else if (dateTime.value) {
|
||||
return getCalendarShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value.getFullYear(), month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value.getFullYear(), month + 1, 1).getUnixTime());
|
||||
} else {
|
||||
return getCalendarShortMonthFromUnixTime(getYearMonthDayDateTime(new Date().getFullYear(), month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(new Date().getFullYear(), month + 1, 1).getUnixTime());
|
||||
}
|
||||
}
|
||||
|
||||
function getDisplayDay(date: Date): string {
|
||||
return getCalendarDayOfMonthFromUnixTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()).getUnixTime());
|
||||
return getCalendarDisplayDayOfMonthFromUnixTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()).getUnixTime());
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
|
||||
@@ -55,8 +55,8 @@ const emit = defineEmits<{
|
||||
|
||||
const {
|
||||
isLongDateMonthAfterYear,
|
||||
getCalendarShortYearFromUnixTime,
|
||||
getCalendarShortMonthFromUnixTime
|
||||
getCalendarDisplayShortYearFromUnixTime,
|
||||
getCalendarDisplayShortMonthFromUnixTime
|
||||
} = useI18n();
|
||||
|
||||
const yearRange = getAllowedYearRange();
|
||||
@@ -97,14 +97,14 @@ function getYear0BasedMonthFromMonthSelectionValue(value: MonthSelectionValue):
|
||||
}
|
||||
|
||||
function getDisplayYear(year: number): string {
|
||||
return getCalendarShortYearFromUnixTime(getYearMonthDayDateTime(year, 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortYearFromUnixTime(getYearMonthDayDateTime(year, 1, 1).getUnixTime());
|
||||
}
|
||||
|
||||
function getDisplayMonth(month: number): string {
|
||||
if (isArray(dateTime.value)) {
|
||||
return getCalendarShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value[0].year, month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value[0].year, month + 1, 1).getUnixTime());
|
||||
} else {
|
||||
return getCalendarShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value.year, month + 1, 1).getUnixTime());
|
||||
return getCalendarDisplayShortMonthFromUnixTime(getYearMonthDayDateTime(dateTime.value.year, month + 1, 1).getUnixTime());
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -69,7 +69,7 @@ const emit = defineEmits<{
|
||||
const {
|
||||
getAllLongWeekdayNames,
|
||||
getAllShortWeekdayNames,
|
||||
getCalendarDayOfMonthFromUnixTime,
|
||||
getCalendarDisplayDayOfMonthFromUnixTime,
|
||||
getCalendarAlternateDates,
|
||||
formatAmountToLocalizedNumeralsWithCurrency
|
||||
} = useI18n();
|
||||
@@ -117,7 +117,7 @@ function getDisplayMonthTotalAmount(amount: number, currency: string | false, sy
|
||||
}
|
||||
|
||||
function getDisplayDay(date: Date): string {
|
||||
return getCalendarDayOfMonthFromUnixTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()).getUnixTime());
|
||||
return getCalendarDisplayDayOfMonthFromUnixTime(getYearMonthDayDateTime(date.getFullYear(), date.getMonth() + 1, date.getDate()).getUnixTime());
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const theme = useTheme();
|
||||
const { tt, formatGregorianCalendarYearDashMonthDashDayToLongDate } = useI18n();
|
||||
const { tt, formatGregorianTextualYearMonthDayToLongDate } = useI18n();
|
||||
|
||||
const dateTime = computed<Date | null>({
|
||||
get: () => props.modelValue ? getLocalDateFromYearDashMonthDashDay(props.modelValue) : null,
|
||||
@@ -62,7 +62,7 @@ const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType
|
||||
const displayTime = computed<string>({
|
||||
get: () => {
|
||||
if (props.modelValue) {
|
||||
return formatGregorianCalendarYearDashMonthDashDayToLongDate(props.modelValue);
|
||||
return formatGregorianTextualYearMonthDayToLongDate(props.modelValue);
|
||||
} else if (props.noDataText) {
|
||||
return props.noDataText;
|
||||
} else {
|
||||
|
||||
@@ -80,10 +80,10 @@ const theme = useTheme();
|
||||
const {
|
||||
tt,
|
||||
getCurrentLanguageTextDirection,
|
||||
getCalendarShortYearFromUnixTime,
|
||||
getCalendarShortYearMonthFromUnixTime,
|
||||
getCalendarYearQuarterFromYearQuarter,
|
||||
getCalendarFiscalYearFromUnixTime,
|
||||
formatUnixTimeToGregorianLikeShortYear,
|
||||
formatUnixTimeToGregorianLikeShortYearMonth,
|
||||
formatYearQuarterToGregorianLikeYearQuarter,
|
||||
formatUnixTimeToGregorianLikeFiscalYear,
|
||||
formatAmountToWesternArabicNumeralsWithoutDigitGrouping,
|
||||
formatAmountToLocalizedNumeralsWithCurrency
|
||||
} = useI18n();
|
||||
@@ -139,13 +139,13 @@ const allDisplayDateRanges = computed<string[]>(() => {
|
||||
const dateRange = allDateRanges.value[i];
|
||||
|
||||
if (props.dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
allDisplayDateRanges.push(getCalendarShortYearFromUnixTime(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatUnixTimeToGregorianLikeShortYear(dateRange.minUnixTime));
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type && 'year' in dateRange) {
|
||||
allDisplayDateRanges.push(getCalendarFiscalYearFromUnixTime(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatUnixTimeToGregorianLikeFiscalYear(dateRange.minUnixTime));
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type && 'quarter' in dateRange) {
|
||||
allDisplayDateRanges.push(getCalendarYearQuarterFromYearQuarter(dateRange.year, dateRange.quarter));
|
||||
allDisplayDateRanges.push(formatYearQuarterToGregorianLikeYearQuarter(dateRange.year, dateRange.quarter));
|
||||
} else { // if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
allDisplayDateRanges.push(getCalendarShortYearMonthFromUnixTime(dateRange.minUnixTime));
|
||||
allDisplayDateRanges.push(formatUnixTimeToGregorianLikeShortYearMonth(dateRange.minUnixTime));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,10 +156,10 @@ const emit = defineEmits<{
|
||||
|
||||
const {
|
||||
tt,
|
||||
getCalendarShortYearFromUnixTime,
|
||||
getCalendarShortYearMonthFromUnixTime,
|
||||
getCalendarYearQuarterFromYearQuarter,
|
||||
getCalendarFiscalYearFromUnixTime,
|
||||
formatUnixTimeToGregorianLikeShortYear,
|
||||
formatUnixTimeToGregorianLikeShortYearMonth,
|
||||
formatYearQuarterToGregorianLikeYearQuarter,
|
||||
formatUnixTimeToGregorianLikeFiscalYear,
|
||||
formatAmountToLocalizedNumeralsWithCurrency
|
||||
} = useI18n();
|
||||
|
||||
@@ -250,13 +250,13 @@ const allDisplayDataItems = computed<MonthlyTrendsBarChartData>(() => {
|
||||
let displayDateRange = '';
|
||||
|
||||
if (props.dateAggregationType === ChartDateAggregationType.Year.type) {
|
||||
displayDateRange = getCalendarShortYearFromUnixTime(dateRange.minUnixTime);
|
||||
displayDateRange = formatUnixTimeToGregorianLikeShortYear(dateRange.minUnixTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type) {
|
||||
displayDateRange = getCalendarFiscalYearFromUnixTime(dateRange.minUnixTime);
|
||||
displayDateRange = formatUnixTimeToGregorianLikeFiscalYear(dateRange.minUnixTime);
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type && 'quarter' in dateRange) {
|
||||
displayDateRange = getCalendarYearQuarterFromYearQuarter(dateRange.year, dateRange.quarter);
|
||||
displayDateRange = formatYearQuarterToGregorianLikeYearQuarter(dateRange.year, dateRange.quarter);
|
||||
} else { // if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
displayDateRange = getCalendarShortYearMonthFromUnixTime(dateRange.minUnixTime);
|
||||
displayDateRange = formatUnixTimeToGregorianLikeShortYearMonth(dateRange.minUnixTime);
|
||||
}
|
||||
|
||||
const dataItems = allDateRangeItemsMap[dateRangeKey] || [];
|
||||
|
||||
Reference in New Issue
Block a user