code refactor

This commit is contained in:
MaysWind
2025-01-12 13:15:10 +08:00
parent f2ebd751d4
commit 6a62cfdef7
9 changed files with 39 additions and 39 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ export class AccountCategory implements TypeAndName {
return AccountCategory.allInstances; return AccountCategory.allInstances;
} }
public static valueOf(type: number): AccountCategory { public static valueOf(type: number): AccountCategory | undefined {
return AccountCategory.allInstancesByType[type]; return AccountCategory.allInstancesByType[type];
} }
} }
+1 -1
View File
@@ -47,7 +47,7 @@ export class PresetAmountColor implements TypeAndName {
return PresetAmountColor.allInstances; return PresetAmountColor.allInstances;
} }
public static valueOf(type: number): PresetAmountColor { public static valueOf(type: number): PresetAmountColor | undefined {
return PresetAmountColor.allInstancesByType[type]; return PresetAmountColor.allInstancesByType[type];
} }
} }
+2 -2
View File
@@ -64,11 +64,11 @@ export class CurrencyDisplayType implements TypeAndName {
return CurrencyDisplayType.allInstances; return CurrencyDisplayType.allInstances;
} }
public static valueOf(type: number): CurrencyDisplayType { public static valueOf(type: number): CurrencyDisplayType | undefined {
return CurrencyDisplayType.allInstancesByType[type]; return CurrencyDisplayType.allInstancesByType[type];
} }
public static parse(typeName: string): CurrencyDisplayType { public static parse(typeName: string): CurrencyDisplayType | undefined {
return CurrencyDisplayType.allInstancesByTypeName[typeName]; return CurrencyDisplayType.allInstancesByTypeName[typeName];
} }
} }
+8 -8
View File
@@ -160,7 +160,7 @@ export class Month {
return Month.allInstances; return Month.allInstances;
} }
public static valueOf(month: number): Month { public static valueOf(month: number): Month | undefined {
return Month.allInstances[month - 1]; return Month.allInstances[month - 1];
} }
} }
@@ -194,11 +194,11 @@ export class WeekDay implements TypeAndName {
return WeekDay.allInstances; return WeekDay.allInstances;
} }
public static valueOf(dayOfWeek: number): WeekDay { public static valueOf(dayOfWeek: number): WeekDay | undefined {
return WeekDay.allInstances[dayOfWeek]; return WeekDay.allInstances[dayOfWeek];
} }
public static parse(typeName: string): WeekDay { public static parse(typeName: string): WeekDay | undefined {
return WeekDay.allInstancesByName[typeName]; return WeekDay.allInstancesByName[typeName];
} }
} }
@@ -269,7 +269,7 @@ export class LongDateFormat implements DateFormat {
return LongDateFormat.allInstancesByTypeName; return LongDateFormat.allInstancesByTypeName;
} }
public static valueOf(type: number): LongDateFormat { public static valueOf(type: number): LongDateFormat | undefined {
return LongDateFormat.allInstancesByType[type]; return LongDateFormat.allInstancesByType[type];
} }
} }
@@ -309,7 +309,7 @@ export class ShortDateFormat implements DateFormat {
return ShortDateFormat.allInstancesByTypeName; return ShortDateFormat.allInstancesByTypeName;
} }
public static valueOf(type: number): ShortDateFormat { public static valueOf(type: number): ShortDateFormat | undefined {
return ShortDateFormat.allInstancesByType[type]; return ShortDateFormat.allInstancesByType[type];
} }
} }
@@ -360,7 +360,7 @@ export class LongTimeFormat implements TimeFormat {
return LongTimeFormat.allInstancesByTypeName; return LongTimeFormat.allInstancesByTypeName;
} }
public static valueOf(type: number): LongTimeFormat { public static valueOf(type: number): LongTimeFormat | undefined {
return LongTimeFormat.allInstancesByType[type]; return LongTimeFormat.allInstancesByType[type];
} }
} }
@@ -404,7 +404,7 @@ export class ShortTimeFormat implements TimeFormat {
return ShortTimeFormat.allInstancesByTypeName; return ShortTimeFormat.allInstancesByTypeName;
} }
public static valueOf(type: number): ShortTimeFormat { public static valueOf(type: number): ShortTimeFormat | undefined {
return ShortTimeFormat.allInstancesByType[type]; return ShortTimeFormat.allInstancesByType[type];
} }
} }
@@ -496,7 +496,7 @@ export class DateRange implements TypeAndName {
return DateRange.allInstancesByTypeName; return DateRange.allInstancesByTypeName;
} }
public static valueOf(type: number): DateRange { public static valueOf(type: number): DateRange | undefined {
return DateRange.allInstancesByType[type]; return DateRange.allInstancesByType[type];
} }
+7 -7
View File
@@ -56,11 +56,11 @@ export class DecimalSeparator implements TypeAndName, NumeralSymbolType {
return DecimalSeparator.allInstances; return DecimalSeparator.allInstances;
} }
public static valueOf(type: number): DecimalSeparator { public static valueOf(type: number): DecimalSeparator | undefined {
return DecimalSeparator.allInstancesByType[type]; return DecimalSeparator.allInstancesByType[type];
} }
public static parse(typeName: string): DecimalSeparator { public static parse(typeName: string): DecimalSeparator | undefined {
return DecimalSeparator.allInstancesByTypeName[typeName]; return DecimalSeparator.allInstancesByTypeName[typeName];
} }
} }
@@ -96,11 +96,11 @@ export class DigitGroupingSymbol implements TypeAndName, NumeralSymbolType {
return DigitGroupingSymbol.allInstances; return DigitGroupingSymbol.allInstances;
} }
public static valueOf(type: number): DigitGroupingSymbol { public static valueOf(type: number): DigitGroupingSymbol | undefined {
return DigitGroupingSymbol.allInstancesByType[type]; return DigitGroupingSymbol.allInstancesByType[type];
} }
public static parse(typeName: string): DigitGroupingSymbol { public static parse(typeName: string): DigitGroupingSymbol | undefined {
return DigitGroupingSymbol.allInstancesByTypeName[typeName]; return DigitGroupingSymbol.allInstancesByTypeName[typeName];
} }
} }
@@ -136,11 +136,11 @@ export class DigitGroupingType implements TypeAndName {
return DigitGroupingType.allInstances; return DigitGroupingType.allInstances;
} }
public static valueOf(type: number): DigitGroupingType { public static valueOf(type: number): DigitGroupingType | undefined {
return DigitGroupingType.allInstancesByType[type]; return DigitGroupingType.allInstancesByType[type];
} }
public static parse(typeName: string): DigitGroupingType { public static parse(typeName: string): DigitGroupingType | undefined {
return DigitGroupingType.allInstancesByTypeName[typeName]; return DigitGroupingType.allInstancesByTypeName[typeName];
} }
} }
@@ -173,7 +173,7 @@ export class AmountFilterType {
return AmountFilterType.allInstances; return AmountFilterType.allInstances;
} }
public static valueOf(type: string): AmountFilterType { public static valueOf(type: string): AmountFilterType | undefined {
return AmountFilterType.allInstancesByType[type]; return AmountFilterType.allInstancesByType[type];
} }
} }
+3 -3
View File
@@ -139,7 +139,7 @@ export class ChartDataType implements TypeAndName {
return ChartDataType.allInstancesByTypeName; return ChartDataType.allInstancesByTypeName;
} }
public static valueOf(type: number): ChartDataType { public static valueOf(type: number): ChartDataType | undefined {
return ChartDataType.allInstancesByType[type]; return ChartDataType.allInstancesByType[type];
} }
@@ -176,7 +176,7 @@ export class ChartSortingType implements TypeAndName {
return ChartSortingType.allInstances; return ChartSortingType.allInstances;
} }
public static valueOf(type: number): ChartSortingType { public static valueOf(type: number): ChartSortingType | undefined {
return ChartSortingType.allInstancesByType[type]; return ChartSortingType.allInstancesByType[type];
} }
} }
@@ -206,7 +206,7 @@ export class ChartDateAggregationType implements TypeAndName {
return ChartDateAggregationType.allInstances; return ChartDateAggregationType.allInstances;
} }
public static valueOf(type: number): ChartDateAggregationType { public static valueOf(type: number): ChartDateAggregationType | undefined {
return ChartDateAggregationType.allInstancesByType[type]; return ChartDateAggregationType.allInstancesByType[type];
} }
} }
+2 -2
View File
@@ -30,7 +30,7 @@ export class TemplateType implements TypeAndName {
return TemplateType.allInstancesByTypeName; return TemplateType.allInstancesByTypeName;
} }
public static valueOf(type: number): TemplateType { public static valueOf(type: number): TemplateType | undefined {
return TemplateType.allInstancesByType[type]; return TemplateType.allInstancesByType[type];
} }
} }
@@ -66,7 +66,7 @@ export class ScheduledTemplateFrequencyType implements TypeAndName {
return ScheduledTemplateFrequencyType.allInstancesByTypeName; return ScheduledTemplateFrequencyType.allInstancesByTypeName;
} }
public static valueOf(type: number): ScheduledTemplateFrequencyType { public static valueOf(type: number): ScheduledTemplateFrequencyType | undefined {
return ScheduledTemplateFrequencyType.allInstancesByType[type]; return ScheduledTemplateFrequencyType.allInstancesByType[type];
} }
} }
+2 -2
View File
@@ -237,12 +237,12 @@ export function getDay(date: SupportedDate): number {
export function getDayOfWeekName(date: SupportedDate): string { export function getDayOfWeekName(date: SupportedDate): string {
const dayOfWeek = moment(date).days(); const dayOfWeek = moment(date).days();
return WeekDay.valueOf(dayOfWeek).name; return (WeekDay.valueOf(dayOfWeek) as WeekDay).name;
} }
export function getMonthName(date: SupportedDate): string { export function getMonthName(date: SupportedDate): string {
const month = moment(date).month(); const month = moment(date).month();
return Month.valueOf(month + 1).name; return (Month.valueOf(month + 1) as Month).name;
} }
export function getAMOrPM(hour: number): string { export function getAMOrPM(hour: number): string {
+13 -13
View File
@@ -328,8 +328,8 @@ export function useI18n() {
return ret; return ret;
} }
function getLocalizedNumeralSeparatorFormats<T extends NumeralSymbolType>(allSeparatorArray: T[], localeDefaultType: T, systemDefaultType: T, languageDefaultValue: number): LocalizedNumeralSymbolType[] { function getLocalizedNumeralSeparatorFormats<T extends NumeralSymbolType>(allSeparatorArray: T[], localeDefaultType: T | undefined, systemDefaultType: T, languageDefaultValue: number): LocalizedNumeralSymbolType[] {
let defaultSeparatorType: T = localeDefaultType; let defaultSeparatorType: T | undefined = localeDefaultType;
if (!defaultSeparatorType) { if (!defaultSeparatorType) {
defaultSeparatorType = systemDefaultType; defaultSeparatorType = systemDefaultType;
@@ -431,10 +431,10 @@ export function useI18n() {
function getNumberFormatOptions(currencyCode?: string): NumberFormatOptions { function getNumberFormatOptions(currencyCode?: string): NumberFormatOptions {
return { return {
decimalSeparator: getCurrentDecimalSeparator(userStore.currentUserDecimalSeparator), decimalSeparator: getCurrentDecimalSeparator(),
decimalNumberCount: getCurrencyFraction(currencyCode), decimalNumberCount: getCurrencyFraction(currencyCode),
digitGroupingSymbol: getCurrentDigitGroupingSymbol(userStore.currentUserDigitGroupingSymbol), digitGroupingSymbol: getCurrentDigitGroupingSymbol(),
digitGrouping: getCurrentDigitGroupingType(userStore.currentUserDigitGrouping), digitGrouping: getCurrentDigitGroupingType(),
}; };
} }
@@ -803,8 +803,8 @@ export function useI18n() {
return joinMultiText(finalWeekdayNames); return joinMultiText(finalWeekdayNames);
} }
function getCurrentDecimalSeparator(decimalSeparator: number): string { function getCurrentDecimalSeparator(): string {
let decimalSeparatorType = DecimalSeparator.valueOf(decimalSeparator); let decimalSeparatorType = DecimalSeparator.valueOf(userStore.currentUserDecimalSeparator);
if (!decimalSeparatorType) { if (!decimalSeparatorType) {
const defaultDecimalSeparatorTypeName = t('default.decimalSeparator'); const defaultDecimalSeparatorTypeName = t('default.decimalSeparator');
@@ -818,8 +818,8 @@ export function useI18n() {
return decimalSeparatorType.symbol; return decimalSeparatorType.symbol;
} }
function getCurrentDigitGroupingSymbol(digitGroupingSymbol: number): string { function getCurrentDigitGroupingSymbol(): string {
let digitGroupingSymbolType = DigitGroupingSymbol.valueOf(digitGroupingSymbol); let digitGroupingSymbolType = DigitGroupingSymbol.valueOf(userStore.currentUserDigitGroupingSymbol);
if (!digitGroupingSymbolType) { if (!digitGroupingSymbolType) {
const defaultDigitGroupingSymbolTypeName = t('default.digitGroupingSymbol'); const defaultDigitGroupingSymbolTypeName = t('default.digitGroupingSymbol');
@@ -833,8 +833,8 @@ export function useI18n() {
return digitGroupingSymbolType.symbol; return digitGroupingSymbolType.symbol;
} }
function getCurrentDigitGroupingType(digitGrouping: number): number { function getCurrentDigitGroupingType(): number {
let digitGroupingType = DigitGroupingType.valueOf(digitGrouping); let digitGroupingType = DigitGroupingType.valueOf(userStore.currentUserDigitGrouping);
if (!digitGroupingType) { if (!digitGroupingType) {
const defaultDigitGroupingTypeName = t('default.digitGrouping'); const defaultDigitGroupingTypeName = t('default.digitGrouping');
@@ -897,7 +897,7 @@ export function useI18n() {
return parseAmount(value, numberFormatOptions); return parseAmount(value, numberFormatOptions);
} }
function getFormattedAmount(value: number | string, currencyCode: string): string { function getFormattedAmount(value: number | string, currencyCode?: string): string {
const numberFormatOptions = getNumberFormatOptions(currencyCode); const numberFormatOptions = getNumberFormatOptions(currencyCode);
return formatAmount(value, numberFormatOptions); return formatAmount(value, numberFormatOptions);
} }
@@ -1007,7 +1007,7 @@ export function useI18n() {
let defaultFirstDayOfWeek = WeekDay.DefaultFirstDay.type; let defaultFirstDayOfWeek = WeekDay.DefaultFirstDay.type;
if (WeekDay.parse(defaultFirstDayOfWeekName)) { if (WeekDay.parse(defaultFirstDayOfWeekName)) {
defaultFirstDayOfWeek = WeekDay.parse(defaultFirstDayOfWeekName).type; defaultFirstDayOfWeek = (WeekDay.parse(defaultFirstDayOfWeekName) as WeekDay).type;
} }
return { return {