mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 09:44:26 +08:00
code refactor
This commit is contained in:
@@ -74,7 +74,7 @@ export function usePieChartBase(props: CommonPieChartProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
finalItem.displayPercent = formatPercent(finalItem.percent, 2, '<0.01');
|
finalItem.displayPercent = formatPercent(finalItem.percent, 2, '<0.01');
|
||||||
finalItem.displayValue = formatAmountWithCurrency(finalItem.value, props.defaultCurrency) as string;
|
finalItem.displayValue = formatAmountWithCurrency(finalItem.value, props.defaultCurrency);
|
||||||
|
|
||||||
validItems.push(finalItem);
|
validItems.push(finalItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,8 +238,8 @@ const yAxisWidth = computed<number>(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxValueText = formatAmountWithCurrency(maxValue, props.defaultCurrency) || '';
|
const maxValueText = formatAmountWithCurrency(maxValue, props.defaultCurrency);
|
||||||
const minValueText = formatAmountWithCurrency(minValue, props.defaultCurrency) || '';
|
const minValueText = formatAmountWithCurrency(minValue, props.defaultCurrency);
|
||||||
const maxLengthText = maxValueText.length > minValueText.length ? maxValueText : minValueText;
|
const maxLengthText = maxValueText.length > minValueText.length ? maxValueText : minValueText;
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
|
|||||||
+2
-6
@@ -1,7 +1,7 @@
|
|||||||
import { CurrencyDisplaySymbol, CurrencyDisplayLocation, type CurrencyPrependAndAppendText, CurrencyDisplayType } from '@/core/currency.ts';
|
import { CurrencyDisplaySymbol, CurrencyDisplayLocation, type CurrencyPrependAndAppendText, CurrencyDisplayType } from '@/core/currency.ts';
|
||||||
import { ALL_CURRENCIES, DEFAULT_CURRENCY_SYMBOL } from '@/consts/currency.ts';
|
import { ALL_CURRENCIES, DEFAULT_CURRENCY_SYMBOL } from '@/consts/currency.ts';
|
||||||
|
|
||||||
import { isString, isNumber } from './common.ts';
|
import { isNumber } from './common.ts';
|
||||||
|
|
||||||
export function getCurrencyFraction(currencyCode?: string): number | undefined {
|
export function getCurrencyFraction(currencyCode?: string): number | undefined {
|
||||||
if (!currencyCode) {
|
if (!currencyCode) {
|
||||||
@@ -12,15 +12,11 @@ export function getCurrencyFraction(currencyCode?: string): number | undefined {
|
|||||||
return currencyInfo?.fraction;
|
return currencyInfo?.fraction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function appendCurrencySymbol(value: unknown, currencyDisplayType: CurrencyDisplayType, currencyCode: string, currencyUnit: string, currencyName: string, isPlural: boolean): string | null {
|
export function appendCurrencySymbol(value: number | string, currencyDisplayType: CurrencyDisplayType, currencyCode: string, currencyUnit: string, currencyName: string, isPlural: boolean): string {
|
||||||
if (isNumber(value)) {
|
if (isNumber(value)) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isString(value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const symbol = getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyUnit, currencyName, isPlural);
|
const symbol = getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyUnit, currencyName, isPlural);
|
||||||
|
|
||||||
if (!symbol) {
|
if (!symbol) {
|
||||||
|
|||||||
@@ -1318,11 +1318,7 @@ export function useI18n() {
|
|||||||
return formatAmount(value, numberFormatOptions);
|
return formatAmount(value, numberFormatOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFormattedAmountWithCurrency(value: number | string, currencyCode?: string | false, notConvertValue?: boolean, currencyDisplayType?: CurrencyDisplayType): string | null {
|
function getFormattedAmountWithCurrency(value: number | string, currencyCode?: string | false, notConvertValue?: boolean, currencyDisplayType?: CurrencyDisplayType): string {
|
||||||
if (!isNumber(value) && !isString(value)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNumber(value)) {
|
if (isNumber(value)) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
}
|
}
|
||||||
@@ -1407,9 +1403,9 @@ export function useI18n() {
|
|||||||
let accountWithDisplaceBalance: AccountWithDisplayBalance;
|
let accountWithDisplaceBalance: AccountWithDisplayBalance;
|
||||||
|
|
||||||
if (showAccountBalance && account.isAsset) {
|
if (showAccountBalance && account.isAsset) {
|
||||||
accountWithDisplaceBalance = AccountWithDisplayBalance.fromAccount(account, getFormattedAmountWithCurrency(account.balance, account.currency) as string);
|
accountWithDisplaceBalance = AccountWithDisplayBalance.fromAccount(account, getFormattedAmountWithCurrency(account.balance, account.currency));
|
||||||
} else if (showAccountBalance && account.isLiability) {
|
} else if (showAccountBalance && account.isLiability) {
|
||||||
accountWithDisplaceBalance = AccountWithDisplayBalance.fromAccount(account, getFormattedAmountWithCurrency(-account.balance, account.currency) as string);
|
accountWithDisplaceBalance = AccountWithDisplayBalance.fromAccount(account, getFormattedAmountWithCurrency(-account.balance, account.currency));
|
||||||
} else {
|
} else {
|
||||||
accountWithDisplaceBalance = AccountWithDisplayBalance.fromAccount(account, '***');
|
accountWithDisplaceBalance = AccountWithDisplayBalance.fromAccount(account, '***');
|
||||||
}
|
}
|
||||||
@@ -1454,7 +1450,7 @@ export function useI18n() {
|
|||||||
finalTotalBalance = finalTotalBalance + '+';
|
finalTotalBalance = finalTotalBalance + '+';
|
||||||
}
|
}
|
||||||
|
|
||||||
finalTotalBalance = getFormattedAmountWithCurrency(finalTotalBalance, defaultCurrency) as string;
|
finalTotalBalance = getFormattedAmountWithCurrency(finalTotalBalance, defaultCurrency);
|
||||||
} else {
|
} else {
|
||||||
finalTotalBalance = '***';
|
finalTotalBalance = '***';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,17 +38,17 @@ export function useHomePageBase() {
|
|||||||
|
|
||||||
const netAssets = computed<string>(() => {
|
const netAssets = computed<string>(() => {
|
||||||
const netAssets = accountsStore.getNetAssets(showAmountInHomePage.value);
|
const netAssets = accountsStore.getNetAssets(showAmountInHomePage.value);
|
||||||
return formatAmountWithCurrency(netAssets, defaultCurrency.value) as string;
|
return formatAmountWithCurrency(netAssets, defaultCurrency.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalAssets = computed<string>(() => {
|
const totalAssets = computed<string>(() => {
|
||||||
const totalAssets = accountsStore.getTotalAssets(showAmountInHomePage.value);
|
const totalAssets = accountsStore.getTotalAssets(showAmountInHomePage.value);
|
||||||
return formatAmountWithCurrency(totalAssets, defaultCurrency.value) as string;
|
return formatAmountWithCurrency(totalAssets, defaultCurrency.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalLiabilities = computed<string>(() => {
|
const totalLiabilities = computed<string>(() => {
|
||||||
const totalLiabilities = accountsStore.getTotalLiabilities(showAmountInHomePage.value);
|
const totalLiabilities = accountsStore.getTotalLiabilities(showAmountInHomePage.value);
|
||||||
return formatAmountWithCurrency(totalLiabilities, defaultCurrency.value) as string;
|
return formatAmountWithCurrency(totalLiabilities, defaultCurrency.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const displayDateRange = computed<TransactionOverviewDisplayTime>(() => {
|
const displayDateRange = computed<TransactionOverviewDisplayTime>(() => {
|
||||||
@@ -75,7 +75,7 @@ export function useHomePageBase() {
|
|||||||
|
|
||||||
function getDisplayAmount(amount: number, incomplete: boolean): string {
|
function getDisplayAmount(amount: number, incomplete: boolean): string {
|
||||||
if (!showAmountInHomePage.value) {
|
if (!showAmountInHomePage.value) {
|
||||||
return formatAmountWithCurrency('***', defaultCurrency.value) as string;
|
return formatAmountWithCurrency('***', defaultCurrency.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatAmountWithCurrency(amount, defaultCurrency.value) + (incomplete ? '+' : '');
|
return formatAmountWithCurrency(amount, defaultCurrency.value) + (incomplete ? '+' : '');
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export function useStatisticsTransactionPageBase() {
|
|||||||
const trendsAnalysisData = computed<TransactionTrendsAnalysisData | null>(() => statisticsStore.trendsAnalysisData);
|
const trendsAnalysisData = computed<TransactionTrendsAnalysisData | null>(() => statisticsStore.trendsAnalysisData);
|
||||||
|
|
||||||
function getDisplayAmount(amount: number, currency: string, textLimit?: number): string {
|
function getDisplayAmount(amount: number, currency: string, textLimit?: number): string {
|
||||||
const finalAmount = formatAmountWithCurrency(amount, currency) as string;
|
const finalAmount = formatAmountWithCurrency(amount, currency);
|
||||||
|
|
||||||
if (!showAccountBalance.value
|
if (!showAccountBalance.value
|
||||||
&& (query.value.chartDataType === ChartDataType.AccountTotalAssets.type
|
&& (query.value.chartDataType === ChartDataType.AccountTotalAssets.type
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ const chartOptions = computed<object>(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function getDisplayCurrency(value: number | string, currencyCode: string): string {
|
function getDisplayCurrency(value: number | string, currencyCode: string): string {
|
||||||
return formatAmountWithCurrency(value, currencyCode) || '0';
|
return formatAmountWithCurrency(value, currencyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDisplayAmount(amount: number, incomplete: boolean): string {
|
function getDisplayAmount(amount: number, incomplete: boolean): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user