migrate to typescript

This commit is contained in:
MaysWind
2024-12-29 14:24:37 +08:00
parent b638a73e4d
commit 2560a70e5e
171 changed files with 3402 additions and 2557 deletions
+19 -20
View File
@@ -29,8 +29,8 @@
</div>
<v-divider />
<v-tabs show-arrows class="account-category-tabs my-4" direction="vertical"
:disabled="loading" v-model="activeAccountCategoryId">
<v-tab class="tab-text-truncate" :key="accountCategory.id" :value="accountCategory.id"
:disabled="loading" v-model="activeAccountCategoryType">
<v-tab class="tab-text-truncate" :key="accountCategory.type" :value="accountCategory.type"
v-for="accountCategory in allAccountCategories">
<ItemIcon icon-type="account" :icon-id="accountCategory.defaultAccountIconId" />
<div class="d-flex flex-column text-truncate ml-2">
@@ -146,8 +146,8 @@
handle=".drag-handle"
ghost-class="dragging-item"
:disabled="activeAccountCategoryVisibleAccountCount <= 1"
:list="allCategorizedAccountsMap[activeAccountCategory.id].accounts"
v-if="allCategorizedAccountsMap[activeAccountCategory.id] && allCategorizedAccountsMap[activeAccountCategory.id].accounts && allCategorizedAccountsMap[activeAccountCategory.id].accounts.length"
:list="allCategorizedAccountsMap[activeAccountCategory.type].accounts"
v-if="allCategorizedAccountsMap[activeAccountCategory.type] && allCategorizedAccountsMap[activeAccountCategory.type].accounts && allCategorizedAccountsMap[activeAccountCategory.type].accounts.length"
@change="onMove"
>
<template #item="{ element }">
@@ -169,7 +169,7 @@
</span>
</div>
<div class="mt-4" v-if="element.type === allAccountTypes.MultiSubAccounts">
<div class="mt-4" v-if="element.type === allAccountTypes.MultiSubAccounts.type">
<v-btn-toggle
class="account-subaccounts"
variant="outlined"
@@ -265,10 +265,9 @@ import { useUserStore } from '@/stores/user.js';
import { useAccountsStore } from '@/stores/account.js';
import { useExchangeRatesStore } from '@/stores/exchangeRates.js';
import accountConstants from '@/consts/account.js';
import { isObject } from '@/lib/common.js';
import { AccountType, AccountCategory } from '@/core/account.ts';
import { isObject } from '@/lib/common.ts';
import {
getAccountCategoryInfo,
getSubAccountCurrencies,
getAccountOrSubAccountId,
getAccountOrSubAccountComment
@@ -295,7 +294,7 @@ export default {
const { mdAndUp } = useDisplay();
return {
activeAccountCategoryId: accountConstants.allCategories[0].id,
activeAccountCategoryType: AccountCategory.Default.type,
activeTab: 'accountPage',
activeSubAccount: {},
loading: true,
@@ -325,10 +324,10 @@ export default {
return this.userStore.currentUserDefaultCurrency;
},
allAccountTypes() {
return accountConstants.allAccountTypes;
return AccountType.all();
},
allAccountCategories() {
return accountConstants.allCategories;
return AccountCategory.values();
},
allAccounts() {
return this.accountsStore.allAccounts;
@@ -352,17 +351,17 @@ export default {
return this.getDisplayCurrency(totalLiabilities, this.defaultCurrency);
},
activeAccountCategory() {
return getAccountCategoryInfo(this.activeAccountCategoryId);
return AccountCategory.valueOf(this.activeAccountCategoryType);
},
activeAccountCategoryTotalBalance() {
return this.accountCategoryTotalBalance(this.activeAccountCategory);
},
activeAccountCategoryVisibleAccountCount() {
if (!this.allCategorizedAccountsMap[this.activeAccountCategory.id] || !this.allCategorizedAccountsMap[this.activeAccountCategory.id].accounts) {
if (!this.allCategorizedAccountsMap[this.activeAccountCategory.type] || !this.allCategorizedAccountsMap[this.activeAccountCategory.type].accounts) {
return 0;
}
const accounts = this.allCategorizedAccountsMap[this.activeAccountCategory.id].accounts;
const accounts = this.allCategorizedAccountsMap[this.activeAccountCategory.type].accounts;
if (this.showHidden) {
return accounts.length;
@@ -422,7 +421,7 @@ export default {
for (let i = 0; i < self.allAccounts.length; i++) {
const account = self.allAccounts[i];
if (account.type === self.allAccountTypes.MultiSubAccounts && !self.activeSubAccount[account.id]) {
if (account.type === self.allAccountTypes.MultiSubAccounts.type && !self.activeSubAccount[account.id]) {
self.activeSubAccount[account.id] = '';
}
}
@@ -459,9 +458,9 @@ export default {
accountCurrency(account) {
const self = this;
if (account.type === self.allAccountTypes.SingleAccount) {
if (account.type === self.allAccountTypes.SingleAccount.type) {
return self.$locale.getCurrencyName(account.currency);
} else if (account.type === self.allAccountTypes.MultiSubAccounts) {
} else if (account.type === self.allAccountTypes.MultiSubAccounts.type) {
const subAccountCurrencies = getSubAccountCurrencies(account, self.showHidden, self.activeSubAccount[account.id])
.map(currencyCode => self.$locale.getCurrencyName(currencyCode));
return self.$locale.joinMultiText(subAccountCurrencies);
@@ -470,10 +469,10 @@ export default {
}
},
accountBalance(account) {
if (account.type === this.allAccountTypes.SingleAccount) {
if (account.type === this.allAccountTypes.SingleAccount.type) {
const balance = this.accountsStore.getAccountBalance(this.showAccountBalance, account);
return this.getDisplayCurrency(balance, account.currency);
} else if (account.type === this.allAccountTypes.MultiSubAccounts) {
} else if (account.type === this.allAccountTypes.MultiSubAccounts.type) {
const balanceResult = this.accountsStore.getAccountSubAccountBalance(this.showAccountBalance, this.showHidden, account, this.activeSubAccount[account.id]);
if (!isObject(balanceResult)) {
@@ -538,7 +537,7 @@ export default {
const self = this;
self.$refs.editDialog.open({
category: self.activeAccountCategoryId
category: self.activeAccountCategoryType
}).then(result => {
if (result && result.message) {
self.$refs.snackbar.showMessage(result.message);
@@ -1,5 +1,5 @@
<template>
<v-dialog :width="account.type === allAccountTypes.MultiSubAccounts ? 1000 : 800" :persistent="!!persistent" v-model="showState">
<v-dialog :width="account.type === allAccountTypes.MultiSubAccounts.type ? 1000 : 800" :persistent="!!persistent" v-model="showState">
<v-card class="pa-2 pa-sm-4 pa-md-8">
<template #title>
<div class="d-flex align-center justify-center">
@@ -8,7 +8,7 @@
<v-progress-circular indeterminate size="22" class="ml-2" v-if="loading"></v-progress-circular>
</div>
<v-btn density="comfortable" color="default" variant="text" class="ml-2" :icon="true"
:disabled="loading || submitting || !!editAccountId || account.type !== allAccountTypes.MultiSubAccounts">
:disabled="loading || submitting || !!editAccountId || account.type !== allAccountTypes.MultiSubAccounts.type">
<v-icon :icon="icons.more" />
<v-menu activator="parent">
<v-list>
@@ -21,12 +21,12 @@
</div>
</template>
<v-card-text class="d-flex flex-column flex-md-row mt-md-4 pt-0">
<div class="mb-4" v-if="account.type === allAccountTypes.MultiSubAccounts">
<div class="mb-4" v-if="account.type === allAccountTypes.MultiSubAccounts.type">
<v-tabs direction="vertical" :disabled="loading || submitting" v-model="currentAccountIndex">
<v-tab :value="-1">
<span>{{ $t('Main Account') }}</span>
</v-tab>
<template v-if="account.type === allAccountTypes.MultiSubAccounts">
<template v-if="account.type === allAccountTypes.MultiSubAccounts.type">
<v-tab :key="idx" :value="idx" v-for="(subAccount, idx) in subAccounts">
<span>{{ $t('Sub Account') + ' #' + (idx + 1) }}</span>
<v-btn class="ml-2" color="error" size="24" variant="text"
@@ -38,15 +38,15 @@
</div>
<v-window class="d-flex flex-grow-1 disable-tab-transition w-100-window-container"
:class="{ 'ml-md-5': account.type === allAccountTypes.MultiSubAccounts }"
:class="{ 'ml-md-5': account.type === allAccountTypes.MultiSubAccounts.type }"
v-model="activeTab">
<v-window-item value="account">
<v-form class="mt-2">
<v-row>
<v-col cols="12" md="12" v-if="account.type === allAccountTypes.SingleAccount || currentAccountIndex < 0">
<v-col cols="12" md="12" v-if="account.type === allAccountTypes.SingleAccount.type || currentAccountIndex < 0">
<v-select
item-title="displayName"
item-value="id"
item-value="type"
persistent-placeholder
:disabled="loading || submitting"
:label="$t('Account Category')"
@@ -71,10 +71,10 @@
</template>
</v-select>
</v-col>
<v-col cols="12" md="12" v-if="account.type === allAccountTypes.SingleAccount || currentAccountIndex < 0">
<v-col cols="12" md="12" v-if="account.type === allAccountTypes.SingleAccount.type || currentAccountIndex < 0">
<v-select
item-title="displayName"
item-value="id"
item-value="type"
persistent-placeholder
:disabled="loading || submitting || !!editAccountId"
:label="$t('Account Type')"
@@ -108,7 +108,7 @@
:disabled="loading || submitting"
v-model="selectedAccount.color" />
</v-col>
<v-col cols="12" :md="currentAccountIndex < 0 && isAccountSupportCreditCardStatementDate() ? 6 : 12" v-if="account.type === allAccountTypes.SingleAccount || currentAccountIndex >= 0">
<v-col cols="12" :md="currentAccountIndex < 0 && isAccountSupportCreditCardStatementDate() ? 6 : 12" v-if="account.type === allAccountTypes.SingleAccount.type || currentAccountIndex >= 0">
<v-autocomplete
item-title="displayName"
item-value="currencyCode"
@@ -126,7 +126,7 @@
</template>
</v-autocomplete>
</v-col>
<v-col cols="12" :md="account.type === allAccountTypes.SingleAccount || currentAccountIndex >= 0 ? 6 : 12" v-if="currentAccountIndex < 0 && isAccountSupportCreditCardStatementDate()">
<v-col cols="12" :md="account.type === allAccountTypes.SingleAccount.type || currentAccountIndex >= 0 ? 6 : 12" v-if="currentAccountIndex < 0 && isAccountSupportCreditCardStatementDate()">
<v-autocomplete
item-title="displayName"
item-value="day"
@@ -141,7 +141,7 @@
></v-autocomplete>
</v-col>
<v-col cols="12" :md="!editAccountId && selectedAccount.balance ? 6 : 12"
v-if="account.type === allAccountTypes.SingleAccount || currentAccountIndex >= 0">
v-if="account.type === allAccountTypes.SingleAccount.type || currentAccountIndex >= 0">
<amount-input :disabled="loading || submitting || !!editAccountId"
:persistent-placeholder="true"
:currency="selectedAccount.currency"
@@ -151,7 +151,7 @@
v-model="selectedAccount.balance"/>
</v-col>
<v-col cols="12" md="6" v-show="selectedAccount.balance"
v-if="!editAccountId && (account.type === allAccountTypes.SingleAccount || currentAccountIndex >= 0)">
v-if="!editAccountId && (account.type === allAccountTypes.SingleAccount.type || currentAccountIndex >= 0)">
<date-time-select
:disabled="loading || submitting"
:label="$t('Balance Time')"
@@ -200,11 +200,11 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { useAccountsStore } from '@/stores/account.js';
import accountConstants from '@/consts/account.js';
import iconConstants from '@/consts/icon.js';
import colorConstants from '@/consts/color.js';
import { isNumber } from '@/lib/common.js';
import { generateRandomUUID } from '@/lib/misc.js';
import { AccountType, AccountCategory } from '@/core/account.ts';
import { ALL_ACCOUNT_ICONS } from '@/consts/icon.ts';
import { ALL_ACCOUNT_COLORS } from '@/consts/color.ts';
import { isNumber } from '@/lib/common.ts';
import { generateRandomUUID } from '@/lib/misc.ts';
import {
setAccountModelByAnotherAccount,
setAccountSuitableIcon
@@ -264,7 +264,7 @@ export default {
}
},
allAccountTypes() {
return accountConstants.allAccountTypes;
return AccountType.all();
},
allAccountCategories() {
return this.$locale.getAllAccountCategories();
@@ -273,10 +273,10 @@ export default {
return this.$locale.getAllAccountTypes();
},
allAccountIcons() {
return iconConstants.allAccountIcons;
return ALL_ACCOUNT_ICONS;
},
allAccountColors() {
return colorConstants.allAccountColors;
return ALL_ACCOUNT_COLORS;
},
allCurrencies() {
return this.$locale.getAllCurrencies();
@@ -366,7 +366,7 @@ export default {
});
},
addSubAccount() {
if (this.account.type !== this.allAccountTypes.MultiSubAccounts) {
if (this.account.type !== this.allAccountTypes.MultiSubAccounts.type) {
return;
}
@@ -393,7 +393,7 @@ export default {
let problemMessage = self.getInputEmptyProblemMessage(self.account, false);
if (!problemMessage && self.account.type === self.allAccountTypes.MultiSubAccounts) {
if (!problemMessage && self.account.type === self.allAccountTypes.MultiSubAccounts.type) {
for (let i = 0; i < self.subAccounts.length; i++) {
problemMessage = self.getInputEmptyProblemMessage(self.subAccounts[i], true);
@@ -447,7 +447,7 @@ export default {
this.showState = false;
},
isAccountSupportCreditCardStatementDate() {
return this.account && this.account.category === accountConstants.creditCardCategoryType;
return this.account && this.account.category === AccountCategory.CreditCard.type;
},
chooseSuitableIcon(oldCategory, newCategory) {
setAccountSuitableIcon(this.account, oldCategory, newCategory);
@@ -459,7 +459,7 @@ export default {
return true;
}
if (this.account.type === this.allAccountTypes.MultiSubAccounts) {
if (this.account.type === this.allAccountTypes.MultiSubAccounts.type) {
for (let i = 0; i < this.subAccounts.length; i++) {
const isSubAccountEmpty = !!this.getInputEmptyProblemMessage(this.subAccounts[i], true);
@@ -478,7 +478,7 @@ export default {
return 'Account type cannot be blank';
} else if (!account.name) {
return 'Account name cannot be blank';
} else if (account.type === this.allAccountTypes.SingleAccount && !account.currency) {
} else if (account.type === this.allAccountTypes.SingleAccount.type && !account.currency) {
return 'Account currency cannot be blank';
} else {
return null;