mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 15:37:33 +08:00
code refactor
This commit is contained in:
@@ -52,8 +52,6 @@ import { type CommonMonthRangeSelectionProps, useMonthRangeSelectionBase } from
|
||||
|
||||
import { useEnvironmentsStore } from '@/stores/environment.ts';
|
||||
|
||||
import { getYearMonthObjectFromString } from '@/lib/datetime.ts';
|
||||
|
||||
const props = defineProps<CommonMonthRangeSelectionProps>();
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:show', value: boolean): void;
|
||||
@@ -62,7 +60,7 @@ const emit = defineEmits<{
|
||||
|
||||
const { tt, getMonthShortName } = useI18n();
|
||||
const { showToast } = useI18nUIComponents();
|
||||
const { yearRange, dateRange, isYearFirst, beginDateTime, endDateTime, getFinalMonthRange } = useMonthRangeSelectionBase(props);
|
||||
const { yearRange, dateRange, isYearFirst, beginDateTime, endDateTime, getMonthSelectionValue, getFinalMonthRange } = useMonthRangeSelectionBase(props);
|
||||
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
|
||||
@@ -90,7 +88,7 @@ function cancel(): void {
|
||||
|
||||
function onSheetOpen(): void {
|
||||
if (props.minTime) {
|
||||
const yearMonth = getYearMonthObjectFromString(props.minTime);
|
||||
const yearMonth = getMonthSelectionValue(props.minTime);
|
||||
|
||||
if (yearMonth) {
|
||||
dateRange.value[0] = yearMonth;
|
||||
@@ -98,7 +96,7 @@ function onSheetOpen(): void {
|
||||
}
|
||||
|
||||
if (props.maxTime) {
|
||||
const yearMonth = getYearMonthObjectFromString(props.maxTime);
|
||||
const yearMonth = getMonthSelectionValue(props.maxTime);
|
||||
|
||||
if (yearMonth) {
|
||||
dateRange.value[1] = yearMonth;
|
||||
|
||||
@@ -46,8 +46,6 @@ import { type CommonMonthSelectionProps, useMonthSelectionBase } from '@/compone
|
||||
|
||||
import { useEnvironmentsStore } from '@/stores/environment.ts';
|
||||
|
||||
import { getYearMonthObjectFromString } from '@/lib/datetime.ts';
|
||||
|
||||
const props = defineProps<CommonMonthSelectionProps>();
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void;
|
||||
@@ -56,7 +54,7 @@ const emit = defineEmits<{
|
||||
|
||||
const { tt, getMonthShortName } = useI18n();
|
||||
const { showToast } = useI18nUIComponents();
|
||||
const { yearRange, monthValue, isYearFirst, getTextualYearMonth } = useMonthSelectionBase(props);
|
||||
const { yearRange, monthValue, isYearFirst, getMonthSelectionValue, getTextualYearMonth } = useMonthSelectionBase(props);
|
||||
|
||||
const environmentsStore = useEnvironmentsStore();
|
||||
|
||||
@@ -84,7 +82,7 @@ function cancel(): void {
|
||||
|
||||
function onSheetOpen(): void {
|
||||
if (props.modelValue) {
|
||||
const yearMonth = getYearMonthObjectFromString(props.modelValue);
|
||||
const yearMonth = getMonthSelectionValue(props.modelValue);
|
||||
|
||||
if (yearMonth) {
|
||||
monthValue.value = yearMonth;
|
||||
|
||||
@@ -95,7 +95,7 @@ import { type CommonTrendsChartProps, type TrendsBarChartClickEvent, useTrendsCh
|
||||
|
||||
import { useUserStore } from '@/stores/user.ts';
|
||||
|
||||
import { type YearMonth, type UnixTimeRange, DateRangeScene } from '@/core/datetime.ts';
|
||||
import { type Year1BasedMonth, type UnixTimeRange, DateRangeScene } from '@/core/datetime.ts';
|
||||
import { ChartDateAggregationType } from '@/core/statistics.ts';
|
||||
import { DEFAULT_CHART_COLORS } from '@/consts/color.ts';
|
||||
import type { YearMonthDataItem, SortableTransactionStatisticDataItem } from '@/models/transaction.ts';
|
||||
@@ -138,7 +138,7 @@ interface TrendsBarChartData {
|
||||
readonly legends: TrendsBarChartLegend[];
|
||||
}
|
||||
|
||||
interface MobileTrendsChartProps<T extends YearMonth> extends CommonTrendsChartProps<T> {
|
||||
interface MobileTrendsChartProps<T extends Year1BasedMonth> extends CommonTrendsChartProps<T> {
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
@@ -191,14 +191,14 @@ const allDisplayDataItems = computed<TrendsBarChartData>(() => {
|
||||
dateRangeKey = dataItem.year.toString();
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.FiscalYear.type) {
|
||||
const fiscalYear = getFiscalYearFromUnixTime(
|
||||
getYearMonthFirstUnixTime({ year: dataItem.year, month: dataItem.month - 1 }),
|
||||
getYearMonthFirstUnixTime({ year: dataItem.year, month1base: dataItem.month1base }),
|
||||
props.fiscalYearStart
|
||||
);
|
||||
dateRangeKey = fiscalYear.toString();
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type) {
|
||||
dateRangeKey = `${dataItem.year}-${Math.floor((dataItem.month - 1) / 3) + 1}`;
|
||||
dateRangeKey = `${dataItem.year}-${Math.floor((dataItem.month1base - 1) / 3) + 1}`;
|
||||
} else { // if (props.dateAggregationType === ChartDateAggregationType.Month.type) {
|
||||
dateRangeKey = `${dataItem.year}-${dataItem.month}`;
|
||||
dateRangeKey = `${dataItem.year}-${dataItem.month1base}`;
|
||||
}
|
||||
|
||||
if (dateRangeItemMap[dateRangeKey]) {
|
||||
@@ -229,8 +229,8 @@ const allDisplayDataItems = computed<TrendsBarChartData>(() => {
|
||||
dateRangeKey = dateRange.year.toString();
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Quarter.type && 'quarter' in dateRange) {
|
||||
dateRangeKey = `${dateRange.year}-${dateRange.quarter}`;
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Month.type && 'month' in dateRange) {
|
||||
dateRangeKey = `${dateRange.year}-${dateRange.month + 1}`;
|
||||
} else if (props.dateAggregationType === ChartDateAggregationType.Month.type && 'month0base' in dateRange) {
|
||||
dateRangeKey = `${dateRange.year}-${dateRange.month0base + 1}`;
|
||||
}
|
||||
|
||||
let displayDateRange = '';
|
||||
|
||||
Reference in New Issue
Block a user