mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 09:14:27 +08:00
code refactor
This commit is contained in:
@@ -16,7 +16,6 @@ import {
|
|||||||
} from '@/models/account.ts';
|
} from '@/models/account.ts';
|
||||||
|
|
||||||
import { isNumber, isEquals } from '@/lib/common.ts';
|
import { isNumber, isEquals } from '@/lib/common.ts';
|
||||||
import { getCurrentUnixTime } from '@/lib/datetime.ts';
|
|
||||||
import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.ts';
|
import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.ts';
|
||||||
import services from '@/lib/services.ts';
|
import services from '@/lib/services.ts';
|
||||||
import logger from '@/lib/logger.ts';
|
import logger from '@/lib/logger.ts';
|
||||||
@@ -268,14 +267,6 @@ export const useAccountsStore = defineStore('accounts', () => {
|
|||||||
return shownAccountCount;
|
return shownAccountCount;
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateNewAccountModel(): Account {
|
|
||||||
return Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateNewSubAccountModel(parentAccount: Account): Account {
|
|
||||||
return parentAccount.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAccountListInvalidState(invalidState: boolean): void {
|
function updateAccountListInvalidState(invalidState: boolean): void {
|
||||||
accountListStateInvalid.value = invalidState;
|
accountListStateInvalid.value = invalidState;
|
||||||
}
|
}
|
||||||
@@ -990,8 +981,6 @@ export const useAccountsStore = defineStore('accounts', () => {
|
|||||||
allAvailableAccountsCount,
|
allAvailableAccountsCount,
|
||||||
allVisibleAccountsCount,
|
allVisibleAccountsCount,
|
||||||
// functions
|
// functions
|
||||||
generateNewAccountModel,
|
|
||||||
generateNewSubAccountModel,
|
|
||||||
updateAccountListInvalidState,
|
updateAccountListInvalidState,
|
||||||
resetAccounts,
|
resetAccounts,
|
||||||
getFirstShowingIds,
|
getFirstShowingIds,
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ import { ref, computed, watch } from 'vue';
|
|||||||
|
|
||||||
import { useI18n } from '@/locales/helpers.ts';
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
|
|
||||||
import { useAccountsStore } from '@/stores/account.ts';
|
import { useUserStore } from '@/stores/user.ts';
|
||||||
|
|
||||||
import type { TypeAndDisplayName } from '@/core/base.ts';
|
import type { TypeAndDisplayName } from '@/core/base.ts';
|
||||||
import { AccountCategory, AccountType } from '@/core/account.ts';
|
import { AccountCategory, AccountType } from '@/core/account.ts';
|
||||||
import type { LocalizedCurrencyInfo } from '@/core/currency.ts';
|
import type { LocalizedCurrencyInfo } from '@/core/currency.ts';
|
||||||
import type { LocalizedAccountCategory } from '@/core/account.ts';
|
import type { LocalizedAccountCategory } from '@/core/account.ts';
|
||||||
import type { Account } from '@/models/account.ts';
|
import { Account } from '@/models/account.ts';
|
||||||
|
|
||||||
|
import { getCurrentUnixTime } from '@/lib/datetime.ts';
|
||||||
import { setAccountSuitableIcon } from '@/lib/account.ts';
|
import { setAccountSuitableIcon } from '@/lib/account.ts';
|
||||||
|
|
||||||
export interface DayAndDisplayName {
|
export interface DayAndDisplayName {
|
||||||
@@ -19,13 +20,14 @@ export interface DayAndDisplayName {
|
|||||||
|
|
||||||
export function useAccountEditPageBaseBase() {
|
export function useAccountEditPageBaseBase() {
|
||||||
const { tt, getAllCurrencies, getAllAccountCategories, getAllAccountTypes, getMonthdayShortName } = useI18n();
|
const { tt, getAllCurrencies, getAllAccountCategories, getAllAccountTypes, getMonthdayShortName } = useI18n();
|
||||||
const accountsStore = useAccountsStore();
|
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const editAccountId = ref<string | null>(null);
|
const editAccountId = ref<string | null>(null);
|
||||||
const clientSessionId = ref<string>('');
|
const clientSessionId = ref<string>('');
|
||||||
const loading = ref<boolean>(false);
|
const loading = ref<boolean>(false);
|
||||||
const submitting = ref<boolean>(false);
|
const submitting = ref<boolean>(false);
|
||||||
const account = ref<Account>(accountsStore.generateNewAccountModel());
|
const account = ref<Account>(Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime()));
|
||||||
const subAccounts = ref<Account[]>([]);
|
const subAccounts = ref<Account[]>([]);
|
||||||
|
|
||||||
const title = computed<string>(() => {
|
const title = computed<string>(() => {
|
||||||
@@ -133,7 +135,7 @@ export function useAccountEditPageBaseBase() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const subAccount = accountsStore.generateNewSubAccountModel(account.value);
|
const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||||
subAccounts.value.push(subAccount);
|
subAccounts.value.push(subAccount);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -144,7 +146,7 @@ export function useAccountEditPageBaseBase() {
|
|||||||
|
|
||||||
if (newAccount.childrenAccounts && newAccount.childrenAccounts.length > 0) {
|
if (newAccount.childrenAccounts && newAccount.childrenAccounts.length > 0) {
|
||||||
for (let i = 0; i < newAccount.childrenAccounts.length; i++) {
|
for (let i = 0; i < newAccount.childrenAccounts.length; i++) {
|
||||||
const subAccount = accountsStore.generateNewSubAccountModel(account.value);
|
const subAccount = account.value.createNewSubAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||||
subAccount.from(newAccount.childrenAccounts[i]);
|
subAccount.from(newAccount.childrenAccounts[i]);
|
||||||
|
|
||||||
subAccounts.value.push(subAccount);
|
subAccounts.value.push(subAccount);
|
||||||
|
|||||||
@@ -204,14 +204,16 @@ import { ref, computed, useTemplateRef, watch } from 'vue';
|
|||||||
import { useI18n } from '@/locales/helpers.ts';
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
import { useAccountEditPageBaseBase } from '@/views/base/accounts/AccountEditPageBase.ts';
|
import { useAccountEditPageBaseBase } from '@/views/base/accounts/AccountEditPageBase.ts';
|
||||||
|
|
||||||
|
import { useUserStore } from '@/stores/user.ts';
|
||||||
import { useAccountsStore } from '@/stores/account.ts';
|
import { useAccountsStore } from '@/stores/account.ts';
|
||||||
|
|
||||||
import { AccountType } from '@/core/account.ts';
|
import { AccountType } from '@/core/account.ts';
|
||||||
import { ALL_ACCOUNT_ICONS } from '@/consts/icon.ts';
|
import { ALL_ACCOUNT_ICONS } from '@/consts/icon.ts';
|
||||||
import { ALL_ACCOUNT_COLORS } from '@/consts/color.ts';
|
import { ALL_ACCOUNT_COLORS } from '@/consts/color.ts';
|
||||||
import type { Account } from '@/models/account.ts';
|
import { Account } from '@/models/account.ts';
|
||||||
|
|
||||||
import { isNumber } from '@/lib/common.ts';
|
import { isNumber } from '@/lib/common.ts';
|
||||||
|
import { getCurrentUnixTime } from '@/lib/datetime.ts';
|
||||||
import { generateRandomUUID } from '@/lib/misc.ts';
|
import { generateRandomUUID } from '@/lib/misc.ts';
|
||||||
import { setAccountSuitableIcon } from '@/lib/account.ts';
|
import { setAccountSuitableIcon } from '@/lib/account.ts';
|
||||||
|
|
||||||
@@ -254,6 +256,7 @@ const {
|
|||||||
setAccount
|
setAccount
|
||||||
} = useAccountEditPageBaseBase();
|
} = useAccountEditPageBaseBase();
|
||||||
|
|
||||||
|
const userStore = useUserStore();
|
||||||
const accountsStore = useAccountsStore();
|
const accountsStore = useAccountsStore();
|
||||||
|
|
||||||
const icons = {
|
const icons = {
|
||||||
@@ -285,7 +288,7 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
|
|
||||||
const newAccount = accountsStore.generateNewAccountModel();
|
const newAccount = Account.createNewAccount(userStore.currentUserDefaultCurrency, getCurrentUnixTime());
|
||||||
account.value.from(newAccount);
|
account.value.from(newAccount);
|
||||||
subAccounts.value = [];
|
subAccounts.value = [];
|
||||||
currentAccountIndex.value = -1;
|
currentAccountIndex.value = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user