code refactor

This commit is contained in:
MaysWind
2025-06-09 00:29:29 +08:00
parent ee47ee91c3
commit 2c730b3e25
16 changed files with 210 additions and 133 deletions
@@ -71,7 +71,6 @@ import { useI18n } from '@/locales/helpers.ts';
import { type CommonMonthRangeSelectionProps, useMonthRangeSelectionBase } from '@/components/base/MonthRangeSelectionBase.ts';
import { ThemeType } from '@/core/theme.ts';
import { getYearMonthObjectFromString } from '@/lib/datetime.ts';
interface DesktopMonthRangeSelectionProps extends CommonMonthRangeSelectionProps {
persistent?: boolean;
@@ -87,7 +86,7 @@ const emit = defineEmits<{
const theme = useTheme();
const { tt, getMonthShortName } = useI18n();
const { yearRange, dateRange, isYearFirst, beginDateTime, endDateTime, getFinalMonthRange } = useMonthRangeSelectionBase(props);
const { yearRange, dateRange, isYearFirst, beginDateTime, endDateTime, getMonthSelectionValue, getFinalMonthRange } = useMonthRangeSelectionBase(props);
const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType.Dark);
const showState = computed<boolean>({
@@ -117,7 +116,7 @@ function cancel(): void {
watch(() => props.minTime, (newValue) => {
if (newValue) {
const yearMonth = getYearMonthObjectFromString(newValue);
const yearMonth = getMonthSelectionValue(newValue);
if (yearMonth) {
dateRange.value[0] = yearMonth;
@@ -127,7 +126,7 @@ watch(() => props.minTime, (newValue) => {
watch(() => props.maxTime, (newValue) => {
if (newValue) {
const yearMonth = getYearMonthObjectFromString(newValue);
const yearMonth = getMonthSelectionValue(newValue);
if (yearMonth) {
dateRange.value[1] = yearMonth;
@@ -50,7 +50,6 @@ import { useI18n } from '@/locales/helpers.ts';
import { type CommonMonthSelectionProps, useMonthSelectionBase } from '@/components/base/MonthSelectionBase.ts';
import { ThemeType } from '@/core/theme.ts';
import { getYearMonthObjectFromString } from '@/lib/datetime.ts';
interface DesktopMonthSelectionProps extends CommonMonthSelectionProps {
persistent?: boolean;
@@ -66,7 +65,7 @@ const emit = defineEmits<{
const theme = useTheme();
const { tt, getMonthShortName } = useI18n();
const { yearRange, monthValue, isYearFirst, getTextualYearMonth } = useMonthSelectionBase(props);
const { yearRange, monthValue, isYearFirst, getMonthSelectionValue, getTextualYearMonth } = useMonthSelectionBase(props);
const isDarkMode = computed<boolean>(() => theme.global.name.value === ThemeType.Dark);
const showState = computed<boolean>({
@@ -96,7 +95,7 @@ function cancel(): void {
watch(() => props.modelValue, (newValue) => {
if (newValue) {
const yearMonth = getYearMonthObjectFromString(newValue);
const yearMonth = getMonthSelectionValue(newValue);
if (yearMonth) {
monthValue.value = yearMonth;
@@ -106,7 +105,7 @@ watch(() => props.modelValue, (newValue) => {
watch(() => props.show, (newValue) => {
if (newValue && props.modelValue) {
const yearMonth = getYearMonthObjectFromString(props.modelValue);
const yearMonth = getMonthSelectionValue(props.modelValue);
if (yearMonth) {
monthValue.value = yearMonth;
+7 -7
View File
@@ -14,7 +14,7 @@ import { type CommonTrendsChartProps, type TrendsBarChartClickEvent, useTrendsCh
import { useUserStore } from '@/stores/user.ts';
import { type YearMonth, DateRangeScene } from '@/core/datetime.ts';
import { type Year1BasedMonth, DateRangeScene } from '@/core/datetime.ts';
import type { ColorValue } from '@/core/color.ts';
import { ThemeType } from '@/core/theme.ts';
import { TrendChartType, ChartDateAggregationType } from '@/core/statistics.ts';
@@ -35,7 +35,7 @@ import {
sortStatisticsItems
} from '@/lib/statistics.ts';
interface DesktopTrendsChartProps<T extends YearMonth> extends CommonTrendsChartProps<T> {
interface DesktopTrendsChartProps<T extends Year1BasedMonth> extends CommonTrendsChartProps<T> {
skeleton?: boolean;
type: number;
showValue?: boolean;
@@ -155,14 +155,14 @@ const allSeries = computed<TrendsChartDataItem[]>(() => {
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}`;
}
const dataItems = dateRangeAmountMap[dateRangeKey] || [];
@@ -181,8 +181,8 @@ const allSeries = computed<TrendsChartDataItem[]>(() => {
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 amount = 0;