code refactor

This commit is contained in:
MaysWind
2023-07-02 00:51:26 +08:00
parent 4e8f530fbb
commit 9adfd286f9
17 changed files with 139 additions and 67 deletions
+7 -3
View File
@@ -78,6 +78,7 @@
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
@@ -102,7 +103,10 @@ export default {
};
},
computed: {
...mapStores(useUserStore, useExchangeRatesStore),
...mapStores(useSettingsStore, useUserStore, useExchangeRatesStore),
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
exchangeRatesData() {
return this.exchangeRatesStore.latestExchangeRates.data;
},
@@ -196,7 +200,7 @@ export default {
const rateStr = this.getConvertedAmount(toExchangeRate).toString();
if (rateStr.indexOf('.') < 0) {
return appendThousandsSeparator(rateStr);
return appendThousandsSeparator(rateStr, this.isEnableThousandsSeparator);
} else {
let firstNonZeroPos = 0;
@@ -208,7 +212,7 @@ export default {
}
const trimmedRateStr = rateStr.substring(0, Math.max(6, Math.max(firstNonZeroPos, rateStr.indexOf('.') + 2)));
return appendThousandsSeparator(trimmedRateStr);
return appendThousandsSeparator(trimmedRateStr, this.isEnableThousandsSeparator);
}
}
}
+8 -8
View File
@@ -151,12 +151,6 @@ export default {
this.settingsStore.setShowAmountInHomePage(value);
}
},
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
currencyDisplayMode() {
return this.settingsStore.appSettings.currencyDisplayMode;
},
defaultCurrency() {
return this.userStore.currentUserDefaultCurrency;
},
@@ -218,12 +212,18 @@ export default {
}
});
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
getDisplayAmount(amount, incomplete) {
if (!this.showAmountInHomePage) {
return this.$locale.getDisplayCurrency('***', this.defaultCurrency);
return this.getDisplayCurrency('***', this.defaultCurrency);
}
return this.$locale.getDisplayCurrency(amount, this.defaultCurrency) + (incomplete ? '+' : '');
return this.getDisplayCurrency(amount, this.defaultCurrency) + (incomplete ? '+' : '');
},
getDisplayIncomeAmount(category) {
return this.getDisplayAmount(category.incomeAmount, category.incompleteIncomeAmount);
@@ -143,6 +143,7 @@
<script>
import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/index.js';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import {appendThousandsSeparator, isEquals} from '@/lib/common.js';
@@ -182,7 +183,10 @@ export default {
}
},
computed: {
...mapStores(useRootStore, useUserStore),
...mapStores(useRootStore, useSettingsStore, useUserStore),
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
displayDataStatistics() {
const self = this;
@@ -191,10 +195,10 @@ export default {
}
return {
totalAccountCount: appendThousandsSeparator(self.dataStatistics.totalAccountCount),
totalTransactionCategoryCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCategoryCount),
totalTransactionTagCount: appendThousandsSeparator(self.dataStatistics.totalTransactionTagCount),
totalTransactionCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCount)
totalAccountCount: appendThousandsSeparator(self.dataStatistics.totalAccountCount, self.isEnableThousandsSeparator),
totalTransactionCategoryCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCategoryCount, self.isEnableThousandsSeparator),
totalTransactionTagCount: appendThousandsSeparator(self.dataStatistics.totalTransactionTagCount, self.isEnableThousandsSeparator),
totalTransactionCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCount, self.isEnableThousandsSeparator)
};
},
isDataExportingEnabled() {
+13 -5
View File
@@ -91,12 +91,17 @@
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import transactionConstants from '@/consts/transaction.js';
import { isNumber, appendThousandsSeparator } from '@/lib/common.js';
import { stringCurrencyToNumeric, getExchangedAmount } from '@/lib/currency.js';
import {
numericCurrencyToString,
stringCurrencyToNumeric,
getExchangedAmount,
} from '@/lib/currency.js';
export default {
data() {
@@ -111,7 +116,10 @@ export default {
};
},
computed: {
...mapStores(useUserStore, useExchangeRatesStore),
...mapStores(useSettingsStore, useUserStore, useExchangeRatesStore),
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
exchangeRatesData() {
return this.exchangeRatesStore.latestExchangeRates.data;
},
@@ -143,7 +151,7 @@ export default {
return availableExchangeRates;
},
displayBaseAmount() {
return this.$locale.getDisplayCurrency(this.baseAmount);
return numericCurrencyToString(this.baseAmount, this.isEnableThousandsSeparator);
},
baseAmountFontSizeClass() {
if (this.baseAmount >= 100000000 || this.baseAmount <= -100000000) {
@@ -231,7 +239,7 @@ export default {
const rateStr = this.getConvertedAmount(toExchangeRate).toString();
if (rateStr.indexOf('.') < 0) {
return appendThousandsSeparator(rateStr);
return appendThousandsSeparator(rateStr, this.isEnableThousandsSeparator);
} else {
let firstNonZeroPos = 0;
@@ -243,7 +251,7 @@ export default {
}
const trimmedRateStr = rateStr.substring(0, Math.max(6, Math.max(firstNonZeroPos, rateStr.indexOf('.') + 2)));
return appendThousandsSeparator(trimmedRateStr);
return appendThousandsSeparator(trimmedRateStr, this.isEnableThousandsSeparator);
}
},
setAsBaseline(currency, amount) {
+8 -8
View File
@@ -212,12 +212,6 @@ export default {
this.settingsStore.setShowAmountInHomePage(value);
}
},
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
currencyDisplayMode() {
return this.settingsStore.appSettings.currencyDisplayMode;
},
defaultCurrency() {
return this.userStore.currentUserDefaultCurrency;
},
@@ -301,12 +295,18 @@ export default {
}
});
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
getDisplayAmount(amount, incomplete) {
if (!this.showAmountInHomePage) {
return this.$locale.getDisplayCurrency('***', this.defaultCurrency);
return this.getDisplayCurrency('***', this.defaultCurrency);
}
return this.$locale.getDisplayCurrency(amount, this.defaultCurrency) + (incomplete ? '+' : '');
return this.getDisplayCurrency(amount, this.defaultCurrency) + (incomplete ? '+' : '');
},
getDisplayIncomeAmount(category) {
return this.getDisplayAmount(category.incomeAmount, category.incompleteIncomeAmount);
+9 -2
View File
@@ -421,6 +421,7 @@
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { useAccountsStore } from '@/stores/account.js';
@@ -467,7 +468,7 @@ export default {
};
},
computed: {
...mapStores(useUserStore, useAccountsStore),
...mapStores(useSettingsStore, useUserStore, useAccountsStore),
title() {
if (!this.editAccountId) {
return 'Add Account';
@@ -720,7 +721,13 @@ export default {
return this.$t(categoryName);
},
getAccountBalance(account) {
return this.$locale.getDisplayCurrency(account.balance, account.currency)
return this.getDisplayCurrency(account.balance, account.currency);
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
chooseSuitableIcon(oldCategory, newCategory) {
for (let i = 0; i < this.allAccountCategories.length; i++) {
+11 -5
View File
@@ -223,15 +223,15 @@ export default {
},
netAssets() {
const netAssets = this.accountsStore.getNetAssets(this.showAccountBalance);
return this.$locale.getDisplayCurrency(netAssets, this.defaultCurrency);
return this.getDisplayCurrency(netAssets, this.defaultCurrency);
},
totalAssets() {
const totalAssets = this.accountsStore.getTotalAssets(this.showAccountBalance);
return this.$locale.getDisplayCurrency(totalAssets, this.defaultCurrency);
return this.getDisplayCurrency(totalAssets, this.defaultCurrency);
},
totalLiabilities() {
const totalLiabilities = this.accountsStore.getTotalLiabilities(this.showAccountBalance);
return this.$locale.getDisplayCurrency(totalLiabilities, this.defaultCurrency);
return this.getDisplayCurrency(totalLiabilities, this.defaultCurrency);
},
showAccountBalance: {
get: function () {
@@ -305,11 +305,11 @@ export default {
},
accountBalance(account) {
const balance = this.accountsStore.getAccountBalance(this.showAccountBalance, account);
return this.$locale.getDisplayCurrency(balance, account.currency);
return this.getDisplayCurrency(balance, account.currency);
},
accountCategoryTotalBalance(accountCategory) {
const totalBalance = this.accountsStore.getAccountCategoryTotalBalance(this.showAccountBalance, accountCategory);
return this.$locale.getDisplayCurrency(totalBalance, this.defaultCurrency);
return this.getDisplayCurrency(totalBalance, this.defaultCurrency);
},
setSortable() {
if (this.sortable) {
@@ -427,6 +427,12 @@ export default {
}
});
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
getAccountDomId(account) {
return 'account_' + account.id;
},
@@ -164,7 +164,10 @@ export default {
return '';
},
getDisplayAmount(value) {
return this.$locale.getDisplayCurrency(value, this.userStore.currentUserDefaultCurrency);
return this.$locale.getDisplayCurrency(value, this.userStore.currentUserDefaultCurrency, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
}
}
}
@@ -714,7 +714,7 @@ export default {
container.scrollTop(targetPos);
},
getDisplayAmount(amount, currency, textLimit) {
amount = this.$locale.getDisplayCurrency(amount, currency);
amount = this.getDisplayCurrency(amount, currency);
if (!this.showAccountBalance
&& (this.query.chartDataType === this.allChartDataTypes.AccountTotalAssets.type
@@ -729,6 +729,12 @@ export default {
return amount;
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
getDisplayPercent(value, precision, lowPrecisionValue) {
return formatPercent(value, precision, lowPrecisionValue);
},
+11 -5
View File
@@ -503,9 +503,9 @@ export default {
const account = accountCategory.accounts[i];
if (this.showAccountBalance && account.isAsset) {
account.displayBalance = this.$locale.getDisplayCurrency(account.balance, account.currency);
account.displayBalance = this.getDisplayCurrency(account.balance, account.currency);
} else if (this.showAccountBalance && account.isLiability) {
account.displayBalance = this.$locale.getDisplayCurrency(-account.balance, account.currency);
account.displayBalance = this.getDisplayCurrency(-account.balance, account.currency);
} else {
account.displayBalance = '***';
}
@@ -544,7 +544,7 @@ export default {
totalBalance = totalBalance + '+';
}
accountCategory.displayBalance = this.$locale.getDisplayCurrency(totalBalance, this.defaultCurrency);
accountCategory.displayBalance = this.getDisplayCurrency(totalBalance, this.defaultCurrency);
} else {
accountCategory.displayBalance = '***';
}
@@ -1067,10 +1067,16 @@ export default {
},
getDisplayAmount(amount, hideAmount) {
if (hideAmount) {
return this.$locale.getDisplayCurrency('***');
return this.getDisplayCurrency('***');
}
return this.$locale.getDisplayCurrency(amount);
return this.getDisplayCurrency(amount);
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
getPrimaryCategoryName(categoryId, allCategories) {
return getTransactionPrimaryCategoryName(categoryId, allCategories);
+9 -3
View File
@@ -842,15 +842,21 @@ export default {
},
getDisplayAmount(amount, currency, hideAmount) {
if (hideAmount) {
return this.$locale.getDisplayCurrency('***', currency);
return this.getDisplayCurrency('***', currency);
}
return this.$locale.getDisplayCurrency(amount, currency);
return this.getDisplayCurrency(amount, currency);
},
getDisplayMonthTotalAmount(amount, currency, symbol, incomplete) {
const displayAmount = this.$locale.getDisplayCurrency(amount, currency);
const displayAmount = this.getDisplayCurrency(amount, currency);
return symbol + displayAmount + (incomplete ? '+' : '');
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
},
getTransactionTypeName(type, defaultName) {
switch (type){
case this.allTransactionTypes.ModifyBalance:
@@ -58,6 +58,7 @@
<script>
import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/index.js';
import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from '@/stores/user.js';
import { appendThousandsSeparator } from '@/lib/common.js';
@@ -81,7 +82,10 @@ export default {
};
},
computed: {
...mapStores(useRootStore, useUserStore),
...mapStores(useRootStore, useSettingsStore, useUserStore),
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
displayDataStatistics() {
const self = this;
@@ -90,10 +94,10 @@ export default {
}
return {
totalAccountCount: appendThousandsSeparator(self.dataStatistics.totalAccountCount),
totalTransactionCategoryCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCategoryCount),
totalTransactionTagCount: appendThousandsSeparator(self.dataStatistics.totalTransactionTagCount),
totalTransactionCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCount)
totalAccountCount: appendThousandsSeparator(self.dataStatistics.totalAccountCount, self.isEnableThousandsSeparator),
totalTransactionCategoryCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCategoryCount, self.isEnableThousandsSeparator),
totalTransactionTagCount: appendThousandsSeparator(self.dataStatistics.totalTransactionTagCount, self.isEnableThousandsSeparator),
totalTransactionCount: appendThousandsSeparator(self.dataStatistics.totalTransactionCount, self.isEnableThousandsSeparator)
};
},
isDataExportingEnabled() {