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
+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;
},