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,10 +1,12 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
import { useSettingsStore } from './setting.js';
|
||||||
import { useUserStore } from './user.js';
|
import { useUserStore } from './user.js';
|
||||||
import { useAccountsStore } from './account.js';
|
import { useAccountsStore } from './account.js';
|
||||||
import { useTransactionCategoriesStore } from './transactionCategory.js';
|
import { useTransactionCategoriesStore } from './transactionCategory.js';
|
||||||
import { useExchangeRatesStore } from './exchangeRates.js';
|
import { useExchangeRatesStore } from './exchangeRates.js';
|
||||||
|
|
||||||
|
import datetimeConstants from '@/consts/datetime.js';
|
||||||
import statisticsConstants from '@/consts/statistics.js';
|
import statisticsConstants from '@/consts/statistics.js';
|
||||||
import categoryConstants from '@/consts/category.js';
|
import categoryConstants from '@/consts/category.js';
|
||||||
import iconConstants from '@/consts/icon.js';
|
import iconConstants from '@/consts/icon.js';
|
||||||
@@ -16,6 +18,9 @@ import {
|
|||||||
isNumber,
|
isNumber,
|
||||||
isObject
|
isObject
|
||||||
} from '@/lib/common.js';
|
} from '@/lib/common.js';
|
||||||
|
import {
|
||||||
|
getDateRangeByDateType
|
||||||
|
} from '@/lib/datetime.js';
|
||||||
|
|
||||||
export const useStatisticsStore = defineStore('statistics', {
|
export const useStatisticsStore = defineStore('statistics', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -413,6 +418,48 @@ export const useStatisticsStore = defineStore('statistics', {
|
|||||||
this.transactionStatisticsStateInvalid = true;
|
this.transactionStatisticsStateInvalid = true;
|
||||||
},
|
},
|
||||||
initTransactionStatisticsFilter(filter) {
|
initTransactionStatisticsFilter(filter) {
|
||||||
|
if (!filter) {
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
|
let defaultChartType = settingsStore.appSettings.statistics.defaultChartType;
|
||||||
|
|
||||||
|
if (defaultChartType !== statisticsConstants.allChartTypes.Pie && defaultChartType !== statisticsConstants.allChartTypes.Bar) {
|
||||||
|
defaultChartType = statisticsConstants.defaultChartType;
|
||||||
|
}
|
||||||
|
|
||||||
|
let defaultChartDataType = settingsStore.appSettings.statistics.defaultChartDataType;
|
||||||
|
|
||||||
|
if (defaultChartDataType < statisticsConstants.allChartDataTypes.ExpenseByAccount.type || defaultChartDataType > statisticsConstants.allChartDataTypes.AccountTotalLiabilities.type) {
|
||||||
|
defaultChartDataType = statisticsConstants.defaultChartDataType;
|
||||||
|
}
|
||||||
|
|
||||||
|
let defaultDateRange = settingsStore.appSettings.statistics.defaultDataRangeType;
|
||||||
|
|
||||||
|
if (defaultDateRange < datetimeConstants.allDateRanges.All.type || defaultDateRange >= datetimeConstants.allDateRanges.Custom.type) {
|
||||||
|
defaultDateRange = statisticsConstants.defaultDataRangeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
let defaultSortType = settingsStore.appSettings.statistics.defaultSortingType;
|
||||||
|
|
||||||
|
if (defaultSortType < statisticsConstants.allSortingTypes.Amount.type || defaultSortType > statisticsConstants.allSortingTypes.Name.type) {
|
||||||
|
defaultSortType = statisticsConstants.defaultSortingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateRange = getDateRangeByDateType(defaultDateRange, userStore.currentUserFirstDayOfWeek);
|
||||||
|
|
||||||
|
filter = {
|
||||||
|
dateType: dateRange ? dateRange.dateType : undefined,
|
||||||
|
startTime: dateRange ? dateRange.minTime : undefined,
|
||||||
|
endTime: dateRange ? dateRange.maxTime : undefined,
|
||||||
|
chartType: defaultChartType,
|
||||||
|
chartDataType: defaultChartDataType,
|
||||||
|
filterAccountIds: settingsStore.appSettings.statistics.defaultAccountFilter || {},
|
||||||
|
filterCategoryIds: settingsStore.appSettings.statistics.defaultTransactionCategoryFilter || {},
|
||||||
|
sortingType: defaultSortType,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (filter && isNumber(filter.dateType)) {
|
if (filter && isNumber(filter.dateType)) {
|
||||||
this.transactionStatisticsFilter.dateType = filter.dateType;
|
this.transactionStatisticsFilter.dateType = filter.dateType;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -365,42 +365,7 @@ export default {
|
|||||||
created() {
|
created() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
let defaultChartType = self.settingsStore.appSettings.statistics.defaultChartType;
|
self.statisticsStore.initTransactionStatisticsFilter();
|
||||||
|
|
||||||
if (defaultChartType !== self.allChartTypes.Pie && defaultChartType !== self.allChartTypes.Bar) {
|
|
||||||
defaultChartType = statisticsConstants.defaultChartType;
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultChartDataType = self.settingsStore.appSettings.statistics.defaultChartDataType;
|
|
||||||
|
|
||||||
if (defaultChartDataType < self.allChartDataTypes.ExpenseByAccount.type || defaultChartDataType > self.allChartDataTypes.AccountTotalLiabilities.type) {
|
|
||||||
defaultChartDataType = statisticsConstants.defaultChartDataType;
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultDateRange = self.settingsStore.appSettings.statistics.defaultDataRangeType;
|
|
||||||
|
|
||||||
if (defaultDateRange < self.allDateRanges.All.type || defaultDateRange >= self.allDateRanges.Custom.type) {
|
|
||||||
defaultDateRange = statisticsConstants.defaultDataRangeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultSortType = self.settingsStore.appSettings.statistics.defaultSortingType;
|
|
||||||
|
|
||||||
if (defaultSortType < self.allSortingTypes.Amount.type || defaultSortType > self.allSortingTypes.Name.type) {
|
|
||||||
defaultSortType = statisticsConstants.defaultSortingType;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dateRange = getDateRangeByDateType(defaultDateRange, self.firstDayOfWeek);
|
|
||||||
|
|
||||||
self.statisticsStore.initTransactionStatisticsFilter({
|
|
||||||
dateType: dateRange ? dateRange.dateType : undefined,
|
|
||||||
startTime: dateRange ? dateRange.minTime : undefined,
|
|
||||||
endTime: dateRange ? dateRange.maxTime : undefined,
|
|
||||||
chartType: defaultChartType,
|
|
||||||
chartDataType: defaultChartDataType,
|
|
||||||
filterAccountIds: self.settingsStore.appSettings.statistics.defaultAccountFilter || {},
|
|
||||||
filterCategoryIds: self.settingsStore.appSettings.statistics.defaultTransactionCategoryFilter || {},
|
|
||||||
sortingType: defaultSortType,
|
|
||||||
});
|
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
self.accountsStore.loadAllAccounts({ force: false }),
|
self.accountsStore.loadAllAccounts({ force: false }),
|
||||||
|
|||||||
@@ -355,42 +355,7 @@ export default {
|
|||||||
created() {
|
created() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
let defaultChartType = self.settingsStore.appSettings.statistics.defaultChartType;
|
self.statisticsStore.initTransactionStatisticsFilter();
|
||||||
|
|
||||||
if (defaultChartType !== self.allChartTypes.Pie && defaultChartType !== self.allChartTypes.Bar) {
|
|
||||||
defaultChartType = statisticsConstants.defaultChartType;
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultChartDataType = self.settingsStore.appSettings.statistics.defaultChartDataType;
|
|
||||||
|
|
||||||
if (defaultChartDataType < self.allChartDataTypes.ExpenseByAccount.type || defaultChartDataType > self.allChartDataTypes.AccountTotalLiabilities.type) {
|
|
||||||
defaultChartDataType = statisticsConstants.defaultChartDataType;
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultDateRange = self.settingsStore.appSettings.statistics.defaultDataRangeType;
|
|
||||||
|
|
||||||
if (defaultDateRange < self.allDateRanges.All.type || defaultDateRange >= self.allDateRanges.Custom.type) {
|
|
||||||
defaultDateRange = statisticsConstants.defaultDataRangeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultSortType = self.settingsStore.appSettings.statistics.defaultSortingType;
|
|
||||||
|
|
||||||
if (defaultSortType < self.allSortingTypes.Amount.type || defaultSortType > self.allSortingTypes.Name.type) {
|
|
||||||
defaultSortType = statisticsConstants.defaultSortingType;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dateRange = getDateRangeByDateType(defaultDateRange, self.firstDayOfWeek);
|
|
||||||
|
|
||||||
self.statisticsStore.initTransactionStatisticsFilter({
|
|
||||||
dateType: dateRange ? dateRange.dateType : undefined,
|
|
||||||
startTime: dateRange ? dateRange.minTime : undefined,
|
|
||||||
endTime: dateRange ? dateRange.maxTime : undefined,
|
|
||||||
chartType: defaultChartType,
|
|
||||||
chartDataType: defaultChartDataType,
|
|
||||||
filterAccountIds: self.settingsStore.appSettings.statistics.defaultAccountFilter || {},
|
|
||||||
filterCategoryIds: self.settingsStore.appSettings.statistics.defaultTransactionCategoryFilter || {},
|
|
||||||
sortingType: defaultSortType,
|
|
||||||
});
|
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
self.accountsStore.loadAllAccounts({ force: false }),
|
self.accountsStore.loadAllAccounts({ force: false }),
|
||||||
|
|||||||
Reference in New Issue
Block a user