migrate transaction category store to composition API and typescript

This commit is contained in:
MaysWind
2025-01-12 23:47:56 +08:00
parent abb26ac410
commit 2be329974e
28 changed files with 818 additions and 663 deletions
+1 -1
View File
@@ -241,7 +241,7 @@ import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/index.js';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useExchangeRatesStore } from '@/stores/exchangeRates.ts';
import { APPLICATION_LOGO_PATH } from '@/consts/asset.ts';
+2 -2
View File
@@ -198,13 +198,13 @@ import PresetDialog from './list/dialogs/PresetDialog.vue';
import { useDisplay } from 'vuetify';
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { CategoryType } from '@/core/category.ts';
import {
isNoAvailableCategory,
getAvailableCategoryCount
} from '@/lib/category.js';
} from '@/lib/category.ts';
import { getNavSideBarOuterHeight } from '@/lib/ui/desktop.ts';
import {
@@ -95,16 +95,18 @@
<script>
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { CategoryType } from '@/core/category.ts';
import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts';
import { ALL_CATEGORY_COLORS } from '@/consts/color.ts';
import { TransactionCategory } from '@/models/transaction_category.ts';
import { generateRandomUUID } from '@/lib/misc.ts';
import {
setCategoryModelByAnotherCategory,
allVisiblePrimaryTransactionCategoriesByType
} from '@/lib/category.js';
} from '@/lib/category.ts';
export default {
props: [
@@ -115,15 +117,12 @@ export default {
'open'
],
data() {
const transactionCategoriesStore = useTransactionCategoriesStore();
const newTransactionCategory = transactionCategoriesStore.generateNewTransactionCategoryModel();
return {
showState: false,
editCategoryId: null,
clientSessionId: '',
loading: false,
category: newTransactionCategory,
category: TransactionCategory.createNewCategory(),
submitting: false,
resolve: null,
reject: null
@@ -176,7 +175,7 @@ export default {
self.loading = true;
self.submitting = false;
const newTransactionCategory = self.transactionCategoriesStore.generateNewTransactionCategoryModel();
const newTransactionCategory = TransactionCategory.createNewCategory();
setCategoryModelByAnotherCategory(self.category, newTransactionCategory);
if (options.id) {
@@ -68,7 +68,7 @@
<script>
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { CategoryType } from '@/core/category.ts';
import { categorizedArrayToPlainArray } from '@/lib/common.ts';
@@ -145,7 +145,7 @@
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useStatisticsStore } from '@/stores/statistics.js';
@@ -162,7 +162,7 @@ import {
isCategoryOrSubCategoriesAllChecked,
isSubCategoriesAllChecked,
isSubCategoriesHasButNotAllChecked
} from '@/lib/category.js';
} from '@/lib/category.ts';
import {
mdiSelectAll,
@@ -187,9 +187,9 @@ export default {
return {
loading: true,
expandCategoryTypes: [
CategoryType.Income.toString(),
CategoryType.Expense.toString(),
CategoryType.Transfer.toString()
CategoryType.Income,
CategoryType.Expense,
CategoryType.Transfer
],
filterCategoryIds: {},
showHidden: false,
@@ -388,11 +388,11 @@ export default {
},
getCategoryTypeName(categoryType) {
switch (categoryType) {
case CategoryType.Income.toString():
case CategoryType.Income:
return this.$t('Income Categories');
case CategoryType.Expense.toString():
case CategoryType.Expense:
return this.$t('Expense Categories');
case CategoryType.Transfer.toString():
case CategoryType.Transfer:
return this.$t('Transfer Categories');
default:
return this.$t('Transaction Categories');
@@ -322,7 +322,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useStatisticsStore } from '@/stores/statistics.js';
import { DateRangeScene, DateRange } from '@/core/datetime.ts';
+2 -2
View File
@@ -591,7 +591,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
@@ -627,7 +627,7 @@ import {
import {
categoryTypeToTransactionType,
transactionTypeToCategoryType
} from '@/lib/category.js';
} from '@/lib/category.ts';
import { getUnifiedSelectedAccountsCurrencyOrDefaultCurrency } from '@/lib/account.js';
import { getTransactionDisplayAmount } from '@/lib/transaction.js';
import { isDataImportingEnabled } from '@/lib/server_settings.ts';
@@ -175,7 +175,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
import { useExchangeRatesStore } from '@/stores/exchangeRates.ts';
@@ -187,7 +187,7 @@ import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
getFirstAvailableCategoryId
} from '@/lib/category.js';
} from '@/lib/category.ts';
import {
mdiPound
@@ -394,7 +394,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
@@ -421,7 +421,7 @@ import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
getFirstAvailableCategoryId
} from '@/lib/category.js';
} from '@/lib/category.ts';
import { setTransactionModelByTransaction } from '@/lib/transaction.js';
import {
isTransactionPicturesEnabled,
@@ -600,7 +600,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useOverviewStore } from '@/stores/overview.ts';
@@ -628,7 +628,7 @@ import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
getFirstAvailableCategoryId
} from '@/lib/category.js';
} from '@/lib/category.ts';
import {
mdiFilterOutline,
+1 -1
View File
@@ -179,7 +179,7 @@ import { mapStores } from 'pinia';
import { useRootStore } from '@/stores/index.js';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useExchangeRatesStore } from '@/stores/exchangeRates.ts';
import { CategoryType } from '@/core/category.ts';
+1 -1
View File
@@ -19,7 +19,7 @@
<script>
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
export default {
props: [
+11 -11
View File
@@ -83,7 +83,7 @@
<template #default>
<div class="grid grid-cols-2">
<div class="list-item-subitem no-chevron">
<a class="item-link" href="#" @click="category.showIconSelectionSheet = true">
<a class="item-link" href="#" @click="showIconSelectionSheet = true">
<div class="item-content">
<div class="item-inner">
<div class="item-header">
@@ -100,12 +100,12 @@
<icon-selection-sheet :all-icon-infos="allCategoryIcons"
:color="category.color"
v-model:show="category.showIconSelectionSheet"
v-model:show="showIconSelectionSheet"
v-model="category.icon"
></icon-selection-sheet>
</div>
<div class="list-item-subitem no-chevron">
<a class="item-link" href="#" @click="category.showColorSelectionSheet = true">
<a class="item-link" href="#" @click="showColorSelectionSheet = true">
<div class="item-content">
<div class="item-inner">
<div class="item-header">
@@ -121,7 +121,7 @@
</a>
<color-selection-sheet :all-color-infos="allCategoryColors"
v-model:show="category.showColorSelectionSheet"
v-model:show="showColorSelectionSheet"
v-model="category.color"
></color-selection-sheet>
</div>
@@ -147,17 +147,19 @@
<script>
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { CategoryType } from '@/core/category.ts';
import { ALL_CATEGORY_ICONS } from '@/consts/icon.ts';
import { ALL_CATEGORY_COLORS } from '@/consts/color.ts';
import { TransactionCategory } from '@/models/transaction_category.ts';
import { getNameByKeyValue } from '@/lib/common.ts';
import { generateRandomUUID } from '@/lib/misc.ts';
import {
setCategoryModelByAnotherCategory,
allVisiblePrimaryTransactionCategoriesByType
} from '@/lib/category.js';
} from '@/lib/category.ts';
export default {
props: [
@@ -165,19 +167,17 @@ export default {
'f7router'
],
data() {
const transactionCategoriesStore = useTransactionCategoriesStore();
const query = this.f7route.query;
const newTransactionCategory = transactionCategoriesStore.generateNewTransactionCategoryModel(parseInt(query.type), query.parentId);
newTransactionCategory.showIconSelectionSheet = false;
newTransactionCategory.showColorSelectionSheet = false;
return {
editCategoryId: null,
clientSessionId: '',
loading: false,
loadingError: null,
category: newTransactionCategory,
category: TransactionCategory.createNewCategory(parseInt(query.type), query.parentId),
showPrimaryCategorySheet: false,
showIconSelectionSheet: false,
showColorSelectionSheet: false,
submitting: false
};
},
+2 -2
View File
@@ -88,14 +88,14 @@
<script>
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { CategoryType } from '@/core/category.ts';
import {
isNoAvailableCategory,
getFirstShowingId,
getLastShowingId
} from '@/lib/category.js';
} from '@/lib/category.ts';
import { onSwipeoutDeleted } from '@/lib/ui/mobile.ts';
export default {
+1 -1
View File
@@ -57,7 +57,7 @@
<script>
import { mapStores } from 'pinia';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { CategoryType } from '@/core/category.ts';
import { getObjectOwnFieldCount, categorizedArrayToPlainArray } from '@/lib/common.ts';
@@ -141,7 +141,7 @@
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useStatisticsStore } from '@/stores/statistics.js';
@@ -158,7 +158,7 @@ import {
isCategoryOrSubCategoriesAllChecked,
isSubCategoriesAllChecked,
isSubCategoriesHasButNotAllChecked
} from '@/lib/category.js';
} from '@/lib/category.ts';
export default {
props: [
@@ -357,11 +357,11 @@ export default {
},
getCategoryTypeName(categoryType) {
switch (categoryType) {
case CategoryType.Income.toString():
case CategoryType.Income:
return this.$t('Income Categories');
case CategoryType.Expense.toString():
case CategoryType.Expense:
return this.$t('Expense Categories');
case CategoryType.Transfer.toString():
case CategoryType.Transfer:
return this.$t('Transfer Categories');
default:
return this.$t('Transaction Categories');
@@ -328,7 +328,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useStatisticsStore } from '@/stores/statistics.js';
import { DateRangeScene, DateRange } from '@/core/datetime.ts';
+2 -2
View File
@@ -434,7 +434,7 @@ import { useSettingsStore } from '@/stores/setting.ts';
import { useEnvironmentsStore } from '@/stores/environment.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
@@ -463,7 +463,7 @@ import {
getTransactionPrimaryCategoryName,
getTransactionSecondaryCategoryName,
getFirstAvailableCategoryId
} from '@/lib/category.js';
} from '@/lib/category.ts';
import { setTransactionModelByTransaction } from '@/lib/transaction.js';
import {
isTransactionPicturesEnabled,
+2 -2
View File
@@ -524,7 +524,7 @@ import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.ts';
import { useUserStore } from '@/stores/user.ts';
import { useAccountsStore } from '@/stores/account.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.js';
import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts';
import { useTransactionTagsStore } from '@/stores/transactionTag.ts';
import { useTransactionsStore } from '@/stores/transaction.js';
@@ -548,7 +548,7 @@ import {
getDateRangeByDateType,
getDateRangeByBillingCycleDateType
} from '@/lib/datetime.ts';
import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js';
import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.ts';
import { getUnifiedSelectedAccountsCurrencyOrDefaultCurrency } from '@/lib/account.js';
import { getTransactionDisplayAmount } from '@/lib/transaction.js';
import { onSwipeoutDeleted, scrollToSelectedItem } from '@/lib/ui/mobile.ts';