mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
code refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ref } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
import type { BeforeResolveFunction } from '@/core/base.ts';
|
import type { BeforeResolveFunction } from '@/core/base.ts';
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
} from '@/models/transaction_category.ts';
|
} from '@/models/transaction_category.ts';
|
||||||
|
|
||||||
import { isEquals } from '@/lib/common.ts';
|
import { isEquals } from '@/lib/common.ts';
|
||||||
|
import { getFirstAvailableCategoryId } from '@/lib/category.ts';
|
||||||
import services, { type ApiResponsePromise } from '@/lib/services.ts';
|
import services, { type ApiResponsePromise } from '@/lib/services.ts';
|
||||||
import logger from '@/lib/logger.ts';
|
import logger from '@/lib/logger.ts';
|
||||||
|
|
||||||
@@ -21,6 +22,33 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
|
|||||||
const allTransactionCategoriesMap = ref<Record<string, TransactionCategory>>({});
|
const allTransactionCategoriesMap = ref<Record<string, TransactionCategory>>({});
|
||||||
const transactionCategoryListStateInvalid = ref<boolean>(true);
|
const transactionCategoryListStateInvalid = ref<boolean>(true);
|
||||||
|
|
||||||
|
const hasAvailableExpenseCategories = computed<boolean>(() => {
|
||||||
|
if (!allTransactionCategories.value || !allTransactionCategories.value[CategoryType.Expense] || !allTransactionCategories.value[CategoryType.Expense].length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstAvailableCategoryId = getFirstAvailableCategoryId(allTransactionCategories.value[CategoryType.Expense]);
|
||||||
|
return firstAvailableCategoryId !== '';
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasAvailableIncomeCategories = computed<boolean>(() => {
|
||||||
|
if (!allTransactionCategories.value || !allTransactionCategories.value[CategoryType.Income] || !allTransactionCategories.value[CategoryType.Income].length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstAvailableCategoryId = getFirstAvailableCategoryId(allTransactionCategories.value[CategoryType.Income]);
|
||||||
|
return firstAvailableCategoryId !== '';
|
||||||
|
});
|
||||||
|
|
||||||
|
const hasAvailableTransferCategories = computed<boolean>(() => {
|
||||||
|
if (!allTransactionCategories.value || !allTransactionCategories.value[CategoryType.Transfer] || !allTransactionCategories.value[CategoryType.Transfer].length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstAvailableCategoryId = getFirstAvailableCategoryId(allTransactionCategories.value[CategoryType.Transfer]);
|
||||||
|
return firstAvailableCategoryId !== '';
|
||||||
|
});
|
||||||
|
|
||||||
function loadTransactionCategoryList(allCategories: Record<number, TransactionCategory[]>): void {
|
function loadTransactionCategoryList(allCategories: Record<number, TransactionCategory[]>): void {
|
||||||
allTransactionCategories.value = allCategories;
|
allTransactionCategories.value = allCategories;
|
||||||
allTransactionCategoriesMap.value = {};
|
allTransactionCategoriesMap.value = {};
|
||||||
@@ -496,6 +524,10 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
|
|||||||
allTransactionCategories,
|
allTransactionCategories,
|
||||||
allTransactionCategoriesMap,
|
allTransactionCategoriesMap,
|
||||||
transactionCategoryListStateInvalid,
|
transactionCategoryListStateInvalid,
|
||||||
|
// computed states
|
||||||
|
hasAvailableExpenseCategories,
|
||||||
|
hasAvailableIncomeCategories,
|
||||||
|
hasAvailableTransferCategories,
|
||||||
// functions
|
// functions
|
||||||
updateTransactionCategoryListInvalidState,
|
updateTransactionCategoryListInvalidState,
|
||||||
resetTransactionCategories,
|
resetTransactionCategories,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { useTransactionsStore } from '@/stores/transaction.ts';
|
|||||||
import { useExchangeRatesStore } from '@/stores/exchangeRates.ts';
|
import { useExchangeRatesStore } from '@/stores/exchangeRates.ts';
|
||||||
|
|
||||||
import type { LocalizedTimezoneInfo } from '@/core/timezone.ts';
|
import type { LocalizedTimezoneInfo } from '@/core/timezone.ts';
|
||||||
import { CategoryType } from '@/core/category.ts';
|
|
||||||
import { TransactionType } from '@/core/transaction.ts';
|
import { TransactionType } from '@/core/transaction.ts';
|
||||||
import { TemplateType } from '@/core/template.ts';
|
import { TemplateType } from '@/core/template.ts';
|
||||||
import { TRANSACTION_MAX_PICTURE_COUNT } from '@/consts/transaction.ts';
|
import { TRANSACTION_MAX_PICTURE_COUNT } from '@/consts/transaction.ts';
|
||||||
@@ -33,10 +32,6 @@ import {
|
|||||||
getCurrentUnixTime
|
getCurrentUnixTime
|
||||||
} from '@/lib/datetime.ts';
|
} from '@/lib/datetime.ts';
|
||||||
|
|
||||||
import {
|
|
||||||
getFirstAvailableCategoryId
|
|
||||||
} from '@/lib/category.ts';
|
|
||||||
|
|
||||||
export enum TransactionEditPageType {
|
export enum TransactionEditPageType {
|
||||||
Transaction = 'transaction',
|
Transaction = 'transaction',
|
||||||
Template = 'template'
|
Template = 'template'
|
||||||
@@ -103,6 +98,10 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
|
|||||||
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
||||||
const allTagsMap = computed<Record<string, TransactionTag>>(() => transactionTagsStore.allTransactionTagsMap);
|
const allTagsMap = computed<Record<string, TransactionTag>>(() => transactionTagsStore.allTransactionTagsMap);
|
||||||
|
|
||||||
|
const hasAvailableExpenseCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableExpenseCategories);
|
||||||
|
const hasAvailableIncomeCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableIncomeCategories);
|
||||||
|
const hasAvailableTransferCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableTransferCategories);
|
||||||
|
|
||||||
const canAddTransactionPicture = computed<boolean>(() => {
|
const canAddTransactionPicture = computed<boolean>(() => {
|
||||||
if (type !== TransactionEditPageType.Transaction || (mode.value !== TransactionEditPageMode.Add && mode.value !== TransactionEditPageMode.Edit)) {
|
if (type !== TransactionEditPageType.Transaction || (mode.value !== TransactionEditPageMode.Add && mode.value !== TransactionEditPageMode.Edit)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -194,33 +193,6 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
|
|||||||
return tt('Transfer In Amount') + ` (${amountRate})`;
|
return tt('Transfer In Amount') + ` (${amountRate})`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasAvailableExpenseCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Expense] || !allCategories.value[CategoryType.Expense].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Expense]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasAvailableIncomeCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Income] || !allCategories.value[CategoryType.Income].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Income]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasAvailableTransferCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Transfer] || !allCategories.value[CategoryType.Transfer].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Transfer]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const sourceAccountName = computed<string>(() => {
|
const sourceAccountName = computed<string>(() => {
|
||||||
if (transaction.value.sourceAccountId) {
|
if (transaction.value.sourceAccountId) {
|
||||||
return Account.findAccountNameById(allAccounts.value, transaction.value.sourceAccountId) || '';
|
return Account.findAccountNameById(allAccounts.value, transaction.value.sourceAccountId) || '';
|
||||||
@@ -422,6 +394,9 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
|
|||||||
allCategoriesMap,
|
allCategoriesMap,
|
||||||
allTags,
|
allTags,
|
||||||
allTagsMap,
|
allTagsMap,
|
||||||
|
hasAvailableExpenseCategories,
|
||||||
|
hasAvailableIncomeCategories,
|
||||||
|
hasAvailableTransferCategories,
|
||||||
canAddTransactionPicture,
|
canAddTransactionPicture,
|
||||||
title,
|
title,
|
||||||
saveButtonTitle,
|
saveButtonTitle,
|
||||||
@@ -429,9 +404,6 @@ export function useTransactionEditPageBase(type: TransactionEditPageType, initMo
|
|||||||
sourceAmountName,
|
sourceAmountName,
|
||||||
sourceAccountTitle,
|
sourceAccountTitle,
|
||||||
transferInAmountTitle,
|
transferInAmountTitle,
|
||||||
hasAvailableExpenseCategories,
|
|
||||||
hasAvailableIncomeCategories,
|
|
||||||
hasAvailableTransferCategories,
|
|
||||||
sourceAccountName,
|
sourceAccountName,
|
||||||
destinationAccountName,
|
destinationAccountName,
|
||||||
sourceAccountCurrency,
|
sourceAccountCurrency,
|
||||||
|
|||||||
@@ -188,8 +188,7 @@ import type { TransactionTag } from '@/models/transaction_tag.ts';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getTransactionPrimaryCategoryName,
|
getTransactionPrimaryCategoryName,
|
||||||
getTransactionSecondaryCategoryName,
|
getTransactionSecondaryCategoryName
|
||||||
getFirstAvailableCategoryId
|
|
||||||
} from '@/lib/category.ts';
|
} from '@/lib/category.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -233,32 +232,9 @@ const allVisibleCategorizedAccounts = computed<CategorizedAccountWithDisplayBala
|
|||||||
const allCategories = computed<Record<number, TransactionCategory[]>>(() => transactionCategoriesStore.allTransactionCategories);
|
const allCategories = computed<Record<number, TransactionCategory[]>>(() => transactionCategoriesStore.allTransactionCategories);
|
||||||
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
||||||
|
|
||||||
const hasAvailableExpenseCategories = computed<boolean>(() => {
|
const hasAvailableExpenseCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableExpenseCategories);
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Expense] || !allCategories.value[CategoryType.Expense].length) {
|
const hasAvailableIncomeCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableIncomeCategories);
|
||||||
return false;
|
const hasAvailableTransferCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableTransferCategories);
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Expense]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasAvailableIncomeCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Income] || !allCategories.value[CategoryType.Income].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Income]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasAvailableTransferCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Transfer] || !allCategories.value[CategoryType.Transfer].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Transfer]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
function getAccountDisplayName(accountId?: string): string {
|
function getAccountDisplayName(accountId?: string): string {
|
||||||
if (accountId) {
|
if (accountId) {
|
||||||
|
|||||||
@@ -497,6 +497,9 @@ const {
|
|||||||
allCategoriesMap,
|
allCategoriesMap,
|
||||||
allTags,
|
allTags,
|
||||||
allTagsMap,
|
allTagsMap,
|
||||||
|
hasAvailableExpenseCategories,
|
||||||
|
hasAvailableIncomeCategories,
|
||||||
|
hasAvailableTransferCategories,
|
||||||
canAddTransactionPicture,
|
canAddTransactionPicture,
|
||||||
title,
|
title,
|
||||||
saveButtonTitle,
|
saveButtonTitle,
|
||||||
@@ -504,9 +507,6 @@ const {
|
|||||||
sourceAmountName,
|
sourceAmountName,
|
||||||
sourceAccountTitle,
|
sourceAccountTitle,
|
||||||
transferInAmountTitle,
|
transferInAmountTitle,
|
||||||
hasAvailableExpenseCategories,
|
|
||||||
hasAvailableIncomeCategories,
|
|
||||||
hasAvailableTransferCategories,
|
|
||||||
sourceAccountName,
|
sourceAccountName,
|
||||||
destinationAccountName,
|
destinationAccountName,
|
||||||
sourceAccountCurrency,
|
sourceAccountCurrency,
|
||||||
|
|||||||
@@ -646,8 +646,7 @@ import {
|
|||||||
} from '@/lib/datetime.ts';
|
} from '@/lib/datetime.ts';
|
||||||
import {
|
import {
|
||||||
getTransactionPrimaryCategoryName,
|
getTransactionPrimaryCategoryName,
|
||||||
getTransactionSecondaryCategoryName,
|
getTransactionSecondaryCategoryName
|
||||||
getFirstAvailableCategoryId
|
|
||||||
} from '@/lib/category.ts';
|
} from '@/lib/category.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -805,32 +804,9 @@ const allCategoriesMap = computed<Record<string, TransactionCategory>>(() => tra
|
|||||||
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
const allTags = computed<TransactionTag[]>(() => transactionTagsStore.allTransactionTags);
|
||||||
const allTagsMap = computed<Record<string, TransactionTag>>(() => transactionTagsStore.allTransactionTagsMap);
|
const allTagsMap = computed<Record<string, TransactionTag>>(() => transactionTagsStore.allTransactionTagsMap);
|
||||||
|
|
||||||
const hasAvailableExpenseCategories = computed<boolean>(() => {
|
const hasAvailableExpenseCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableExpenseCategories);
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Expense] || !allCategories.value[CategoryType.Expense].length) {
|
const hasAvailableIncomeCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableIncomeCategories);
|
||||||
return false;
|
const hasAvailableTransferCategories = computed<boolean>(() => transactionCategoriesStore.hasAvailableTransferCategories);
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Expense]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasAvailableIncomeCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Income] || !allCategories.value[CategoryType.Income].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Income]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const hasAvailableTransferCategories = computed<boolean>(() => {
|
|
||||||
if (!allCategories.value || !allCategories.value[CategoryType.Transfer] || !allCategories.value[CategoryType.Transfer].length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstAvailableCategoryId = getFirstAvailableCategoryId(allCategories.value[CategoryType.Transfer]);
|
|
||||||
return firstAvailableCategoryId !== '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const supportedImportFileExtensions = computed<string | undefined>(() => {
|
const supportedImportFileExtensions = computed<string | undefined>(() => {
|
||||||
if (allFileSubTypes.value && allFileSubTypes.value.length) {
|
if (allFileSubTypes.value && allFileSubTypes.value.length) {
|
||||||
|
|||||||
@@ -514,15 +514,15 @@ const {
|
|||||||
allCategoriesMap,
|
allCategoriesMap,
|
||||||
allTags,
|
allTags,
|
||||||
allTagsMap,
|
allTagsMap,
|
||||||
|
hasAvailableExpenseCategories,
|
||||||
|
hasAvailableIncomeCategories,
|
||||||
|
hasAvailableTransferCategories,
|
||||||
canAddTransactionPicture,
|
canAddTransactionPicture,
|
||||||
title,
|
title,
|
||||||
saveButtonTitle,
|
saveButtonTitle,
|
||||||
sourceAmountName,
|
sourceAmountName,
|
||||||
sourceAccountTitle,
|
sourceAccountTitle,
|
||||||
transferInAmountTitle,
|
transferInAmountTitle,
|
||||||
hasAvailableExpenseCategories,
|
|
||||||
hasAvailableIncomeCategories,
|
|
||||||
hasAvailableTransferCategories,
|
|
||||||
sourceAccountName,
|
sourceAccountName,
|
||||||
destinationAccountName,
|
destinationAccountName,
|
||||||
sourceAccountCurrency,
|
sourceAccountCurrency,
|
||||||
|
|||||||
Reference in New Issue
Block a user